diff options
| author | Dennis Fink | 2026-08-09 15:34:34 +0200 |
|---|---|---|
| committer | Dennis Fink | 2026-08-09 15:34:34 +0200 |
| commit | 9b7e535fa76efdd4f76c23f3d7dee8d860b60642 (patch) | |
| tree | 4d204556ef12f5ebd5ab585a05a04fd9cf286908 /packages | |
| parent | 6135bf04509417823b63929524d31c53b47ac901 (diff) | |
| download | dennisfink.me-9b7e535fa76efdd4f76c23f3d7dee8d860b60642.tar.gz dennisfink.me-9b7e535fa76efdd4f76c23f3d7dee8d860b60642.zip | |
Add self-hosted Pagefind search
This adds the Pagefind component UI assets and wires the search modal
into the base template with a compact header trigger.
The integration marks searchable page bodies explicitly, exposes page
titles to Pagefind metadata, and adds site-specific styling so the
search modal, trigger, focus states, and keyboard-selected results match
the blog’s colour scheme.
Diffstat (limited to '')
| -rw-r--r-- | packages/pagefind/lektor_pagefind.py | 44 | ||||
| -rw-r--r-- | packages/pagefind/setup.py | 13 |
2 files changed, 57 insertions, 0 deletions
diff --git a/packages/pagefind/lektor_pagefind.py b/packages/pagefind/lektor_pagefind.py new file mode 100644 index 0000000..17627fc --- /dev/null +++ b/packages/pagefind/lektor_pagefind.py @@ -0,0 +1,44 @@ +from __future__ import annotations + +import subprocess +from pathlib import Path +from typing import Any + +from lektor.pluginsystem import Plugin + +COMPONENT_UI_FILES = ( + "pagefind-component-ui.css", + "pagefind-component-ui.js", +) + + +class PagefindPlugin(Plugin): + name = "Pagefind" + description = "Generate the Pagefind search index." + + def on_after_prune( + self, + builder: Any, + all: bool, + **extra: Any, + ) -> None: + if all: + return + + site_path = Path(builder.destination_path) + + subprocess.run( + [ + "npx", + "pagefind", + "--site", + str(site_path), + ], + cwd=self.env.root_path, + check=True, + ) + + pagefind_path = site_path / "pagefind" + + for filename in COMPONENT_UI_FILES: + (pagefind_path / filename).unlink(missing_ok=True) diff --git a/packages/pagefind/setup.py b/packages/pagefind/setup.py new file mode 100644 index 0000000..066d872 --- /dev/null +++ b/packages/pagefind/setup.py @@ -0,0 +1,13 @@ +from setuptools import setup + +setup( + name="lektor-pagefind", + version="0.1.0", + py_modules=["lektor_pagefind"], + entry_points={ + "lektor.plugins": [ + "pagefind = lektor_pagefind:PagefindPlugin", + ] + }, + install_requires=[], +) |
