Skip to content

Conversation

@HiDeoo
Copy link
Member

@HiDeoo HiDeoo commented Aug 4, 2023

What kind of changes does this PR include?

  • Changes to Starlight code

Description

As discussed on Discord, this PR fixes the current page highlight in the sidebar for URLs with no trailing slash.

This Discord thread also discusses why this PR does not handle Astro trailingSlash and build.format options for the sidebar isCurrent check which is purposefully lenient. These options should be handled in #207.

My initial suggestion on Discord was to use const isCurrent = href === currentPathname.replace(/\/?$/, '/'); but instead I used the same approach as the existing ensureLeadingAndTrailingSlashes() function for multiple reasons:

  • Consistency
  • Might be slightly easier to understand for someone not used to regex
  • According to this bench, this is faster. Not sure it's properly benchmarked or if it even matters in this case but might as well use the faster option ^^

@changeset-bot
Copy link

changeset-bot bot commented Aug 4, 2023

🦋 Changeset detected

Latest commit: e67bf8a

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 Aug 4, 2023

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit e67bf8a
🔍 Latest deploy log https://app.netlify.com/sites/astro-starlight/deploys/64d15e091be7320008baa5ed
😎 Deploy Preview https://deploy-preview-460--astro-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Aug 4, 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 — LGTM! Left one refactor suggestion, but doesn’t have to be part of this PR if you don’t think it’s important.

@delucis delucis added the 🌟 patch Change that triggers a patch release label Aug 4, 2023
@HiDeoo
Copy link
Member Author

HiDeoo commented Aug 7, 2023

Moved all these helpers to a new dedicated file and indeed, as expected, according to the same benchmark tool, the stripping regexp version was also slower.

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.

Thank you @HiDeoo!

@delucis delucis merged commit 2e0fb90 into withastro:main Aug 7, 2023
@astrobot-houston astrobot-houston mentioned this pull request Aug 7, 2023
Yoxnear pushed a commit to Yoxnear/starlight-custom that referenced this pull request Jul 23, 2025
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 🌟 patch Change that triggers a patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants