GithubHelp home page GithubHelp logo

shishkin / astro-pagefind Goto Github PK

View Code? Open in Web Editor NEW
153.0 4.0 11.0 963 KB

Astro integration for Pagefind static site search.

License: MIT License

Shell 1.09% TypeScript 29.15% JavaScript 16.35% Astro 53.41%
astro pagefind search withastro

astro-pagefind's People

Contributors

renovate[bot] avatar semantic-release-bot avatar shishkin avatar tanerijun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

astro-pagefind's Issues

Peer dependency conflict with astro 3.0

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.

Doesn't work with other package managers

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!

Support Astro Image Optimization

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.

Use in Astro SSR sites?

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?

Not work at Astro 4.0.6

Hi! Thanks for plugin!

Add as in manual, but on dev server got this error

On local server using astro dev got this in browser console
image

If I try astro build:
image

Could not resolve "node:path"

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"

  • I use SSR
  • I use the cloudflare adapter
  • when i'am running pnpm run dev everything is working

Do you know how to fix this issue? If you need more information let me know.

kind regards

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yaml
  • actions/checkout v4
  • actions/setup-node v4
.github/workflows/release.yaml
  • actions/checkout v4
  • actions/setup-node v4
npm
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
nvm
.nvmrc

  • Check this box to trigger a request for Renovate to run again on this repository

Possible TypeScript type definitions regression on 1.2.3

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.

Conversion of type 'AstroConfig' to type 'Required<AstroUserConfig>' - Error

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

The automated release is failing 🚨

🚨 The automated release from the 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.


Invalid npm token.

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 πŸ“¦πŸš€

Should support `prerender=true`

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?

Add possibility to not use pagefind's CSS file

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?

Allow multiple instances on a page

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).

Can't build index; No files found in output dir

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.

Broken with Astro 4.0?

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.

How to make search work with astro dev

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.

Support for indexing

Indexing support in pagefind would be useful in this integration.
Thanks for developing this integration, it makes things easier.

Support showSubResults

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?

Bug: Pagefind doesn't load UI in preview / production

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.

Question - dev mode pagefind.js 404

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.

Error: Pagefind wasn't able to build an index.

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:
image

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.

image

Pagefind only works when I run my project in dev mode.

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

problem with displaying the search field

the search box doesn't show when you go to the next page - looks like an initialization problem - after refreshing it works ok.
Is there any way to fix this?

image

after refresh the page:
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.