Skip to content

Commit 1a8a73c

Browse files
committed
fix: correct search result URLs under subpath deployment
Override themes/hextra/assets/json/search-data.json to use .Permalink instead of .RelPermalink. Under a project page deployment where baseURL has a subpath like /go-tutorial/, RelPermalink omits the subpath, so clicking a search result jumped to the wrong host path. Also switch glossary entry key from relLangURL to absLangURL for the same reason.
1 parent e1cb8f0 commit 1a8a73c

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

assets/json/search-data.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{{/* FlexSearch Index Data — override of themes/hextra/assets/json/search-data.json */}}
2+
{{/* Use .Permalink (absolute URL) instead of .RelPermalink so subpath */}}
3+
{{/* deployments (e.g. project pages at /repo/) link correctly from search results. */}}
4+
{{- $indexType := site.Params.search.flexsearch.index | default "content" -}}
5+
6+
{{- if not (in (slice "content" "summary" "heading" "title" ) $indexType) -}}
7+
{{- errorf "unknown flexsearch index type: %s" $indexType -}}
8+
{{- end -}}
9+
10+
{{- $pages := where .Site.Pages "Kind" "in" (slice "page" "section") -}}
11+
{{- $pages = where $pages "Params.excludeSearch" "!=" true -}}
12+
{{- $pages = where $pages "Content" "!=" "" -}}
13+
14+
{{- $output := dict -}}
15+
16+
{{- range $index, $page := $pages -}}
17+
{{- $pageTitle := $page.LinkTitle | default $page.File.BaseFileName -}}
18+
{{- $pageLink := $page.Permalink -}}
19+
{{- $data := partial "utils/fragments" (dict "context" $page "type" $indexType) -}}
20+
{{- $output = $output | merge (dict $pageLink (dict "title" $pageTitle "data" $data)) -}}
21+
{{- end -}}
22+
23+
{{/* Extract glossary data entries */}}
24+
{{- $glossaryEntries := dict -}}
25+
{{- with (index .Site.Data .Site.Language.Lang "termbase") -}}
26+
{{- range . -}}
27+
{{- $entry := cond (.abbr) (printf "%s %s %s" .abbr .term .definition) (printf "%s %s" .term .definition) -}}
28+
{{- $glossaryEntries = $glossaryEntries | merge (dict .term $entry) -}}
29+
{{- end -}}
30+
{{- end -}}
31+
32+
{{- $glossary := dict
33+
"title" "Glossary"
34+
"data" $glossaryEntries
35+
-}}
36+
37+
{{- $output = $output | merge (dict (absLangURL "glossary") $glossary )}}
38+
39+
{{- $output | jsonify -}}

0 commit comments

Comments
 (0)