Skip to content
staticcanvasPublic

Latest commit

Β 

History

176 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Logo

Hawk

Themeable, pluggable command-palette search UI for static sites, powered by Pagefind.

license github-actions codecov github-issues

github-release github-tag

npm-version npm-downloads

jsr-version jsdelivr-hitsperweek

docs-badge playground-badge gallery-badge


Overview

Hawk adds a keyboard-accessible search palette to a static site using its Pagefind index. Theme and animation plugins let the palette match the site.

πŸ“šTable of Contents

Features

  • Pagefind-backed β€” chunked, lazily-loaded, typo-tolerant search index.
  • Scale-safe result hydration β€” bounded concurrent fragment loading and progressive rendering keep Hawk's network and DOM work predictable for both small and very large indexes.
  • Developer-configured tabs β€” auto-derived category pills, or explicit Pagefind-filter tabs.
  • Fit / medium / compact density modes with a slideout control and a saved preference.
  • Two-pane keyboard navigation β€” Tab between input, filters, results, and preview.
  • Configurable layout β€” scale, position, offset, columns, and a JS-driven breakpoint.
  • Theme and animation plugin systems β€” a TypeFlow typewriter driver ships built-in, alongside a zero-dependency instant driver.
  • Search operators β€” narrow results with tags:API, author:"Ada Lovelace", or filter:category=Guides, and change order with sort:date:desc.
  • Result metadata β€” dates, tags, related pages, and a pin system, each independently themeable and configurable.
  • Built-in trigger element and Pagefind attribution, so no hand-built markup is required.
  • Accessible by default β€” a real modal focus trap, graceful fallback if Pagefind fails to load, and full i18n via config.strings.

See Resources below for the full feature reference.

Installation

npm install @staticcanvas/hawk
npm install --save-dev pagefind
# Optional: the official TypeFlow animation driver
npm install @staticcanvas/typeflow

pagefind is a real dependency (hawk has nothing to search without an index). @staticcanvas/typeflow is an optional peer dependency β€” only needed when importing Hawk's official TypeFlow animation adapter. Hawk core and the TypeFlow visual theme remain independent.

Quick start

import { HawkSearch } from '@staticcanvas/hawk';
import '@staticcanvas/hawk/css';

new HawkSearch({
  index: '/pagefind/',
  preload: true,
  trigger: { container: 'body' },
});

preload: true warms Pagefind and the initial results during idle time after page load. Remove it to load search on first use.

The Result density button beside Escape slides Fit, Medium, and Compact out to the left. Hawk remembers the visitor's choice. Set headerControls.density.layout to 'inline' for always-visible buttons or 'dropdown' for a vertical list. Set headerControls.density to false to hide the size control while keeping Escape.

Try tags: Pagefind sort:date:desc to browse tagged pages newest first. A space after an operator's colon shows a badge while you type its value. Edit the badge as ordinary input text. category:guides matches Guides regardless of case. Use case:category=Guides to require exact case. Result dates are hidden by default. Set showResultDate: true to show them.

The default TypeFlow preview reveal animates only visible content. The rest of the preview is ready to scroll as soon as the page content loads.

Hawk hydrates Pagefind result fragments in ordered batches: up to 6 requests run concurrently, the first completed batch renders immediately, and loading stops once maxResults is filled. Large or exclusion-heavy indexes are bounded to maxCandidateResults candidates (by default, three times maxResults). Both limits are configurable; see the API reference.

trigger renders Hawk's own search button. See Getting started in the docs for the full TypeFlow-themed setup, frontmatter/metadata mapping, and every config option.

Build from source

git clone https://github.com/staticcanvas/hawk.git
cd hawk
npm install
npm run build   # core + optional (theme-typeflow, animation-typeflow, debug, metrics) bundles
npm test        # vitest, jsdom

To build and preview the docs site itself (Hugo + Pagefind, requires Hugo on PATH):

npm run docs:serve

See Development & NPM Scripts for the full script reference.

Acknowledgments

Hawk's development and distribution are supported by these services:

  • jsDelivr β€” open-source CDN delivery.
  • UNPKG β€” CDN delivery for npm packages.
  • npm β€” package registry and distribution.
  • JSR β€” JavaScript and TypeScript package registry.
  • Shields.io β€” project and status badges.
  • GitHub β€” source hosting, CI/CD, releases, and documentation hosting.
  • Codecov β€” test coverage reporting.

Resources

Contributing

Contributions are welcome. For a substantial change, first open an issue to discuss the proposal. For smaller fixes:

  1. Fork the project, then clone your fork: git clone https://github.com/YOUR_USERNAME/hawk.git.

  2. Enter the checkout: cd hawk.

  3. Install the locked dependencies: npm ci.

  4. Create a branch from develop: git switch develop && git switch -c feature/feature-name.

  5. Make your changes, then run npm run lint and npm test.

  6. Commit and push: git commit -m 'Add feature name' && git push -u origin feature/feature-name.

  7. Open a pull request targeting develop:

    Open a GitHub pull request

Links

Development & NPM Scripts

Script Purpose
npm run dev Vite dev server
npm run serve:demo Opens the local web utility demo in Vite
npm run build Builds core + optional (theme-typeflow, animation-typeflow, debug, metrics) bundles
npm run dev:typeflow Builds hawk and copies the bundle + a preview Pagefind index into the sibling typeflow checkout's docs site, for live prototyping
npm run pagefind:index Wraps pagefind --site <dir> β€” see scripts/pagefind-index.mjs
npm test / npm run test:coverage Vitest (jsdom) β€” unit coverage
npm run test:bun / npm run test:coverage:bun Bun test runner, with optional coverage
npm run test:e2e Playwright, real Chromium against a real built docs site + Pagefind index (not a fixture) β€” builds the docs site with a localhost baseURL override first. Runs as a required browser check in GitHub Actions.
npm run lint / npm run lint:fix ESLint
npm run format Formats the repository with Prettier
npm run docs:build / npm run docs:serve Builds and serves hawk's own Hugo docs site
npm run themes:css Generates one small standalone CSS file per gallery/template theme into docs/static/assets/themes/ β€” see scripts/generate-theme-css.mjs
npm run docs:scss Compiles docs/static/assets/scss/*.scss into docs/static/assets/docs.css/playground.css β€” see scripts/compile-docs-scss.mjs. Also runs automatically as part of docs:build/docs:serve
npm run check:size Enforces the gzip bundle size budget
npm run check:jsr Validates the JSR package configuration and dry-run contents
npm run validate:release CI release-artifact validation
npm run check:quality Builds, checks the bundle size, and runs the Vitest suite
npm run bench:size Compares bundle sizes against a selected Git reference

License

Distributed under the MIT License. See LICENSE for details.

CI and release setup is documented in GitHub Actions.

Releases

Packages

Contributors

Languages