From c2895e5c2af553544be1a921fb9fe1667b17491e Mon Sep 17 00:00:00 2001 From: Alvaro Torres Cogollo Date: Tue, 10 Nov 2020 22:50:21 +0100 Subject: [PATCH] Allow geekdocSearchShowParent --- assets/js/search-data.js | 3 ++- assets/js/search.js | 5 +++++ exampleSite/content/usage/configuration.md | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/assets/js/search-data.js b/assets/js/search-data.js index 6dcc37f..7ce2cd8 100644 --- a/assets/js/search-data.js +++ b/assets/js/search-data.js @@ -10,7 +10,7 @@ indexCfg.doc = { id: 'id', field: ['title', 'content'], - store: ['title', 'href'], + store: ['title', 'href', 'parent'], }; const index = FlexSearch.create(indexCfg); @@ -21,6 +21,7 @@ 'id': {{ $index }}, 'href': '{{ $page.RelPermalink }}', 'title': {{ (partial "title" $page) | jsonify }}, + 'parent': {{ with $page.Parent }}{{ (partial "title" .) | jsonify }}{{ else }}''{{ end }}, 'content': {{ $page.Plain | jsonify }} }); {{- end -}} diff --git a/assets/js/search.js b/assets/js/search.js index fd4cd99..6e5d1e7 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -46,7 +46,12 @@ a = li.appendChild(document.createElement('a')); a.href = page.href; + + {{ if .Site.Params.GeekdocSearchShowParent }} + a.textContent = page.parent ? page.parent + ' / ' + page.title : page.title; + {{ else }} a.textContent = page.title; + {{ end }} results.appendChild(li); results.classList.add("DUMMY"); diff --git a/exampleSite/content/usage/configuration.md b/exampleSite/content/usage/configuration.md index e7131e8..e19d466 100644 --- a/exampleSite/content/usage/configuration.md +++ b/exampleSite/content/usage/configuration.md @@ -62,6 +62,11 @@ enableGitInfo = true # Index is built on the fly and might slowdown your website. geekdocSearch = false + # (Optional, default false) Display search results with the parent folder as prefix. This + # option allows you to distinguish between files with the same name in different folders. + # NOTE: This parameter only applies when geekdocSearch=true + GeekdocSearchShowParent = true + # (Optional, default none) Add a link to your Legal Notice page to the site footer. # It can be either a remote url or a local file path relative to your content directory. geekdocLegalNotice = "https://blog.example.com/legal" @@ -137,6 +142,11 @@ params: # Index is built on the fly and might slowdown your website. geekdocSearch: false + # (Optional, default false) Display search results with the parent folder as prefix. This + # option allows you to distinguish between files with the same name in different folders. + # NOTE: This parameter only applies when geekdocSearch=true + GeekdocSearchShowParent: true + # (Optional, default none) Add a link to your Legal Notice page to the site footer. # It can be either a remote url or a local file path relative to your content directory. geekdocLegalNotice: "https://blog.example.com/legal"