feat(search): support different search index types (#145)

* add support for different search index types: `content | summary | heading | title`
* resolves #139
This commit is contained in:
Xin
2023-10-21 16:00:39 -04:00
committed by GitHub
parent 88b0f1b2ab
commit 93cb788e52
5 changed files with 93 additions and 25 deletions

View File

@ -198,6 +198,37 @@ By default, the page width is set to `normal`.
Similarly, the width of the navbar and footer can be customized by the `params.navbar.width` and `params.footer.width` parameters.
### Search Index
Full-text search powered by [FlexSearch](https://github.com/nextapps-de/flexsearch) is enabled by default.
To customize the search index, set the `params.search.flexsearch.index` parameter in the config file:
```yaml {filename="hugo.yaml"}
params:
# Search
search:
enable: true
type: flexsearch
flexsearch:
# index page by: content | summary | heading | title
index: content
```
available options for `flexsearch.index`:
- `content` - full content of the page (default)
- `summary` - summary of the page, see [Hugo Content Summaries](https://gohugo.io/content-management/summaries/) for more details
- `heading` - level 1 and level 2 headings
- `title` - only include the page title
To exclude a page from the search index, set the `excludeSearch: true` in the front matter of the page:
```yaml {filename="content/docs/guide/configuration.md"}
---
title: Configuration
excludeSearch: true
---
```
### Google Analytics

View File

@ -117,8 +117,15 @@ params:
displayUpdatedDate: true
dateFormat: "January 2, 2006"
# Search
# flexsearch is enabled by default
search:
enable: true
type: flexsearch
flexsearch:
# index page by: content | summary | heading | title
index: content
editURL:
enable: true