mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
feat(search): add pagefind search engine support (#738)
* feat(search): add native pagefind support * chore: code review and change --------- Co-authored-by: Cell <1024@lruihao.cn>
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
{{- if and (eq .Site hugo.Sites.Default) .Site.Params.search.enable (eq .Site.Params.search.type "pagefind") -}}
|
||||
{{- warnf "FixIt Pagefind search enabled\nRun `npx pagefind --site <publicDir>` after site build to create the search index.\n\n" -}}
|
||||
{{- end -}}
|
||||
@@ -4,6 +4,7 @@
|
||||
{{- partial "init/detection-env.html" . -}}
|
||||
{{- partial "init/detection-version.html" . -}}
|
||||
{{- partial "init/detection-deprecated.html" . -}}
|
||||
{{- partial "init/detection-pagefind.html" . -}}
|
||||
{{- partial "init/global.html" . -}}
|
||||
{{- partial "init/patch.html" . -}}
|
||||
{{- partial "init/compatibility.html" . -}}
|
||||
|
||||
@@ -44,6 +44,19 @@ FixIt theme assets partial
|
||||
{{- $source := $cdn.fuseJS | default "lib/fuse/fuse.min.js" -}}
|
||||
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}}
|
||||
{{- $config = dict "isCaseSensitive" $search.fuse.isCaseSensitive "minMatchCharLength" $search.fuse.minMatchCharLength "findAllMatches" $search.fuse.findAllMatches "location" $search.fuse.location "threshold" $search.fuse.threshold "distance" $search.fuse.distance "ignoreLocation" $search.fuse.ignoreLocation "useExtendedSearch" $search.fuse.useExtendedSearch "ignoreFieldNorm" $search.fuse.ignoreFieldNorm | dict "search" | merge $config -}}
|
||||
{{- else if eq $search.type "pagefind" -}}
|
||||
{{- $pagefind := $search.pagefind | default dict -}}
|
||||
{{- $config = dict
|
||||
"type" "pagefind"
|
||||
"pagefind" (dict
|
||||
"bundlePath" ($pagefind.bundlePath | default "pagefind/")
|
||||
"baseURL" .Site.BaseURL
|
||||
"debounceTimeoutMs" ($pagefind.debounceTimeoutMs | default 300)
|
||||
"useBuiltInFilters" ($pagefind.useBuiltInFilters | default true)
|
||||
"sortBy" ($pagefind.sortBy | default "")
|
||||
"sortOrder" ($pagefind.sortOrder | default "desc")
|
||||
)
|
||||
| dict "search" | merge $config -}}
|
||||
{{- else if eq $search.type "cse" -}}
|
||||
{{- $config = dict "type" "cse" | dict "search" | merge $config -}}
|
||||
{{- $cse := .Site.Params.cse -}}
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
{{- template "_internal/opengraph.html" . -}}
|
||||
{{- partial "layouts/head/twitter-cards.html" . -}}
|
||||
|
||||
{{- partial "plugin/pagefind-metadata.html" . -}}
|
||||
|
||||
<meta name="application-name" content="{{ .Site.Params.app.title | default .Site.Title }}">
|
||||
<meta name="apple-mobile-web-app-title" content="{{ .Site.Params.app.title | default .Site.Title }}">
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{{- if and .Site.Params.search.enable (eq .Site.Params.search.type "pagefind") .IsPage -}}
|
||||
{{- $params := partial "function/params.html" -}}
|
||||
{{- $hidden := cond (eq $params.hiddenFromSearch true) "true" "false" -}}
|
||||
{{- $encrypted := cond (and (isset $params "password") (ne (printf "%v" $params.password) "")) "true" "false" -}}
|
||||
{{- $pageDate := (.PublishDate | default .Date) -}}
|
||||
{{- $dateLabel := $pageDate | dateFormat (.Site.Params.dateFormat | default "2006-01-02") -}}
|
||||
<meta data-pagefind-filter="hidden:{{ $hidden }}">
|
||||
<meta data-pagefind-filter="encrypted:{{ $encrypted }}">
|
||||
<meta data-pagefind-meta="date:{{ $dateLabel }}">
|
||||
<meta data-pagefind-sort="date:{{ $pageDate.Unix }}">
|
||||
{{- end -}}
|
||||
+3
-2
@@ -5,10 +5,11 @@
|
||||
|
||||
{{- define "content" -}}
|
||||
{{- $params := partial "function/params.html" -}}
|
||||
{{- $pagefindEnabled := and .Site.Params.search.enable (eq .Site.Params.search.type "pagefind") -}}
|
||||
<article class="page single special">
|
||||
<div class="header">
|
||||
{{- /* Title */ -}}
|
||||
<h1 class="single-title animate__animated animate__pulse animate__faster">{{- cond (.Param "capitalizeTitles") (title .Title) .Title -}}</h1>
|
||||
<h1 class="single-title animate__animated animate__pulse animate__faster"{{ if $pagefindEnabled }} data-pagefind-body{{ end }}>{{- cond (.Param "capitalizeTitles") (title .Title) .Title -}}</h1>
|
||||
|
||||
{{- /* Subtitle */ -}}
|
||||
{{- with $params.subtitle -}}<p class="single-subtitle animate__animated animate__fadeIn">{{ . | $.RenderString }}</p>{{- end -}}
|
||||
@@ -16,7 +17,7 @@
|
||||
|
||||
{{- /* Content */ -}}
|
||||
{{- $content := dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
|
||||
<div class="content" id="content">
|
||||
<div class="content" id="content"{{ if $pagefindEnabled }} data-pagefind-body{{ end }}>
|
||||
{{- if not $params.password -}}
|
||||
{{- $content -}}
|
||||
{{- end -}}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
{{- $showToc := $toc.enable | and (ne $tableOfContents `<nav id="TableOfContents"></nav>`) -}}
|
||||
{{- .Store.Set "showToc" $showToc -}}
|
||||
{{- $tableOfContents = dict "Content" $tableOfContents "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
|
||||
{{- $pagefindEnabled := and .Site.Params.search.enable (eq .Site.Params.search.type "pagefind") -}}
|
||||
|
||||
<aside class="aside-collection animate__animated animate__fadeIn animate__faster" aria-label="{{ T "collections" }}">
|
||||
{{- /* Collection List */ -}}
|
||||
@@ -26,7 +27,7 @@
|
||||
<article class="page single"{{ with .Params.fromAdapters }} data-adapters="{{ . }}"{{ end }}>
|
||||
<div class="header">
|
||||
{{- /* Title */ -}}
|
||||
<h1 class="single-title animate__animated animate__flipInX">
|
||||
<h1 class="single-title animate__animated animate__flipInX"{{ if $pagefindEnabled }} data-pagefind-body{{ end }}>
|
||||
{{- $repost := $params.repost | default dict -}}
|
||||
{{- with $repost -}}
|
||||
{{- if eq .Enable true -}}
|
||||
@@ -181,7 +182,7 @@
|
||||
|
||||
{{- /* Content */ -}}
|
||||
{{- $content := dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
|
||||
<div class="content" id="content"{{ with $params.endFlag }} data-end-flag="{{ . }}"{{ end }}>
|
||||
<div class="content" id="content"{{ if $pagefindEnabled }} data-pagefind-body{{ end }}{{ with $params.endFlag }} data-end-flag="{{ . }}"{{ end }}>
|
||||
{{- if not $params.password -}}
|
||||
{{- $content -}}
|
||||
{{- end -}}
|
||||
|
||||
Reference in New Issue
Block a user