Use Pagefind with next.js non static exports.
Install the modules required for the program.
cargo install spider_cli
cargo install pagefind
cargo install next-pagefind
next-pagefind
at the root directory of your next application to create your search index's and output the content into the public
folder.```tsx import { useEffect } from "react";
export function Layout({ Component, pageProps }) { const loaded = useRef(false);
useEffect(() => { if (!loaded.current) { loaded.current = true; const PagefindUI = // @ts-ignore typeof window.PagefindUI !== "undefined" && window.PagefindUI;
if (PagefindUI) {
new PagefindUI({
element: "#search",
resetStyles: false,
showImages: false,
showEmptyFilters: false,
});
}
}
}, [loaded]);
return ( <>
If you need to handle themes include the following css before _/pagefind/pagefind-ui.css
.
Inside your public folder add the following file css/_pagefind.css
with the markup.
```css :root { --pagefind-ui-scale: 1; --pagefind-ui-primary: #034ad8; --pagefind-ui-text: #393939; --pagefind-ui-background: #ffffff; --pagefind-ui-border: #eeeeee; --pagefind-ui-tag: #eeeeee; --pagefind-ui-border-width: 2px; --pagefind-ui-border-radius: 8px; --pagefind-ui-image-border-radius: 8px; --pagefind-ui-image-box-ratio: 3 / 2; --pagefind-ui-font: sans-serif; }
:root.dark { --pagefind-ui-primary: #eeeeee; --pagefind-ui-text: #eeeeee; --pagefind-ui-background: #152028; --pagefind-ui-border: #152028; --pagefind-ui-tag: #152028; } ```
Next include the css before pagefind <link href="/css/_pagefind.css" rel="stylesheet" />
.
spider
and simply use npx -y pagefind --source _temp_spider_downloads --bundle-dir public/_pagefind && cp -R _temp_spider_downloads/public/_pagefind public/_pagefind
to perform the conversion.