mirror of
https://github.com/alex-shpak/hugo-book.git
synced 2024-11-28 14:10:14 +00:00
parent
05c6336d22
commit
f416a71bf8
@ -194,6 +194,12 @@ ul.pagination {
|
|||||||
|
|
||||||
@include spin(1s);
|
@include spin(1s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#book-search-results {
|
||||||
|
small {
|
||||||
|
opacity: .5;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.book-toc {
|
.book-toc {
|
||||||
|
@ -10,18 +10,21 @@
|
|||||||
indexCfg.doc = {
|
indexCfg.doc = {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
field: ['title', 'content'],
|
field: ['title', 'content'],
|
||||||
store: ['title', 'href'],
|
store: ['title', 'href', 'section'],
|
||||||
};
|
};
|
||||||
|
|
||||||
const index = FlexSearch.create('balance', indexCfg);
|
const index = FlexSearch.create('balance', indexCfg);
|
||||||
window.bookSearchIndex = index;
|
window.bookSearchIndex = index;
|
||||||
|
|
||||||
{{ range $index, $page := where .Site.Pages "Kind" "in" (slice "page" "section") }}
|
{{ range $index, $page := where .Site.Pages "Kind" "in" (slice "page" "section") }}
|
||||||
|
{{ if $page.Content }}
|
||||||
index.add({
|
index.add({
|
||||||
'id': {{ $index }},
|
'id': {{ $index }},
|
||||||
'href': '{{ $page.RelPermalink }}',
|
'href': '{{ $page.RelPermalink }}',
|
||||||
'title': {{ (partial "docs/title" $page) | jsonify }},
|
'title': {{ (partial "docs/title" $page) | jsonify }},
|
||||||
|
'section': {{ (partial "docs/title" $page.Parent) | jsonify }},
|
||||||
'content': {{ $page.Plain | jsonify }}
|
'content': {{ $page.Plain | jsonify }}
|
||||||
});
|
});
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
})();
|
})();
|
||||||
|
@ -64,11 +64,12 @@
|
|||||||
|
|
||||||
const searchHits = window.bookSearchIndex.search(input.value, 10);
|
const searchHits = window.bookSearchIndex.search(input.value, 10);
|
||||||
searchHits.forEach(function (page) {
|
searchHits.forEach(function (page) {
|
||||||
const li = document.createElement('li'),
|
const li = element('<li><a href></a><small></small></li>');
|
||||||
a = li.appendChild(document.createElement('a'));
|
const a = li.querySelector('a'), small = li.querySelector('small');
|
||||||
|
|
||||||
a.href = page.href;
|
a.href = page.href;
|
||||||
a.textContent = page.title;
|
a.textContent = page.title;
|
||||||
|
small.textContent = page.section;
|
||||||
|
|
||||||
results.appendChild(li);
|
results.appendChild(li);
|
||||||
});
|
});
|
||||||
@ -87,4 +88,14 @@
|
|||||||
|
|
||||||
document.head.appendChild(script);
|
document.head.appendChild(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} content
|
||||||
|
* @returns {Node}
|
||||||
|
*/
|
||||||
|
function element(content) {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.innerHTML = content;
|
||||||
|
return div.firstChild;
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
{"Target":"book.min.b3215d9d1d18d9051e7fbe8f256ff80e30f41d29073b86348e230d297b771002.css","MediaType":"text/css","Data":{"Integrity":"sha256-syFdnR0Y2QUef76PJW/4DjD0HSkHO4Y0jiMNKXt3EAI="}}
|
{"Target":"book.min.f11f00e4d2659e7749c679f7a29960dab5462bcb609a767e0f2ea963159b9024.css","MediaType":"text/css","Data":{"Integrity":"sha256-8R8A5NJlnndJxnn3oplg2rVGK8tgmnZ+Dy6pYxWbkCQ="}}
|
Loading…
Reference in New Issue
Block a user