2.4 KiB
2.4 KiB
Instructions for Installing and Running PageFind
Install nvm and npx
There are a few ways to install PageFind. I used the npx method, but you can check out other ways from their website. Below is the npx method.
- Install
nvmfrom the git repo using theInstall and Update Script.curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bashnvm install --lts
- Install
npmsudo apt install npm
- Verify Installations
which npxshould print out the path to thenpxbinary.npx --versionshould give you the version that was installed.
Include PageFind Script into Website
- In the
config.tomlfile of the root of thelibertytools.ioproject, set the following:BookSearch = true
cd libertytoolsio/themes/hugo-book/layouts/_partials/docs- Make a backup of
search.html:cp search.html search.html.bkup
- Open
search.htmland delete the contents. Replace the contents with the following script from the pagefind website:
<link href="/pagefind/pagefind-ui.css" rel="stylesheet">
<script src="/pagefind/pagefind-ui.js"></script>
<div id="search"></div>
<script>
window.addEventListener('DOMContentLoaded', (event) => {
new PagefindUI({ element: "#search", showSubResults: true });
});
</script>
Index the Website
Once the pagefind script has been copied into the libertytoolsio/themes/hugo-book/layouts/_partials/docs/search.html, the search bar should persist across all pages created. To index the website for pagefind we first have to build the site using hugo, then we will have to index the contents of the site using the npx wrapper.
- Build the site:
- From the project root (i.e.
libertytoolsio/),hugo serve
- From the project root (i.e.
- Building the site will publish the html and shit to the
public/directory. We now have to index and rebuild the site in order for pagefind to persist:- From the project root,
npx -y pagefind --site public --serve - If all goes well, you should see something like
Serving "public" at http://localhost:1414at the bottom of the output. Paste the addresshttp://localhost:1414into a browser. You should now see the search bar in the upper left, and it should be available on all pages.
- From the project root,