shishkin / astro-pagefind Goto Github PK
View Code? Open in Web Editor NEWAstro integration for Pagefind static site search.
License: MIT License
Astro integration for Pagefind static site search.
License: MIT License
npm ERR! Found: [email protected]
npm ERR! node_modules/astro
npm ERR! astro@"^3.0.7" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer astro@"^2.0.4" from [email protected]
npm ERR! node_modules/astro-pagefind
npm ERR! astro-pagefind@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
I was going to make a pull request to fix it, but tbh I could not figure out how to satisfy your commitlint.
Great job on the integration π
One thing I found is that due to the npx
command inside the package, if you run build
script with something else (not npm
), e.g., pnpm
β the build fails. Would be nice to have an option to use other package managers as well.
Thank you!
When you build your project and you're using optimized images, Astro will use a dev url in the format of:
_image?href={path}&origWidth={number}&origHeight={number}&origFormat={image type}&w=300&f=webp
However, pagefind will use the finalized URL of the built image to keep in the pagefind data:
/_astro/{image name}.{random id}.{format}
This causes all images not to be shown when in dev, making it difficult to really tell what the final product is going to be, basically meaning you have to test using live builds.
I've followed all the steps and added <Search />
in my blog page and I can see it on localhost but after deploying it on netlify I can't see search bar on blog page.
Great integration @shishkin! We are using Astro 3.0 in SSR mode with many Markdown pages. Does your astro-pagefind
integration work with SSR pages?
Hello,
Thank you for making this plugin!
After i install your package, when i run pnpm build i get the error: Could not resolve "node:path"
Do you know how to fix this issue? If you need more information let me know.
kind regards
I want to do a search on blog pages only. Is that possible?
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@types/prettier
, eslint
).github/workflows/ci.yaml
actions/checkout v4
actions/setup-node v4
.github/workflows/release.yaml
actions/checkout v4
actions/setup-node v4
package.json
@commitlint/cli 19.2.2
@commitlint/config-conventional 19.2.2
@types/eslint 8.56.10
@types/prettier 2.7.3
@typescript-eslint/eslint-plugin 7.7.0
@typescript-eslint/parser 7.7.0
eslint 8.57.0
eslint-config-prettier 9.1.0
eslint-plugin-astro 0.34.0
eslint-plugin-prettier 5.1.3
husky 9.0.11
prettier 3.2.5
prettier-plugin-astro 0.13.0
packages/astro-pagefind/package.json
@pagefind/default-ui ^1.0.3
pagefind ^1.0.3
sirv ^2.0.3
@astrojs/check 0.5.10
@astrojs/markdown-remark 5.1.0
@semantic-release/changelog 6.0.3
@semantic-release/git 10.0.1
@types/semantic-release 20.0.6
astro 4.6.3
semantic-release 23.0.8
typescript 5.4.5
astro ^2.0.4 || ^3.0.0 || ^4.0.0
packages/example/package.json
@astrojs/check 0.5.10
astro 4.6.3
typescript 5.4.5
.nvmrc
Hi, thanks for your work on this useful Pagefind integration for Astro!
I use it in an open-source project where Renovate automatically updates dependencies, and as a result I have noticed that bumping astro-pagefind
from 1.2.3 to 1.2.3 caused some new TypeScript checking errors, which you can read in this CI workflow run log.
Since this is a patch release, there should not be any breaking changes like this. As far as I know, my project isn't doing anything wrong with how it integrates astro-pagefind
, but I'd love to hear if I'm wrong or should change something on my end.
I think it would be neat for the component to be able to use a query string.
/search?q=my-search-term
I just updated to Astro v2.9.0, when I try to build my app with the following command: astro check && tsc --noEmit && vue-tsc --noEmit && astro build
I get this error that prevents the build progress.
node_modules/astro-pagefind/src/pagefind.ts:14:19 - error TS2352: Conversion of type 'AstroConfig' to type 'Required<AstroUserConfig>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Type 'AstroConfig' is missing the following properties from type 'Required<AstroUserConfig>': renderers, projectRoot, src, pages, and 6 more.
14 const c = config as Config;
~~~~~~~~~~~~~~~~
Found 1 error in node_modules/astro-pagefind/src/pagefind.ts:14
main
branch failed. π¨I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.
You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. Iβm sure you can fix this πͺ.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main
branch. You can also manually restart the failed CI job that runs semantic-release.
If you are not sure how to resolve this, here are some links that can help you:
If those donβt help, or if this issue is reporting something you think isnβt right, you can always ask the humans behind semantic-release.
The npm token configured in the NPM_TOKEN
environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/
.
If you are using Two Factor Authentication for your account, set its level to "Authorization only" in your account settings. semantic-release cannot publish with the default "
Authorization and writes" level.
Please make sure to set the NPM_TOKEN
environment variable in your CI with the exact value of the npm token.
Good luck with your project β¨
Your semantic-release bot π¦π
When output type is set to server
instead of hybrid
or static
the following is shown when building the project (and search is broken)
16:07:20 [WARN] [pagefind] Output type `server` does not produce static *.html pages in its output and thus will not work with astro-pagefind integration.
16:07:20 [WARN] [pagefind] astro-pagefind couldn't reliably determine the output directory. Search assets will not be served.
However for pages marked export const prerender=true
a HTML will still be generated. Is there any specific limitation that prevents pagefind from scanning those files?
I faced issue that my project failed in build because command npx pagefind
falled on cloudflare CI for some reason.
Then I made pnpm add pagefind
and it worked.
Maybe we should install it along with astro-pagefind
? And update installation guide accordingly
The package has been updated to include Astro v4 as a peer dependency, but this has not been republished on npmjs.com so the published package still requires astro v3.
Hi!
thanks for this awesome integration of pagefind and Astro! Setting this up is really easy π
I find myself constantly overriding pagefind's CSS selectors when adjusting the styling to my own needs.
In the docs of pagefind there is a section called "Styling pagefind ui yourself" which basically says: "don't use the CSS file": https://pagefind.app/docs/ui-usage/#styling-pagefind-ui-yourself
Is it a possibility for you to make an unstyled version of your integration?
because ID "search" is hardcoded, only 1 search box per page will attach.
The underlying pagefind library allows one to specify the id, so that multiple searches are available on the page.
This would be useful in the situation where a search bar in a global header gives truncated results, while a dedicated search page handles longer queries (which itself would have the global header available).
In the latest v1.2.1, Pagefind is unable to build an index and reports 0 files found when walking the source directory even though the correct output dir is used and there are ~60 .html files in that folder generated by the build.
I believe this is due to line 29 in pagefind.ts:
29 const path = fileURLToPath(dir);
30 const cmd = `npx pagefind --source "${path}"`;
This sets the path
variable to the full path of the output directory on my drive, as opposed to just the dir name, "dist".
This is the Pagefind console output on running astro build :
Running Pagefind v0.12.0 (Extended)
Running from: "C:\\Users\\tyler\\projects\\astro-site"
Source: "C:\\Users\\tyler\\projects\\astro-site\\dist\""
Bundle Directory: "_pagefind"
[Walking source directory]
Found 0 files matching **/*.{html}
[Parsing files]
Did not find a data-pagefind-body element on the site.
β³ Indexing all <body> elements on the site.
[Reading languages]
Discovered 0 languages:
[Building search indexes]
Total:
Indexed 0 languages
Indexed 0 pages
Indexed 0 words
Indexed 0 filters
Indexed 0 sorts
Error: Pagefind wasn't able to build an index.
If I install Pagefind manually (not astro-pagefind) and invoke it in the postbuild script of package.json with "postbuild": "pagefind --source dist"
, the source directory is just "dist" instead of the full path and the index is generated successfully:
Running Pagefind v0.12.0 (Extended)
Running from: "C:\\Users\\tyler\\projects\\astro-site"
Source: "dist"
Bundle Directory: "_pagefind"
[Walking source directory]
Found 65 files matching **/*.{html}
[Parsing files]
Did not find a data-pagefind-body element on the site.
β³ Indexing all <body> elements on the site.
[Reading languages]
Discovered 1 language: en
[Building search indexes]
Total:
Indexed 1 language
Indexed 64 pages
Indexed 2322 words
Indexed 0 filters
Indexed 0 sorts
If there was a way to force astro-pagefind to use an explicitly defined output directory path, as opposed to always running it through the fileURLToPath(dir)
function, that should allow users to navigate around this issue.
Got this error when attempting to install:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/astro
npm ERR! astro@"^4.0.3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer astro@"^2.0.4 || ^3.0.0" from [email protected]
npm ERR! node_modules/astro-pagefind
npm ERR! astro-pagefind@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
The integration works well when I run astro preview
however if I run astro dev
the search just hangs and doesn't find any results.
I've followed the basic steps, i.e. installing the integration, adding it to config, and importing the Search component.
Indexing support in pagefind would be useful in this integration.
Thanks for developing this integration, it makes things easier.
I'd like to pass showSubResults: true
to the PagefindUI
constructor. Perhaps you could add a uiOptions
prop to the Search component in case more options are added in future?
Hi I've configured the plugin properly it works great in dev mode after building the code.
But the UI doesn't get loaded in preview.
I do not get any errors in console as well, however the JS file is loaded in the browser console.
On one of my sites, astro-pagefind works beautifully in dev mode and finds the prebuilt index and the output pagefind.js in dist/_pagefind. On two of my sites, dev mode returns 404s for pagefind.js. I'm going through the sites file by file for anything that could affect this and I cannot tell the difference. Have you seen this behavior at all?
Thank you! Love this integration so much.
Hello, what is needed to setup this Pagefind in astro project?
I added pagefind() to integration, when I run npx pagefind --source dist
it works:
but when I try to build my project all the time I have this issue:
Error: Pagefind wasn't able to build an index. Most likely, the directory passed to Pagefind was empty or did not contain any html files.
Hi there, great plugin. I am however having a strange issue.
The plugin only works when I run my project in dev mode. When I run it in preview mode or when I deploy the project to Netlify, the search box just doesn't show up. I can see the pages being successfully indexed in the deploy, but nothing shows up on the search page.
However, when I run it in dev mode everything works just fine.
Have you come across this before?
Thanks,
Alex
Hello,
With the pagefind searhc library you can set custom translations:
see: https://pagefind.app/docs/ui/#translations
how can i arrange this using this integration
Issues dependency warnings with Astro 4
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.