Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9d07c97

Browse files
ultimapesehyeon1104
authored andcommittedJan 9, 2023
add optinal lunr searching of pages (#3352)
1 parent 9a9f142 commit 9d07c97

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed
 

‎_config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ atom_feed:
6262
search : # true, false (default)
6363
search_full_content : # true, false (default)
6464
search_provider : # lunr (default), algolia, google
65+
lunr:
66+
search_within_pages : # true, false (default)
6567
algolia:
6668
application_id : # YOUR_APPLICATION_ID
6769
index_name : # YOUR_INDEX_NAME

‎assets/js/lunr/lunr-store.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,38 @@ var store = [
4646
"teaser": {{ teaser | relative_url | jsonify }}
4747
}{%- unless forloop.last and l -%},{%- endunless -%}
4848
{%- endfor -%}
49-
{%- endfor -%}]
49+
{%- endfor -%}{%- if site.lunr.search_within_pages -%},
50+
{%- for doc in site.pages -%}
51+
{%- if forloop.last -%}
52+
{%- assign l = true -%}
53+
{%- endif -%}
54+
{
55+
"title": {{ doc.title | jsonify }},
56+
"excerpt":
57+
{%- if site.search_full_content == true -%}
58+
{{ doc.content | newline_to_br |
59+
replace:"<br />", " " |
60+
replace:"</p>", " " |
61+
replace:"</h1>", " " |
62+
replace:"</h2>", " " |
63+
replace:"</h3>", " " |
64+
replace:"</h4>", " " |
65+
replace:"</h5>", " " |
66+
replace:"</h6>", " "|
67+
strip_html | strip_newlines | jsonify }},
68+
{%- else -%}
69+
{{ doc.content | newline_to_br |
70+
replace:"<br />", " " |
71+
replace:"</p>", " " |
72+
replace:"</h1>", " " |
73+
replace:"</h2>", " " |
74+
replace:"</h3>", " " |
75+
replace:"</h4>", " " |
76+
replace:"</h5>", " " |
77+
replace:"</h6>", " "|
78+
strip_html | strip_newlines | truncatewords: 50 | jsonify }},
79+
{%- endif -%}
80+
"url": {{ doc.url | absolute_url | jsonify }}
81+
}{%- unless forloop.last and l -%},{%- endunless -%}
82+
{%- endfor -%}
83+
{%- endif -%}]

‎docs/_docs/05-configuration.md

+7
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,13 @@ To enable site-wide search add `search: true` to your `_config.yml`.
618618

619619
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.
620620

621+
To have it index all pages, update `lunr` in `_config.yml` like so:
622+
623+
```yaml
624+
lunr:
625+
search_within_pages: true
626+
```
627+
621628
**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.
622629
{: .notice--warning}
623630

0 commit comments

Comments
 (0)
Please sign in to comment.