Open eric-burel opened 3 weeks ago
Run & review this pull request in StackBlitz Codeflow.
Alright ! So the TutorialStore is a stateful singleton as far as I can tell from the code.
However I see setLesson
being called only in WorkspacePanelWrapper
in a useEffect
hook: is this value available in server-side Astro components as well? I feel like it only works in islands, and is strongly tied to the WorkspacePanel component loading first.
This PR introduces a way to access the current lesson frontmatter / collection entry from any component, using
Astro.locals
as a server context.I've tried to find simpler alternatives:
frontmatter
object accessible in Markdown files can help avoiding repetitions when a component needs the current lesson title etc. However it won't enjoy the parsing logic from TutorialKitgetTutorial
function inpackages/astro/src/default/utils/content.ts
<Markdown />
component inpackages/astro/src/default/components/TutorialContent.astro
. I didn't actually try but found no documentation regarding such an usage, all the more thatAstro.render()
has already been called to generate this component so I suspect that even it was possible, it would be too late to pass it some props.url
value in a MDX page but it points to the file and not the actual URL (it had no chance to work since using a collection decorelates the URL and the entry). We can only access thefrontmatter
propI needed to pass an additional
entrySlug
to be able to callgetEntry
later on. I focused on lessons at the moment.Use cases would be crafting reusable lesson-specific component, that are able to figure the lesson URL, reuse the frontmatter config etc. For instance I am trying to wrap up a "Share on Bluesky" component.