CloudCannon / pagefind

Static low-bandwidth search at scale
https://pagefind.app
MIT License
3.48k stars 113 forks source link

Document Jekyll integration #76

Open itamarst opened 2 years ago

itamarst commented 2 years ago

It would be useful to have this documented.

For reference, I've gotten it working by adding a file called pagefind.rb to _plugins/ with the following contents:

Jekyll::Hooks.register :site, :post_write do |site|
  system("pagefind --source '%{path}'" % {:path => site.dest})
end
bglw commented 2 years ago

Hi @itamarst 👋

If you do land with a good code sample I could look at adding some SSG specific guides to the documentation. The recommended way to run Pagefind is after your primary build, so usually more along the lines of changing your build command to:

bundle exec jekyll build && pagefind --source _site

Happy to document options though so let me know if you resolve any issues you're having with your setup and I can look at the docs 🙂

itamarst commented 2 years ago

The above essentially does it after the build, just, automatically. The problem is probably actually #77.

itamarst commented 2 years ago

Updated above to note that actually works. Very slick build, in general!

itamarst commented 2 years ago

The final version I went with was:

Jekyll::Hooks.register :site, :post_write do |site|
  system("npx -y pagefind --source '%{path}'" % {:path => site.dest})
end

which has the benefit of Just Working on Netlify (and any computer with npx installed).

bglw commented 2 years ago

Awesome — I have some docs work to do soon and I'll look at adding some SSG tips 🙂

mstewartgallus commented 1 year ago

Not really a problem here because the input is relatively safe but you want to avoid calling into the shell.

Something like the following should probably work

 system "npx", "-y", "pagefind", "--source",  site.dest