Refactor autogenerated sidebar groups#3618
Conversation
🦋 Changeset detectedLatest commit: 3e793dd 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
|
| parseStarlightConfigWithFriendlyErrors({ | ||
| title: 'Test', | ||
| sidebar: [ | ||
| // @ts-expect-error - Testing invalid config |
There was a problem hiding this comment.
I need to investigate why this error was hoisted (I can guess why, but need to know the specific reason) and see if we can move it back down at the group item level without losing some other type behaviors we expect.
| export interface SidebarAutoLink extends SidebarManualLink { | ||
| autogenerated: true; | ||
| } | ||
|
|
There was a problem hiding this comment.
@HiDeoo Did you have an intended use case for this new property? We didn’t distinguish autogenerated groups from other groups previously, so maybe we can just keep treating all links the same once they get generated and omit this property?
I see this mentioned in the PR comment but I don’t understand why plugins would need access to this data.
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>

Description
This PR adds a new feature which has been discussed and approved here.
Closes Groupless autogenarated sidebar links #3336
This PR removes the notion of "autogenerated sidebar groups" in favor of simply using "autogenerated sidebar links" which can be used in regular sidebar groups. As discussed in #3336, this simplifies the mental model around groups and also allows for use cases that were not possible before, such as having a sidebar entirely made of autogenerated links for a specific directory without having it nested inside a group.
For users, the gist of the change is:
{ label: 'My group', - autogenerate: { directory: 'some-dir' }, + items: [{ autogenerate: { directory: 'some-dir' } }], }Such refactor removes the 1:1 mapping that was previously available between an autogenerated sidebar group in the Starlight configuration and such autogenerated group in the Starlight route data. To address such change, the Starlight route data has been updated and many solutions are possible to address this, e.g. having multiple types (
link,autolink,group, andautogroup). This PR has gone through multiple variations of such approach, and the current implementation does not introduce new types but rather adds anautogeneratedproperty set to totruefor links and subgroups that were autogenerated. Of course, other approaches are possible and feedback is welcome.To make sure such change does not impact plugins with previous features that would no longer be possible due to the changes, I rewrote locally the
starlight-auto-sidebarplugin, which was heavily relying on that 1:1 mapping and to my knowledge, may be one of the "largest" plugins tweaking sidebar route data for autogenerated groups with a large enough set of tests. I managed to rewrite it successfully while using the Starlight version from this PR and achieved the same results as before.Note: I also addded a few tests for some behaviors that were not covered before and were impacted by this change, e.g. the
collapsedstate of autogenerated subgroups.Remaining tasks