feat: apply Pagefind attributes by selector through config rules
exclude_selectors is the only way the config can reach into a page, and it carries the semantics of data-pagefind-ignore="index". Every other control Pagefind has lives on an attribute, so reaching it from the config meant a new flag per attribute. Add a rules list that pairs a selector with the attributes to set on the elements it matches. The attributes are applied before every other handler, so the rest of the parser reads them exactly as if the page had carried them, and every documented attribute is reachable without new flags. An attribute already present on the element wins, so a rule never overrides markup. A selector that cannot be parsed is reported and skipped. Rules are config-file only: a list of selectors with attribute maps does not fit a CLI flag or an environment variable.
This commit is contained in:
1 parent
c036b250ba
commit
085385c3e4
3 files changed
+163
-3
No files matched your search
@@ -71,6 +71,30 @@ Note that currently Pagefind only supports lists of options via configuration fi
|
||||
|---------------------------|------------------------------|---------------------|
|
||||
| `--exclude-selectors <S>` | `PAGEFIND_EXCLUDE_SELECTORS` | `exclude_selectors` |
|
||||
|
||||
### Rules
|
||||
Applies Pagefind attributes to the elements a selector matches, so a site can be configured with the same vocabulary its HTML would use. For example, in `pagefind.yml`:
|
||||
|
||||
```yml
|
||||
rules:
|
||||
- selector: "#my_navigation"
|
||||
attributes:
|
||||
data-pagefind-ignore: all
|
||||
- selector: ".article-body"
|
||||
attributes:
|
||||
data-pagefind-body: ""
|
||||
data-pagefind-meta: "title[data-title]"
|
||||
```
|
||||
|
||||
Each rule behaves exactly as if the attributes had been written on the matching elements, so the documentation for [indexing attributes](/docs/indexing/) applies unchanged.
|
||||
|
||||
An attribute written in the page always wins over a rule setting the same attribute, so rules never override markup you control. A selector Pagefind cannot parse is reported and skipped, and indexing continues without it.
|
||||
|
||||
Rules are only available via configuration files, as a list of selectors with their attributes does not fit a CLI flag or an environment variable.
|
||||
|
||||
| CLI Flag | ENV Variable | Config Key |
|
||||
|----------|--------------|------------|
|
||||
| n/a | n/a | `rules` |
|
||||
|
||||
### Include characters
|
||||
Prevents Pagefind from stripping the provided characters when indexing content.
|
||||
Allows users to search for words including these characters.
|
||||
|
||||
Reference in new issue
Block a user