Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- add framework for custom content into
  Lunr indices
  • Loading branch information
diablodale committed Dec 19, 2022
1 parent 6d9d413 commit 9d861f1
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 1 deletion.
Empty file added _includes/lunr-data.json
Empty file.
Empty file added _includes/lunr-index.js
Empty file.
3 changes: 2 additions & 1 deletion assets/js/just-the-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function initSearch() {
request.onload = function(){
if (request.status >= 200 && request.status < 400) {
var docs = JSON.parse(request.responseText);

lunr.tokenizer.separator = {{ site.search.tokenizer_separator | default: site.search_tokenizer_separator | default: "/[\s\-/]+/" }}

var index = lunr(function(){
Expand All @@ -87,6 +87,7 @@ function initSearch() {
this.metadataWhitelist = ['position']

for (var i in docs) {
{% include lunr-index.js %}
this.add({
id: i,
title: docs[i].title,
Expand Down
2 changes: 2 additions & 0 deletions assets/js/zzzz-search-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ permalink: /assets/js/search-data.json
"title": {{ title | jsonify }},
"content": {{ content | replace: '</h', ' . </h' | replace: '<hr', ' . <hr' | replace: '</p', ' . </p' | replace: '<ul', ' . <ul' | replace: '</ul', ' . </ul' | replace: '<ol', ' . <ol' | replace: '</ol', ' . </ol' | replace: '</tr', ' . </tr' | replace: '<li', ' | <li' | replace: '</li', ' | </li' | replace: '</td', ' | </td' | replace: '<td', ' | <td' | replace: '</th', ' | </th' | replace: '<th', ' | <th' | strip_html | remove: 'Table of contents' | normalize_whitespace | replace: '. . .', '.' | replace: '. .', '.' | replace: '| |', '|' | append: ' ' | jsonify }},
"url": "{{ url | relative_url }}",
{% include lunr-data.json page=page %}
"relUrl": "{{ url }}"
}
{%- assign i = i | plus: 1 -%}
Expand All @@ -62,6 +63,7 @@ permalink: /assets/js/search-data.json
"title": {{ page.title | jsonify }},
"content": {{ parts[0] | replace: '</h', ' . </h' | replace: '<hr', ' . <hr' | replace: '</p', ' . </p' | replace: '<ul', ' . <ul' | replace: '</ul', ' . </ul' | replace: '<ol', ' . <ol' | replace: '</ol', ' . </ol' | replace: '</tr', ' . </tr' | replace: '<li', ' | <li' | replace: '</li', ' | </li' | replace: '</td', ' | </td' | replace: '<td', ' | <td' | replace: '</th', ' | </th' | replace: '<th', ' | <th' | strip_html | remove: 'Table of contents' | normalize_whitespace | replace: '. . .', '.' | replace: '. .', '.' | replace: '| |', '|' | append: ' ' | jsonify }},
"url": "{{ page.url | relative_url }}",
{% include lunr-data.json page=page %}
"relUrl": "{{ page.url }}"
}
{%- assign i = i | plus: 1 -%}
Expand Down
2 changes: 2 additions & 0 deletions lib/tasks/search.rake
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ permalink: /assets/js/search-data.json
"title": {{ title | jsonify }},
"content": {{ content | replace: \'</h\', \' . </h\' | replace: \'<hr\', \' . <hr\' | replace: \'</p\', \' . </p\' | replace: \'<ul\', \' . <ul\' | replace: \'</ul\', \' . </ul\' | replace: \'<ol\', \' . <ol\' | replace: \'</ol\', \' . </ol\' | replace: \'</tr\', \' . </tr\' | replace: \'<li\', \' | <li\' | replace: \'</li\', \' | </li\' | replace: \'</td\', \' | </td\' | replace: \'<td\', \' | <td\' | replace: \'</th\', \' | </th\' | replace: \'<th\', \' | <th\' | strip_html | remove: \'Table of contents\' | normalize_whitespace | replace: \'. . .\', \'.\' | replace: \'. .\', \'.\' | replace: \'| |\', \'|\' | append: \' \' | jsonify }},
"url": "{{ url | relative_url }}",
{% include lunr-data.json page=page %}
"relUrl": "{{ url }}"
}
{%- assign i = i | plus: 1 -%}
Expand All @@ -72,6 +73,7 @@ permalink: /assets/js/search-data.json
"title": {{ page.title | jsonify }},
"content": {{ parts[0] | replace: \'</h\', \' . </h\' | replace: \'<hr\', \' . <hr\' | replace: \'</p\', \' . </p\' | replace: \'<ul\', \' . <ul\' | replace: \'</ul\', \' . </ul\' | replace: \'<ol\', \' . <ol\' | replace: \'</ol\', \' . </ol\' | replace: \'</tr\', \' . </tr\' | replace: \'<li\', \' | <li\' | replace: \'</li\', \' | </li\' | replace: \'</td\', \' | </td\' | replace: \'<td\', \' | <td\' | replace: \'</th\', \' | </th\' | replace: \'<th\', \' | <th\' | strip_html | remove: \'Table of contents\' | normalize_whitespace | replace: \'. . .\', \'.\' | replace: \'. .\', \'.\' | replace: \'| |\', \'|\' | append: \' \' | jsonify }},
"url": "{{ page.url | relative_url }}",
{% include lunr-data.json page=page %}
"relUrl": "{{ page.url }}"
}
{%- assign i = i | plus: 1 -%}
Expand Down

0 comments on commit 9d861f1

Please sign in to comment.