feat: access current lesson from Astro.locals #398
+80
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.