-
-
Notifications
You must be signed in to change notification settings - Fork 578
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
fix: handle build.format
links in sidebar
#1023
Conversation
🦋 Changeset detectedLatest commit: 596d889 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 site configuration. |
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kevinzunigacuellar! I see build.format: 'file'
in the docs to test, but looks like the sidebar in the deploy preview does not use .html
. Any idea why?
Checking the build output it looks that all the href in the sidebar have a .html append to the end. I think it's one of netlify features to strip the .html from the deployed files (Pretty URL’s) |
Co-authored-by: Chris Swithinbank <[email protected]>
Ahhhhh! Thank you Netlify 🖖 |
I had to make a few assertions for On second thought, we could create a default fully defined build config and override it with opts. I am open to suggestions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for cleaning up that test config helper. I left a suggestion to avoid the type assertions and then one question.
packages/starlight/__tests__/sidebar-file-build/vitest.config.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Chris Swithinbank <[email protected]>
I made a function called |
Nice work!
Might make sense to move it to its own file. We do have The other option would be to refactor it slightly to take the required config as an argument and put it together in /** Add `.html` extension to a path. */
export function ensureHtmlExtension(path: string) {
if (path.endsWith('.html')) return ensureLeadingSlash(path);
path = stripLeadingAndTrailingSlashes(path);
return path ? ensureLeadingSlash(path) + '.html' : '/index.html';
}
export function formatPath(href: string, format: 'file' | 'directory') {
// atach base
href = format === 'file' ? fileWithBase(href) : pathWithBase(href);
// add html extension
href = format === 'file' ? ensureHtmlExtension(href) : stripExtension(href);
return href;
} Then users could import it and pass the import project from 'virtual:starlight/project-context';
import { formatPath } from './path';
formatPath(path, project.build.format); |
I've created a new file for the format function and added There's some ambiguity regarding the expected behavior for In my view, adopting a convention would simplify the comparison of values for "isCurrent" in the sidebar. The convention I propose is as follows:
Establishing this convention would enhance consistency and aid in comparing values for "isCurrent" in the sidebar, offering a clearer and more predictable structure for the project. What do you think? @delucis @HiDeoo PS: When reviewing the test file for |
Hey @kevinzunigacuellar! Turned out this was fiddlier than I expected, so I spent some time getting everything polished up. Quick summary of the changes I made:
Would love a quick look if you have time and thanks for the patience waiting for me on this one! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @delucis for the review and changes. Yes, this PR started very simple but it got very complex very quickly 😅. I left a couple comments, feel free to disregard the nit comments btw.
Co-authored-by: Kevin Zuniga Cuellar <[email protected]>
Lost Glasses, Troublesome Moment! ✅ |
What kind of changes does this PR include?
Description
Closes Setting Astro
build.format
config breaks sidebar links #180Implemented
formatPath
function to adjust path formats according to project configurations.Defined conventions for formatting paths:
build.format: "file"
, the path will conclude with a ".html" extension. For instance, "/reference/" will transform into "/reference.html".build.format: "directory"
, the path will include a trailing slash. For instance, "/reference.html" will change to "/reference/".