add optinal lunr searching of pages (#3352)
This commit is contained in:
parent
a66bf7e317
commit
00b86b1ff8
3 changed files with 44 additions and 1 deletions
|
@ -62,6 +62,8 @@ atom_feed:
|
||||||
search : # true, false (default)
|
search : # true, false (default)
|
||||||
search_full_content : # true, false (default)
|
search_full_content : # true, false (default)
|
||||||
search_provider : # lunr (default), algolia, google
|
search_provider : # lunr (default), algolia, google
|
||||||
|
lunr:
|
||||||
|
search_within_pages : # true, false (default)
|
||||||
algolia:
|
algolia:
|
||||||
application_id : # YOUR_APPLICATION_ID
|
application_id : # YOUR_APPLICATION_ID
|
||||||
index_name : # YOUR_INDEX_NAME
|
index_name : # YOUR_INDEX_NAME
|
||||||
|
|
36
assets/js/lunr/lunr-store.js
vendored
36
assets/js/lunr/lunr-store.js
vendored
|
@ -46,4 +46,38 @@ var store = [
|
||||||
"teaser": {{ teaser | relative_url | jsonify }}
|
"teaser": {{ teaser | relative_url | jsonify }}
|
||||||
}{%- unless forloop.last and l -%},{%- endunless -%}
|
}{%- unless forloop.last and l -%},{%- endunless -%}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
{%- endfor -%}]
|
{%- endfor -%}{%- if site.lunr.search_within_pages -%},
|
||||||
|
{%- for doc in site.pages -%}
|
||||||
|
{%- if forloop.last -%}
|
||||||
|
{%- assign l = true -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{
|
||||||
|
"title": {{ doc.title | jsonify }},
|
||||||
|
"excerpt":
|
||||||
|
{%- if site.search_full_content == true -%}
|
||||||
|
{{ doc.content | newline_to_br |
|
||||||
|
replace:"<br />", " " |
|
||||||
|
replace:"</p>", " " |
|
||||||
|
replace:"</h1>", " " |
|
||||||
|
replace:"</h2>", " " |
|
||||||
|
replace:"</h3>", " " |
|
||||||
|
replace:"</h4>", " " |
|
||||||
|
replace:"</h5>", " " |
|
||||||
|
replace:"</h6>", " "|
|
||||||
|
strip_html | strip_newlines | jsonify }},
|
||||||
|
{%- else -%}
|
||||||
|
{{ doc.content | newline_to_br |
|
||||||
|
replace:"<br />", " " |
|
||||||
|
replace:"</p>", " " |
|
||||||
|
replace:"</h1>", " " |
|
||||||
|
replace:"</h2>", " " |
|
||||||
|
replace:"</h3>", " " |
|
||||||
|
replace:"</h4>", " " |
|
||||||
|
replace:"</h5>", " " |
|
||||||
|
replace:"</h6>", " "|
|
||||||
|
strip_html | strip_newlines | truncatewords: 50 | jsonify }},
|
||||||
|
{%- endif -%}
|
||||||
|
"url": {{ doc.url | absolute_url | jsonify }}
|
||||||
|
}{%- unless forloop.last and l -%},{%- endunless -%}
|
||||||
|
{%- endfor -%}
|
||||||
|
{%- endif -%}]
|
||||||
|
|
|
@ -618,6 +618,13 @@ To enable site-wide search add `search: true` to your `_config.yml`.
|
||||||
|
|
||||||
The default search uses [**Lunr**](https://lunrjs.com/) to build a search index of all post and your documents in collections. This method is 100% compatible with sites hosted on GitHub Pages.
|
The default search uses [**Lunr**](https://lunrjs.com/) to build a search index of all post and your documents in collections. This method is 100% compatible with sites hosted on GitHub Pages.
|
||||||
|
|
||||||
|
To have it index all pages, update `lunr` in `_config.yml` like so:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
lunr:
|
||||||
|
search_within_pages: true
|
||||||
|
```
|
||||||
|
|
||||||
**Note:** Only the first 50 words of a post or page's body content is added to the Lunr search index. Setting `search_full_content` to `true` in your `_config.yml` will override this and could impact page load performance.
|
**Note:** Only the first 50 words of a post or page's body content is added to the Lunr search index. Setting `search_full_content` to `true` in your `_config.yml` will override this and could impact page load performance.
|
||||||
{: .notice--warning}
|
{: .notice--warning}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue