Skip to content

Commit

Permalink
Add offlineSearchSummaryLength to config.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed May 23, 2020
1 parent 88311ff commit 3c17f0f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion assets/json/offline-search-index.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- $.Scratch.Add "offline-search-index" slice -}}
{{- range where .Site.AllPages ".Params.exclude_search" "!=" true -}}
{{- $.Scratch.Add "offline-search-index" (dict "title" (.Title | htmlUnescape) "ref" .RelPermalink "body" (.Plain | htmlUnescape) "excerpt" (.Summary | htmlUnescape | truncate 100)) -}}
{{- $.Scratch.Add "offline-search-index" (dict "title" (.Title | htmlUnescape) "ref" .RelPermalink "body" (.Plain | htmlUnescape) "excerpt" (.Plain | htmlUnescape | truncate (.Site.Params.offlineSearchSummaryLength | default 70))) -}}
{{- end -}}
{{- $.Scratch.Get "offline-search-index" | jsonify -}}
3 changes: 1 addition & 2 deletions userguide/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ algolia_docsearch = false

#Enable offline search with Lunr.js
offlineSearch = false
offlineSearchSummaryLength = 70

# User interface configuration
[params.ui]
Expand Down Expand Up @@ -188,5 +189,3 @@ enable = false
# url = "https://example.org/mail"
# icon = "fa fa-envelope"
# desc = "Discuss development issues around the project"


10 changes: 10 additions & 0 deletions userguide/content/en/docs/Adding content/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ Once you've completed these steps, local search is enabled for your site and res
If you're [testing this locally](/docs/deployment/#serving-your-site-locally) using Hugo’s local server functionality, you need to build your `offline-search-index.xxx.json` file first by running `hugo`. If you have the Hugo server running while you build `offline-search-index.xxx.json`, you may need to stop the server and restart it in order to see your search results.
{{% /alert %}}

### Changing the summary length of the local search results

You can customize the summary length by setting `offlineSearchSummaryLength` in `config.toml`.

```
#Enable offline search with Lunr.js
offlineSearch = true
offlineSearchSummaryLength = 200
```

### Changing the width of the local search results popover

The width of the search results popover will automatically widen according to the content.
Expand Down

0 comments on commit 3c17f0f

Please sign in to comment.