Add Lunr.js for client-side search functionality and implement search results display
- Integrated Lunr.js library for indexing and searching content. - Created search.js to handle search queries and display results dynamically. - Implemented displayResults function to format and show search results. - Enhanced search functionality with boosted fields for title and content. - Added search.min.js for optimized production use.
This commit is contained in:
31
layouts/index.searchindex.json
Normal file
31
layouts/index.searchindex.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{{ $configDateFormat := .Site.Params.dateFormat | default "2 Jan 2006" }}
|
||||
[
|
||||
{{- range $index, $page := .Site.RegularPages -}}
|
||||
{{- if gt $index 0 -}}
|
||||
,
|
||||
{{- end -}}
|
||||
{{- $entry := dict "uri" $page.RelPermalink "title" $page.Title "content" ($page.Plain | htmlUnescape) -}}
|
||||
{{- if $page.Params.subtitle -}}
|
||||
{{- $subtitle := partial "utils/markdownify.html" (dict "$" $page "raw" $page.Params.subtitle "isContent" false) -}}
|
||||
{{- $entry = merge $entry (dict "subtitle" ($subtitle | plainify)) -}}
|
||||
{{- end -}}
|
||||
{{- if $page.Params.date -}}
|
||||
{{- $entry = merge $entry (dict "date" ($page.Params.date | time.Format $configDateFormat )) -}}
|
||||
{{- end -}}
|
||||
{{- if .Site.Params.displayPostDescription -}}
|
||||
{{- $description := partial "utils/markdownify.html" (dict "$" $page "raw" $page.Description "isContent" false) -}}
|
||||
{{- $entry = merge $entry (dict "description" ($description | plainify)) -}}
|
||||
{{- end -}}
|
||||
{{- if .Site.Params.displayCategory -}}
|
||||
{{- if eq .Site.Params.categoryBy "sections" -}}
|
||||
{{- $entry = merge $entry (dict "categories" (slice $page.Section)) -}}
|
||||
{{- else if eq .Site.Params.categoryBy "categories" -}}
|
||||
{{- $entry = merge $entry (dict "categories" $page.Params.categories) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if .Site.Params.enablePostTags -}}
|
||||
{{- $entry = merge $entry (dict "tags" $page.Params.tags) -}}
|
||||
{{- end -}}
|
||||
{{- $entry | jsonify -}}
|
||||
{{- end -}}
|
||||
]
|
||||
Reference in New Issue
Block a user