Site Search
A pure vanilla JS implementation based of Combobox and Pagefind API
It allows indexing and searching static sites without third parties and no database
Anatomy
The Site Search component consists of the following data-part
root
label
control
title
input
trigger
positioner
content
Before using Pagefind, you need to build your site and run the indexing process.
If you're using Vite, start by building your site:
npm run build
Once the build is complete, run Pagefind to index your site:
npm install -D pagefind
npx pagefind --site "dist"
Finally, make sure to initialize Pagefind in your main TypeScript file.
import { initializeSiteSearch } from "@netoum/corex/components/site-search";
(async () => {
try {
// @ts-ignore
const pagefind = await import("../dist/pagefind/pagefind.js");
await pagefind.options({
bundlePath: "../dist/pagefind/pagefind.js",
baseUrl: "/",
});
await pagefind.init();
console.log("Pagefind initialized");
initializeSiteSearch(pagefind);
} catch (error) {
console.error("Failed to initialize Pagefind:", error);
}
})();
Data attributes
Each site-search can be set with different settings with the following data-attribute.
Refer to the Comboxbox component for more details
Templates
Site Search components is available in the followng templates
-
Corex template
Default corex templates. It provides the global, semantic and components tokens
-
Modex template
Based on Corex default template, it adds dark and light mode option to the tokens
-
Themex template
Based on the Corex default template, it adds theming capabilities as well as light and dark mode options to the tokens.