mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-04-17 00:22:24 -06:00
Improved search preview
This commit is contained in:
parent
447ba4f20c
commit
9495640378
@ -129,6 +129,7 @@
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 40%;
|
width: 40%;
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
|
word-wrap: break-word;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,6 +146,7 @@
|
|||||||
@include mq(sm) {
|
@include mq(sm) {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 60%;
|
width: 60%;
|
||||||
|
vertical-align: top;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ function initSearch() {
|
|||||||
// Success!
|
// Success!
|
||||||
var data = JSON.parse(request.responseText);
|
var data = JSON.parse(request.responseText);
|
||||||
|
|
||||||
|
lunr.tokenizer.separator = /[\s\-/]+/
|
||||||
var index = lunr(function () {
|
var index = lunr(function () {
|
||||||
this.ref('id');
|
this.ref('id');
|
||||||
this.field('title', { boost: 200 });
|
this.field('title', { boost: 200 });
|
||||||
@ -220,7 +221,7 @@ function initSearch() {
|
|||||||
var nextSpace = doc.content.indexOf(' ', previewEnd + 1);
|
var nextSpace = doc.content.indexOf(' ', previewEnd + 1);
|
||||||
var nextDot = doc.content.indexOf('.', previewEnd + 1);
|
var nextDot = doc.content.indexOf('.', previewEnd + 1);
|
||||||
if ((nextDot > 0) && (nextDot < nextSpace)) {
|
if ((nextDot > 0) && (nextDot < nextSpace)) {
|
||||||
previewEnd = nextDot + 1;
|
previewEnd = nextDot;
|
||||||
ellipsesAfter = false;
|
ellipsesAfter = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -238,7 +239,7 @@ function initSearch() {
|
|||||||
preview += '<span class="search-result-highlight">' + doc.content.substring(start, end) + '</span>';
|
preview += '<span class="search-result-highlight">' + doc.content.substring(start, end) + '</span>';
|
||||||
preview += doc.content.substring(end, previewEnd);
|
preview += doc.content.substring(end, previewEnd);
|
||||||
if (ellipsesAfter) {
|
if (ellipsesAfter) {
|
||||||
preview += '...';
|
preview += ' ...';
|
||||||
}
|
}
|
||||||
|
|
||||||
var resultPreview = document.createElement('div');
|
var resultPreview = document.createElement('div');
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
{% for page in site.html_pages %}{% if page.search_exclude != true %}"{{ forloop.index0 }}": {
|
{% for page in site.html_pages %}{% if page.search_exclude != true %}"{{ forloop.index0 }}": {
|
||||||
"id": "{{ forloop.index0 }}",
|
"id": "{{ forloop.index0 }}",
|
||||||
"title": "{{ page.title | replace: '&', '&' }}",
|
"title": "{{ page.title | replace: '&', '&' }}",
|
||||||
"content": "{{ page.content | markdownify | strip_html | escape_once | remove: 'Table of contents' | remove: '```' | remove: '---' | replace: '\', ' ' | normalize_whitespace }}",
|
"content": "{{ page.content | markdownify | replace: '</h', ' . </h' | replace: '<hr', ' . <hr' | replace: '</p', ' . </p' | replace: '</ul', ' . </ul' | replace: '</tr', ' . </tr' | replace: '</li', ' | </li' | replace: '</td', ' | </td' | strip_html | escape_once | remove: 'Table of contents' | remove: '```' | remove: '---' | replace: '\', ' ' | replace: ' . . . ', ' . ' | replace: ' . . ', ' . ' | normalize_whitespace }}",
|
||||||
"url": "{{ page.url | absolute_url }}",
|
"url": "{{ page.url | absolute_url }}",
|
||||||
"relUrl": "{{ page.url }}"
|
"relUrl": "{{ page.url }}"
|
||||||
}{% unless forloop.last %},{% endunless %}
|
}{% unless forloop.last %},{% endunless %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user