forked from drowl87/hextra_mirror
feat: show breadcrumbs in search results (#473)
* Show crumbs in search results * remove unnecessary console.log * amend comment * amend comment again * Implement requested changes
This commit is contained in:
parent
97ea67198b
commit
a97a1791cc
@ -200,7 +200,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
cache: 100,
|
cache: 100,
|
||||||
document: {
|
document: {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
store: ['title'],
|
store: ['title', 'crumb'],
|
||||||
index: "content"
|
index: "content"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -210,7 +210,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
cache: 100,
|
cache: 100,
|
||||||
document: {
|
document: {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
store: ['title', 'content', 'url', 'display'],
|
store: ['title', 'content', 'url', 'display', 'crumb'],
|
||||||
index: "content",
|
index: "content",
|
||||||
tag: 'pageId'
|
tag: 'pageId'
|
||||||
}
|
}
|
||||||
@ -222,6 +222,30 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
for (const route in data) {
|
for (const route in data) {
|
||||||
let pageContent = '';
|
let pageContent = '';
|
||||||
++pageId;
|
++pageId;
|
||||||
|
const urlParts = route.split('/').filter(x => x != "" && !x.startsWith('#'));
|
||||||
|
|
||||||
|
let crumb = '';
|
||||||
|
let searchUrl = '/'
|
||||||
|
for (let i = 0; i < urlParts.length; i++) {
|
||||||
|
const urlPart = urlParts[i];
|
||||||
|
searchUrl += urlPart + '/'
|
||||||
|
|
||||||
|
const crumbData = data[searchUrl];
|
||||||
|
if (!crumbData) {
|
||||||
|
console.warn('Excluded page', searchUrl, '- will not be included for search result breadcrumb for', route);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let title = data[searchUrl].title;
|
||||||
|
if (title == "_index") {
|
||||||
|
title = urlPart.split("-").map(x => x).join(" ");
|
||||||
|
}
|
||||||
|
crumb += title;
|
||||||
|
|
||||||
|
if (i < urlParts.length - 1) {
|
||||||
|
crumb += ' > ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const heading in data[route].data) {
|
for (const heading in data[route].data) {
|
||||||
const [hash, text] = heading.split('#');
|
const [hash, text] = heading.split('#');
|
||||||
@ -235,6 +259,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
id: url,
|
id: url,
|
||||||
url,
|
url,
|
||||||
title,
|
title,
|
||||||
|
crumb,
|
||||||
pageId: `page_${pageId}`,
|
pageId: `page_${pageId}`,
|
||||||
content: title,
|
content: title,
|
||||||
...(paragraphs[0] && { display: paragraphs[0] })
|
...(paragraphs[0] && { display: paragraphs[0] })
|
||||||
@ -245,6 +270,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
id: `${url}_${i}`,
|
id: `${url}_${i}`,
|
||||||
url,
|
url,
|
||||||
title,
|
title,
|
||||||
|
crumb,
|
||||||
pageId: `page_${pageId}`,
|
pageId: `page_${pageId}`,
|
||||||
content: paragraphs[i]
|
content: paragraphs[i]
|
||||||
});
|
});
|
||||||
@ -256,6 +282,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
window.pageIndex.add({
|
window.pageIndex.add({
|
||||||
id: pageId,
|
id: pageId,
|
||||||
title: data[route].title,
|
title: data[route].title,
|
||||||
|
crumb,
|
||||||
content: pageContent
|
content: pageContent
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -308,7 +335,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
_page_rk: i,
|
_page_rk: i,
|
||||||
_section_rk: j,
|
_section_rk: j,
|
||||||
route: url,
|
route: url,
|
||||||
prefix: isFirstItemOfPage ? result.doc.title : undefined,
|
prefix: isFirstItemOfPage ? result.doc.crumb : undefined,
|
||||||
children: { title, content }
|
children: { title, content }
|
||||||
})
|
})
|
||||||
isFirstItemOfPage = false
|
isFirstItemOfPage = false
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
{{- $pages := where .Site.Pages "Kind" "in" (slice "page" "section") -}}
|
{{- $pages := where .Site.Pages "Kind" "in" (slice "page" "section") -}}
|
||||||
{{- $pages = where $pages "Params.excludeSearch" "!=" true -}}
|
{{- $pages = where $pages "Params.excludeSearch" "!=" true -}}
|
||||||
{{- $pages = where $pages "Content" "!=" "" -}}
|
|
||||||
|
|
||||||
{{- $output := dict -}}
|
{{- $output := dict -}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user