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 📦
|
delucis
left a comment
There was a problem hiding this comment.
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 <swithinbank@gmail.com>
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 |
delucis
left a comment
There was a problem hiding this comment.
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 <swithinbank@gmail.com>
|
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! |
kevinzunigacuellar
left a comment
There was a problem hiding this comment.
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 <46791833+kevinzunigacuellar@users.noreply.github.com>
|
Lost Glasses, Troublesome Moment! ✅ |
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> Co-authored-by: Kevin Zuniga Cuellar <46791833+kevinzunigacuellar@users.noreply.github.com>

What kind of changes does this PR include?
Description
Closes Setting Astro
build.formatconfig breaks sidebar links #180Implemented
formatPathfunction 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/".