Classes
LunrIndexGenerator
Generate pre-built Lunr.js search index at build time.
Uses the Python `lunr` package (pure Python…
LunrIndexGenerator
Generate pre-built Lunr.js search index at build time.
Uses the Pythonlunrpackage (pure Python implementation of Lunr.js)
to build a serialized search index that can be loaded directly by the
client-side Lunr.js library.
Field Boosts (matching search.js):
- title: 10x (most important)
- search_keywords: 8x (explicit search terms)
- description: 5x (page summary)
- tags: 3x (categorization)
- section: 2x (content organization)
- author: 2x (authorship)
- content: 1x (full text)
- kind: 1x (content type)
Methods 2
is_available
Check if the lunr Python package is available.
is_available
def is_available(self) -> bool
Check if the lunr Python package is available.
Returns
True if lunr can be imported, False otherwisebool
—
generate
Generate pre-built Lunr index from index.json.
generate
def generate(self, index_json_path: Path | None = None) -> Path | None
Generate pre-built Lunr index from index.json.
Parameters 1
index_json_path |
Path | None |
Path to index.json. If None, uses default location. |
Returns
Path to the generated search-index.json, or None if generation failed.Path | None
—
Internal Methods 6
__init__
Initialize the Lunr index generator.
__init__
def __init__(self, site: Site) -> None
Initialize the Lunr index generator.
Parameters 1
site |
Site |
Site instance with rendered pages |
_build_documents
Build document list for Lunr indexing.
Filters out pages marked for exclusion …
_build_documents
def _build_documents(self, pages: list[dict[str, Any]]) -> list[dict[str, Any]]
Build document list for Lunr indexing.
Filters out pages marked for exclusion and transforms page data into the format expected by Lunr.
Parameters 1
pages |
list[dict[str, Any]] |
List of page dictionaries from index.json |
Returns
List of documents ready for Lunr indexinglist[dict[str, Any]]
—
_get_author
Extract author string from page data.
_get_author
def _get_author(self, page: dict[str, Any]) -> str
Extract author string from page data.
Parameters 1
page |
dict[str, Any] |
Returns
str
_join_list
Join list items into space-separated string.
_join_list
def _join_list(self, items: list[str] | None) -> str
Join list items into space-separated string.
Parameters 1
items |
list[str] | None |
Returns
str
_get_index_json_path
Get the path to index.json, handling i18n prefixes.
_get_index_json_path
def _get_index_json_path(self) -> Path
Get the path to index.json, handling i18n prefixes.
Returns
Path
_get_output_path
Get the output path for search-index.json, handling i18n prefixes.
_get_output_path
def _get_output_path(self) -> Path
Get the output path for search-index.json, handling i18n prefixes.
Returns
Path