From e87060f707c107eeb99295e961eb1437d0dd0436 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Wed, 31 Dec 2025 16:43:04 +0800 Subject: [PATCH] perf(search): enable anchorify for headings in search results (#672) --- assets/js/theme.js | 1 + hugo.toml | 2 + layouts/home.search.json | 92 +++++++++++++++++++++++++--------------- 3 files changed, 61 insertions(+), 34 deletions(-) diff --git a/assets/js/theme.js b/assets/js/theme.js index 087110c0..9d852fa8 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -372,6 +372,7 @@ class FixIt { } ); autosearch.on('autocomplete:selected', (_event, suggestion, _dataset, _context) => { + document.getElementById('mask')?.click(); window.location.assign(suggestion.uri); }); if (isMobile) { diff --git a/hugo.toml b/hugo.toml index c89f2631..5af42bcc 100644 --- a/hugo.toml +++ b/hugo.toml @@ -496,6 +496,8 @@ snippetLength = 30 highlightTag = "em" # whether to use the absolute URL based on the baseURL in search index absoluteURL = false +# FixIt 0.4.0 | NEW whether to enable anchorify for headings in search results +anchorify = true [params.search.algolia] index = "" diff --git a/layouts/home.search.json b/layouts/home.search.json index 18eae38c..f0907ace 100644 --- a/layouts/home.search.json +++ b/layouts/home.search.json @@ -22,48 +22,72 @@ {{/* Remove line number for code */}} {{- $content = $content | replaceRE ` *\d*\n?` "" -}} {{- $content = $content | replaceRE ` class="heading-element"` "" -}} - {{- $anchor := "" -}} - {{- range $h, $contenth := split $content "

") 0) `"` "" -}} - {{- $contenth = printf "

") 0) `"` "" -}} + {{- $contenth = printf "

") 0) `"` "" -}} + {{- $contenti = printf "

") 0) `"` "" -}} + {{- $contentj = printf "

") 0) `"` "" -}} + {{- $contentk = printf "

") 0) `"` "" -}} + {{- $contentk = printf "

") 0) `"` "" -}} + {{- $contentm = printf "
") 0) `"` "" -}} {{- $contenti = printf "

") 0) `"` "" -}} {{- $contentj = printf "

") 0) `"` "" -}} - {{- $contentk = printf "

") 0) `"` "" -}} - {{- $contentk = printf "

") 0) `"` "" -}} - {{- $contentm = printf "