Support passing generateId to docsLoader()#3272
Conversation
🦋 Changeset detectedLatest commit: 24557af The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
size-limit report 📦
|
HiDeoo
left a comment
There was a problem hiding this comment.
Impressive how exposing such feature can be done quite easily and beautifully 👏 Like you mentioned, the bulk of the work is definitely the documentation (which imo is perfect).
Left a tiny comment, also wonder if there are some places where it could be relevant to link to this new documentation section, e.g.:
- "Configure content collections" section, maybe linking
docsLoaderanddocsSchema? - "Extend translation schema" section, maybe linking
extend? - "Customize frontmatter schema"
extendsection, maybe linkingextend?
Nothing blocking, just some thoughts.
Like you mentioned and as we discussed earlier, there are definitely some potential limits to this feature or potential issues that could arise, but I still think it is a great addition, and in the case of plugins, if it's ever an issue, it should be relatively easy to support an equivalent option at the plugin level, to use a custom function instead of the default assumed github-slugger one.
Co-Authored-By: HiDeoo <494699+HiDeoo@users.noreply.github.com>
|
OK, perfect — thanks for the helpful feedback! I decided against linking the two |
Co-authored-by: HiDeoo <494699+HiDeoo@users.noreply.github.com>
Root cause: topic overview MDX files had `draft: true` in frontmatter. They were excluded from the production build by Astro/Starlight, which caused 404s in preview and production. Also includes framework upgrades to enable upcoming slug work: - Astro: v5.8.2 → v5.13.5 - Starlight: v0.34.3 → v0.35.2 From Starlight v0.35.0, custom slug generation is supported to decouple file structure from public URLs. Refs: withastro/starlight#3272
Root cause: 'Topic' overview MDX files had `draft: true` in frontmatter. They were excluded from the production build by Astro/Starlight, which caused 404s in preview and production. This commit also includes framework upgrades to enable upcoming slug work: - Astro: v5.8.2 → v5.13.5 - Starlight: v0.34.3 → v0.35.2 From Starlight v0.35.0, custom slug generation is supported to decouple file structure from public URLs. Refs: withastro/starlight#3272

Closes #3227
This PR makes it possible to pass
generateIdto Starlight’sdocsLoader().Currently, using
generateIdto customize content slugs is only possible by ejecting back up to Astro’s genericglob()loader, but this requires figuring out thepatternandbaseStarlight uses if you want to mirror thedocsLoader()behaviour, e.g.:After this PR you can keep using
docsLoader(), and just add your ID method:I did not also add an equivalent method to the
i18nLoaderas customizing slugs for languages seems much less common, and it would be more liable to break given how we load translation files in non-content collection contexts.A big part of this PR was also figuring out how best to document this, as we currently only document our loaders in passing. This PR adds a “Configuring content collections” section to the config reference which documents all our loaders and schemas. I kept this minimal for now and linked out to existing relevant docs rather than duplicating or moving things around, but I’d welcome feedback on this new section.
It’s perhaps worth noting that there is some risk in supporting custom
generateIdmethods. Especially for multilingual sites.There are a few code paths running outside of the Astro/Vite context where Starlight uses raw file paths directly rather than the content collection ID. This is notably the case for remark/rehype plugins. For example, we use the file path to work out the current language for remark plugins. This means it won’t be possible to use
generateIdfor entirely novel structures like storing localized content in sub-directories or something.For example, moving the locale from a file name to the front of the ID like this wouldn’t work for our remark plugins:
But for common scenarios like preserving uppercase characters or special characters like
.inside IDs, it should work pretty OK although it is likely to break compatibility with plugins like https://github.com/HiDeoo/starlight-links-validator that rely on being able to predict the ID format based on the filepath.