https://github.com/pelican-plugins/search
Pelican plugin that adds site search capability
https://github.com/pelican-plugins/search
pelican pelican-plugins search
Last synced: about 1 year ago
JSON representation
Pelican plugin that adds site search capability
- Host: GitHub
- URL: https://github.com/pelican-plugins/search
- Owner: pelican-plugins
- Created: 2021-11-16T16:03:37.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-12T11:14:29.000Z (almost 2 years ago)
- Last Synced: 2025-03-09T17:52:39.057Z (over 1 year ago)
- Topics: pelican, pelican-plugins, search
- Language: Python
- Homepage:
- Size: 40 KB
- Stars: 51
- Watchers: 5
- Forks: 9
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# Search: A Plugin for Pelican
[](https://github.com/pelican-plugins/search/actions)
[](https://pypi.org/project/pelican-search/)
[](https://pypi.org/project/pelican-search/)

This plugin generates an index for searching content on a Pelican-powered site.
## Why would you want this?
Static sites are, well, static… and thus usually don’t have an application server component that could be used to power site search functionality. Rather than give up control (and privacy) to third-party search engine corporations, this plugin adds elegant and self-hosted site search capability to your site. Last but not least, searches are **really** fast. 🚀
Want to see just _how_ fast? Try it out for yourself. Following are some sites that use this plugin:
* [Justin Mayer](https://justinmayer.com)
* [Open Source Alternatives](https://opensourcealternatives.org)
## Installation
This plugin uses [Stork](https://stork-search.net/) to generate a search index. Follow the [Stork installation instructions](https://stork-search.net/docs/install) to install this required command-line tool and ensure it is available within `/usr/local/bin/` or another `$PATH`-accessible location of your choosing. For example, Stork can be installed on macOS (Intel) via:
export STORKVERSION="v1.5.0"
wget -O /usr/local/bin/stork https://files.stork-search.net/releases/$STORKVERSION/stork-macos-10-15
chmod +x /usr/local/bin/stork
For macOS on ARM, install via Homebrew:
brew install stork-search/stork-tap/stork
Confirm that Stork is properly installed via:
stork --help
Once Stork has been successfully installed and tested, this plugin can be installed via:
python -m pip install pelican-search
If you are using Pelican 4.5+ with namespace plugins and don’t have a `PLUGINS` setting defined in your configuration, then the Search plugin should be auto-discovered with no further action required. If, on the other hand, you _do_ have a `PLUGINS` setting defined (because you also use legacy plugins or because you want to be able to selectively disable installed plugins), then you must manually add `search` to the `PLUGINS` list, as described in the [Pelican plugins documentation][].
## Settings
This plugin’s behavior can be customized via Pelican settings. Those settings, and their default values, follow below.
### `STORK_INPUT_OPTIONS = {}`
In addition to plain-text files, Stork can recognize and index HTML and Markdown-formatted content. The default behavior of this plugin is to index generated HTML files, since Stork is good at extracting content from tags, scripts, and styles. But that mode may require a slight theme modification that isn’t necessary when indexing Markdown source (see HTML selector setting below). That said, indexing Markdown means that markup information may not be removed from the indexed content and will thus be visible in the search preview results. With that caveat aside, if you want to index Markdown source content files instead of the generated HTML output, you can set `base_directory` to your content path.
Any other setting then the output path will toggle the plugin to switch to "source" mode.
**Example**:
```python
STORK_INPUT_OPTIONS = {
"base_directory" : PATH
}
```
#### Stork HTML Selector
By default, Stork looks for `[…]` tags to determine where your main content is located. If such tags do not already exist in your theme’s template files, you can either (1) add `` tags or (2) change the HTML selector that Stork should look for.
To use the default `main` selector, in each of your theme’s relevant template files, wrap the content you want to index with `` tags. For example:
`article.html`:
```jinja
{{ article.content }}
```
`page.html`:
```jinja
{{ page.content }}
```
For more information, refer to [Stork’s documentation on HTML tag selection](https://stork-search.net/docs/html).
**Example**:
To set it to a different selector (for example, `primary`), you can set it like this:
```python
STORK_INPUT_OPTIONS = {
"html_selector" : "primary"
}
```
Additional [Input Options](https://stork-search.net/docs/config-ref) can be added here as a `dict`.
**Example**:
```python
STORK_INPUT_OPTIONS = {
"url_prefix" : SITEURL
}
```
### `STORK_OUTPUT_OPTIONS = {}`
[Output Options](https://stork-search.net/docs/config-ref) can be configured as a `dict`.
Keep in mind that keys are case-sensitive and must be lower case.
**Example**:
```python
STORK_OUTPUT_OPTIONS = {
"debug" : True
}
```
## Static Assets
There are two options for serving the necessary JavaScript, WebAssembly, and CSS static assets:
1. Use a content delivery network (CDN) to serve Stork’s static assets
2. Self-host the Stork static assets
The first option is easier to set up. The second option is provided for folks who prefer to self-host everything. After you have decided which option you prefer, follow the relevant section’s instructions below.
### Static Assets — Option 1: Use CDN
#### CSS
Add the Stork CSS before the closing `` tag in your theme’s base template file, such as `base.html`:
```html
```
If your theme supports dark mode, you may want to also add Stork’s dark CSS file:
```html
```
#### JavaScript
Add the following script tags to your theme’s base template, just before your closing `