Support for zero frontmatter in content files and/or remarkPluginFrontmatter
#3461
delucis
started this conversation in
Feature Requests
Replies: 1 comment 7 replies
-
|
Hi @delucis, I have made the minimal changes to make starlight work without frontmatter on my personal fork. You can look at it here. Let me know if can and I should raise a PR. The change consist on 4 main changes:
I have explored the creation of a remark fontmatter plugin to get title from headers, but had 2 issues:
I can share more details if you are interested Thanks |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
What version of
starlightare you using?0.36.0
What is your idea?
Currently Starlight requires a minimal frontmatter block in every content file:
All other frontmatter fields are optional, but we require
titleso we can populate things like sidebar labels,<title>meta, pagination links, and of course the actual on-page title field.This discussion is to consider whether it could be possible to loosen this in some ways to support Astro’s
remarkPluginFrontmatter, allowingtitleto be populated programmatically that way, e.g. extracting it from anh1node, perhaps even doing that by default iftitleis not set.Why is this feature necessary?
We’ve recently seen some requests to support no frontmatter, to make it easier to use content files that have a double purpose being rendered on e.g. GitHub, where frontmatter would make the file look less nice.
Additionally, for more advanced use cases there may be instances where
remarkPluginFrontmattercan allow some dynamic control over frontmatter and avoid needing to manually set things repeatedly in frontmatter. It also provides an additional hook for people to have programmatic control over Starlight’s data model, which runs earlier than route data middleware:remarkPluginFrontmatterallows programmatic control at the content input level vs middleware which gives control over the Starlight data layer before rendering.Historical context
One big reason for avoiding this in initial designs was performance:
titleis used in a lot of places, including on pages other than the titled page. For example, in an autogenerated sidebar, all link labels are pulled from thetitlefields of all pages. Extracting frontmatter values is much faster than parsing Markdown for all pages and so Astro split these two tasks into two chunks of work done separately:This allowed for snappy dev server startup and updates by deferring Markdown processing. Having to process all Markdown for all pages to render one page’s sidebar is slow and we avoided that.
However, if I’m not mistaken, this two-step performance optimization was removed in the Astro v5 content collection re-architecting and now Markdown is once again processed upfront and cached in the collection. If that’s the case (we should confirm), and if there’s no intention to bring back the two-step process, then we could reconsider the design decision in Starlight to require
titleas the benefit would no longer be present.Ideally, I’d argue that if Astro is committed to running the Markdown pipeline early, then integrating
remarkPluginFrontmatterinto regular frontmatter should be done at the Astro level, so that data flows as:This means users no longer have to deal with both
entry.dataand(await render(entry)).remarkPluginFrontmatter)and resolve that in templates, but can just rely onentry.dataand schema types for a nicer DX.Do you have examples of this feature in other projects?
titleParticipation
Beta Was this translation helpful? Give feedback.
All reactions