Skip to content

Commit

Permalink
fix: import github.com/hugomods/search-index (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang authored Oct 26, 2024
1 parent cbd4214 commit 5a836e5
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 132 deletions.
9 changes: 3 additions & 6 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ isHTML = true
mediaType = 'text/html'
notAlternative = true

[outputFormats.SearchIndex]
baseName = 'search'
isPlainText = true
mediaType = 'application/json'
notAlternative = true

[module]
[module.hugoVersion]
extended = true
min = "0.128.0"

[[module.imports]]
path = "github.com/hugomods/search-index"

[[module.imports]]
path = "github.com/hugomods/i18n-js"

Expand Down
1 change: 0 additions & 1 deletion layouts/_default/index.searchindex.json

This file was deleted.

2 changes: 1 addition & 1 deletion layouts/partials/search/assets/js-resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{{- range .Sites }}
{{- $site := . }}
{{- with .Home.OutputFormats.Get "SearchIndex" }}
{{- $hash := partialCached "search/functions/search-index-hash" $site $site }}
{{- $hash := partialCached "search-index/functions/hash" $site $site }}
{{- $indexURL := printf "%s?v=%s" .Permalink $hash }}
{{- $indices = $indices | append $indexURL }}
{{- end }}
Expand Down
5 changes: 1 addition & 4 deletions layouts/partials/search/functions/pages.html
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
{{- $indexAllPages := default true site.Params.search.index_all_pages -}}
{{- $pages := cond $indexAllPages site.Pages site.RegularPages -}}
{{- $pages = where $pages "Params.noindex" "ne" true -}}
{{- return $pages }}
{{- return partial "search-index/functions/pages" . }}
6 changes: 1 addition & 5 deletions layouts/partials/search/functions/parse-headings.html
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{{- $headings := slice }}
{{- with .Fragments }}
{{- $headings = partial "search/functions/walk-headings" (dict "Headings" .Headings "PID" -1) }}
{{- end }}
{{- return $headings -}}
{{- return partial "search-index/functions/parse-headings" . }}
10 changes: 1 addition & 9 deletions layouts/partials/search/functions/search-index-hash.html
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
{{/* This hashing function just calculate the number of pages and the lastmod time. */}}
{{- $ctx := dict "Site" . }}
{{- $pages := partialCached "search/functions/pages" $ctx .Language.Lang -}}
{{- $hash := printf "total=%d" $pages.Len }}
{{- $latest := first 1 $pages.ByLastmod.Reverse }}
{{- with index $latest 0 }}
{{- $hash = printf "%s&lastmod=%d" $hash .Lastmod.Unix }}
{{- end }}
{{- return ($hash | md5) }}
{{- return partial "search-index/functions/hash" . }}
20 changes: 1 addition & 19 deletions layouts/partials/search/functions/walk-headings.html
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
{{- $v := slice }}
{{- $pid := .PID }}
{{- range .Headings }}
{{- if gt .Level (default 6 site.Params.search.headings_end_level) }}
{{- break }}
{{- end }}
{{- if ne .Title "" }}
{{- $v = $v | append (dict
"pid" $pid
"anchor" .ID
"title" (.Title | plainify))
}}
{{- end }}
{{- $v = $v | append (partial "search/functions/walk-headings" (dict
"Headings" .Headings
"PID" (add $pid (len $v))))
}}
{{- end }}
{{- return $v }}
{{- return partial "search-index/functions/walk-headings" . }}
20 changes: 1 addition & 19 deletions layouts/partials/search/functions/years.html
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
{{- $years := slice }}
{{- if default true site.Params.search.filter_years }}
{{- $indexAllPages := default true site.Params.search.index_all_pages }}
{{- $pages := site.AllPages }}
{{- if not $indexAllPages }}
{{- $pages = where $pages "Kind" "page" }}
{{- end }}
{{- $pages = where $pages "Params.noindex" "ne" true }}
{{- with $pages.GroupByDate "2006" }}
{{- range . }}
{{- if eq .Key "0001" }}
{{- continue }}
{{- end }}
{{- $years = $years | append .Key }}
{{- end }}
{{- $years = sort $years }}
{{- end }}
{{- end }}
{{- return $years }}
{{- return partial "search-index/functions/years" }}
68 changes: 0 additions & 68 deletions layouts/partials/search/index.json.html

This file was deleted.

0 comments on commit 5a836e5

Please sign in to comment.