Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip leading and trailing slashes from autogenerate.directory #944

Merged

Conversation

HiDeoo
Copy link
Member

@HiDeoo HiDeoo commented Oct 23, 2023

What kind of changes does this PR include?

  • Changes to Starlight code

Description

For sidebar autogenerated groups, we expect the autogenerate.directory to not include leading or trailing slashes:

const localeDir = locale ? locale + '/' + directory : directory;
const dirDocs = routes.filter(
(doc) =>
// Match against `foo.md` or `foo/index.md`.
stripExtension(doc.id) === localeDir ||
// Match against `foo/anything/else.md`.
doc.id.startsWith(localeDir + '/')
);

This can lead to empty groups in the sidebar if the user has a leading or trailing slash in their autogenerate.directory and no real hint or error message as to why like this Discord message.

This pull request suggests that we strip leading and trailing slashes from autogenerate.directory in the Zod schema using a .transform().

Note: I also updated some invalid paths in various mockedAstroContent() test calls following the rename of reference/configuration.md to reference/configuration.mdx in #869.

@changeset-bot
Copy link

changeset-bot bot commented Oct 23, 2023

🦋 Changeset detected

Latest commit: 998cde0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight Patch

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

@netlify
Copy link

netlify bot commented Oct 23, 2023

👷 Deploy Preview for astro-starlight processing.

Name Link
🔨 Latest commit 998cde0
🔍 Latest deploy log https://app.netlify.com/sites/astro-starlight/deploys/6536501d8a638e0007f2390e

@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Oct 23, 2023
Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @HiDeoo! Tried to think through if there are any drawbacks to supporting directory containing slashes, but I can’t think of any, so this seems like a good solution. Thanks for putting it together!

@delucis delucis merged commit 7a6446e into withastro:main Oct 23, 2023
10 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 core Changes to Starlight’s main package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants