From 168f1babc3e74c7501730fa61e970f55f96813d1 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Wed, 27 Nov 2024 16:20:21 +0800 Subject: [PATCH] :sparkles: Feat: add page layout "search" --- hugo.toml | 11 ++++++++++- layouts/page/search.html | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 layouts/page/search.html diff --git a/hugo.toml b/hugo.toml index 2268c36a0..04554ccfe 100644 --- a/hugo.toml +++ b/hugo.toml @@ -389,7 +389,7 @@ enableEmoji = true # Search config [params.search] enable = false - # type of search engine ["algolia", "fuse"] + # type of search engine ["algolia", "fuse", "cse"] type = "fuse" # max index length of the chunked content contentLength = 4000 @@ -418,6 +418,15 @@ enableEmoji = true ignoreLocation = false useExtendedSearch = false ignoreFieldNorm = false + # FixIt 0.3.16 | NEW Custom Search Engine (CSE) + [params.search.cse] + # support cse engine: ["google", "bing"] + engine = "google" + # Google: https://programmablesearchengine.google.com/ + # Google Custom Search Engine Context + cx = "" + # Bing: https://www.customsearch.ai/ + # TODO # Header config [params.header] diff --git a/layouts/page/search.html b/layouts/page/search.html new file mode 100644 index 000000000..04b974849 --- /dev/null +++ b/layouts/page/search.html @@ -0,0 +1,37 @@ +{{- /* + TODO Adapting to dark mode, maybe use css variables +*/ -}} +{{- define "title" -}} + {{- cond (.Param "capitalizeTitles") (title .Title) .Title -}} + {{- if .Site.Params.withSiteTitle }} {{ .Site.Params.titleDelimiter }} {{ .Site.Title }}{{- end -}} +{{- end -}} + +{{- define "content" -}} + {{- $params := partial "function/params.html" -}} + {{- $cse := .Site.Params.search.cse -}} +
+
+ {{- /* Title */ -}} +

{{- cond (.Param "capitalizeTitles") (title .Title) .Title -}}

+ + {{- /* Subtitle */ -}} + {{- with $params.subtitle -}}

{{ . | $.RenderString }}

{{- end -}} +
+ + {{- /* Content */ -}} +
+ {{- dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}} +
+ + {{- /* Google CSE */ -}} + {{- if eq $cse.engine "google" -}} + {{- with $cse.cx -}} + + +
+ {{- end -}} + {{- end -}} + + {{- /* TODO Bing CSE */ -}} +
+{{- end -}}