generated from hugomods/template-mod
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
js-resource.html
106 lines (106 loc) · 4.26 KB
/
js-resource.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{{- $defaultLang := .Sites.First.Language.Lang }}
{{- $multihost := partialCached "search/functions/is-multihost" . }}
{{- $langs := newScratch }}
{{- range .Site.Languages }}
{{- $langs.Set .Lang (dict "lang" .Lang "name" .LanguageName) }}
{{- end }}
{{/* years. */}}
{{- $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 }}
{{/* taxonomies. */}}
{{- $taxonomies := newScratch }}
{{- if default true site.Params.search.filter_taxonomies }}
{{- $allTaxonomies := newScratch }}
{{- range .Site.Sites }}
{{- range $name, $taxonomy := .Taxonomies }}
{{- range $taxonomy }}
{{- $allTaxonomies.Add $name (slice .Page.Title) }}
{{- end }}
{{- end }}
{{- end }}
{{/* remove duplicate taxonomies. */}}
{{- range $name, $v := $allTaxonomies.Values }}
{{- $taxonomies.Set $name ($v | uniq) }}
{{- end }}
{{- end }}
{{- $taxonomyKeys := slice }}
{{- range $name, $v := .Site.Taxonomies }}
{{- $taxonomyKeys = $taxonomyKeys | append $name }}
{{- end }}
{{/* i18n messages. */}}
{{- $i18n := newScratch }}
{{- range $lang, $messages := .Site.Data.search.i18n }}
{{/* Exclude the unused messages. */}}
{{- if isset $langs.Values $lang }}
{{- $i18n.Set $lang $messages }}
{{- end }}
{{- end }}
{{- $js := resources.Get "search/js/index.ts" }}
{{/* The SVG icons. */}}
{{- $icons := dict
"page" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "file-earmark-richtext" "size" "2em"))
"heading" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "hash" "size" "2em"))
"history" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "clock" "size" "2em"))
"meta" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "info-circle" "size" "2em"))
"search" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "search" "size" "1.25em"))
"spinner" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "arrow-clockwise" "size" "1.35em"))
"lang" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "translate" "size" "1em"))
"sort" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "sort-down" "size" "1em"))
"expand" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "chevron-expand" "size" "1em"))
"year" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "calendar-check" "size" "1em"))
"taxonomies" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "tags" "size" "1em"))
}}
{{/* Include the following icons when necessary. */}}
{{- if default true .Site.Params.search.index_all_pages }}
{{- $icons = merge $icons (dict
"home" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "house" "size" "2em"))
"section" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "list" "size" "2em"))
"term" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "tag" "size" "2em"))
"taxonomy" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "tags" "size" "2em")))
}}
{{- end }}
{{/* Index files URL. */}}
{{- $indices := slice }}
{{- range .Sites }}
{{- $site := . }}
{{- with .Home.OutputFormats.Get "SearchIndex" }}
{{- $hash := partialCached "search/functions/search-index-hash" $site $site }}
{{- $indexURL := printf "%s?v=%s" (cond $multihost .Permalink .RelPermalink) $hash }}
{{- $indices = $indices | append $indexURL }}
{{- end }}
{{- end }}
{{- $defaultParams := partialCached "search/functions/params" . }}
{{- $params := merge $defaultParams (dict
"icons" $icons
"indices" $indices
"i18n" $i18n.Values
"historiesCount" (default 5 site.Params.search.histories_count)
"defaultLang" $defaultLang
"langs" $langs.Values
"years" $years
"taxonomies" $taxonomies.Values
"taxonomyKeys" $taxonomyKeys)
}}
{{- $options := dict
"targetPath" "js/search.js"
"minify" hugo.IsProduction
"params" $params
}}
{{- $js = $js | js.Build $options }}
{{- return $js -}}