From c634cb83eb068952bc4c35f3a25c2b66875d2d52 Mon Sep 17 00:00:00 2001 From: loenvom <59039948+loenvom@users.noreply.github.com> Date: Mon, 18 Mar 2024 02:50:22 +0800 Subject: [PATCH] feat: support customize flexsearch tokenize option (#319) Co-authored-by: loenvom --- assets/js/flexsearch.js | 5 +++-- exampleSite/hugo.yaml | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/assets/js/flexsearch.js b/assets/js/flexsearch.js index 15e5a1d2..1c5eb35b 100644 --- a/assets/js/flexsearch.js +++ b/assets/js/flexsearch.js @@ -172,8 +172,9 @@ document.addEventListener("DOMContentLoaded", function () { // Preload the search index. async function preloadIndex() { + const tokenize = '{{- site.Params.search.flexsearch.tokenize | default "forward" -}}'; window.pageIndex = new FlexSearch.Document({ - tokenize: 'forward', + tokenize, cache: 100, document: { id: 'id', @@ -183,7 +184,7 @@ document.addEventListener("DOMContentLoaded", function () { }); window.sectionIndex = new FlexSearch.Document({ - tokenize: 'forward', + tokenize, cache: 100, document: { id: 'id', diff --git a/exampleSite/hugo.yaml b/exampleSite/hugo.yaml index 1def5550..0da0ad99 100644 --- a/exampleSite/hugo.yaml +++ b/exampleSite/hugo.yaml @@ -136,6 +136,9 @@ params: flexsearch: # index page by: content | summary | heading | title index: content + # full | forward | reverse | strict + # https://github.com/nextapps-de/flexsearch/#tokenizer-prefix-search + tokenize: forward editURL: enable: true