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

extend config options to pagefind #1365

Merged
merged 17 commits into from
Jan 29, 2024
Merged

extend config options to pagefind #1365

merged 17 commits into from
Jan 29, 2024

Conversation

kevinzunigacuellar
Copy link
Member

@kevinzunigacuellar kevinzunigacuellar commented Jan 12, 2024

Description

Copy link

changeset-bot bot commented Jan 12, 2024

🦋 Changeset detected

Latest commit: eac4542

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

Copy link

vercel bot commented Jan 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
starlight ✅ Ready (Inspect) Visit Preview Jan 29, 2024 11:04am
1 Ignored Deployment
Name Status Preview Updated (UTC)
starlight-i18n ⬜️ Ignored (Inspect) Visit Preview Jan 29, 2024 11:04am

@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Jan 12, 2024
@astrobot-houston
Copy link
Collaborator

astrobot-houston commented Jan 12, 2024

size-limit report 📦

Path Size
/index.html 5.22 KB (+0.04% 🔺)
/_astro/*.js 21.54 KB (+0.48% 🔺)
/_astro/*.css 13.14 KB (0%)

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 for the speedy work @kevinzunigacuellar! Left a comment.

@@ -53,6 +53,8 @@ const pagefindTranslations = {
</site-search>

<script>
import { formatPathNoBase } from '../utils/format-path';
Copy link
Member

Choose a reason for hiding this comment

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

I know it might require some code duplication but I’m hesitant about importing this utility into client-side code. Can we move this into a minimal version of the code just for this use case inside the <script> tag?

Copy link
Member Author

@kevinzunigacuellar kevinzunigacuellar Jan 16, 2024

Choose a reason for hiding this comment

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

I am not sure if I understood this correctly, you mean creating a utility inside the script tag just for pagefind?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. Basically to isolate the client-side script from modules that are used elsewhere and might import all kinds of things unintentionally at some point.

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.

@kevinzunigacuellar Thanks for your patience on this one! Was hoping to get a review before today’s release, but because this can go out in a patch, prioritised minor changes instead.

But now I had some time to do some research and tests to see if all this extra client-side JS is needed and I have some fun news: I don’t think so!

I spun up a test project and built with various settings to test out the current behaviour and reached the conclusion that the only change needed is to support trailingSlash: 'never'.

  • With build.format: 'file', Pagefind correctly recognises the format and generates URLs like /guides/example.html
  • With base: 'foo', because we already pass that to Pagefind, it’s handled correctly as /foo/guides/example/

From what I can tell Pagefind always assumes a trailing slash, so we just need to account for the case where it needs stripping. Should be nice to simplify this!

I also think we’ll need a slightly different function than the current stripTrailingSlash() because these paths can be stuff like /guides/example/#heading where the / before the fragment needs stripping.

You still up for reworking this?

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.

Nice, thanks @kevinzunigacuellar! I think we can go even simpler still.

packages/starlight/components/Search.astro Outdated Show resolved Hide resolved
packages/starlight/components/Search.astro Outdated Show resolved Hide resolved
packages/starlight/components/Search.astro Outdated Show resolved Hide resolved
packages/starlight/components/Search.astro Outdated Show resolved Hide resolved
packages/starlight/components/Search.astro Outdated Show resolved Hide resolved
packages/starlight/components/Search.astro Outdated Show resolved Hide resolved
packages/starlight/components/Search.astro Outdated Show resolved Hide resolved
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
@kevinzunigacuellar
Copy link
Member Author

Should we add tests for this new striptrailingslash? I tested locally a few searchs. The only instance where it didn't work was when referencing an id #_top in the landing page. it strips the slash but chrome (I think) automatically adds it back because we are in the / page.

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.

Should we add tests for this new striptrailingslash? I tested locally a few searchs. The only instance where it didn't work was when referencing an id #_top in the landing page. it strips the slash but chrome (I think) automatically adds it back because we are in the / page.

I’m not sure testing would add all that much in this case given how much we don‘t control in this context and how relatively simple the function is. I updated the regular expression to handle the case you mentioned and avoid stripping / in the case of things like / or /#something.

Thanks again for tackling this @kevinzunigacuellar! ✨

@delucis delucis merged commit a0af7cc into main Jan 29, 2024
9 checks passed
@delucis delucis deleted the pagefind-config branch January 29, 2024 11:07
@astrobot-houston astrobot-houston mentioned this pull request Jan 29, 2024
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.

config options are not followed in pagefind search
3 participants