Skip to content

Commit

Permalink
✨ Feat: add page layout "search"
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Nov 27, 2024
1 parent 38b681c commit 168f1ba
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
11 changes: 10 additions & 1 deletion hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
37 changes: 37 additions & 0 deletions layouts/page/search.html
Original file line number Diff line number Diff line change
@@ -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 -}}
<article class="page single special cse">
<div class="header">
{{- /* Title */ -}}
<h1 class="single-title animate__animated animate__pulse animate__faster">{{- cond (.Param "capitalizeTitles") (title .Title) .Title -}}</h1>

{{- /* Subtitle */ -}}
{{- with $params.subtitle -}}<p class="single-subtitle animate__animated animate__fadeIn">{{ . | $.RenderString }}</p>{{- end -}}
</div>

{{- /* Content */ -}}
<div class="content" id="content">
{{- dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
</div>

{{- /* Google CSE */ -}}
{{- if eq $cse.engine "google" -}}
{{- with $cse.cx -}}
<script async defer src="https://cse.google.com/cse.js?cx={{ . }}"></script>
<div class="gcse-searchbox"></div>
<div class="gcse-searchresults"></div>
{{- end -}}
{{- end -}}

{{- /* TODO Bing CSE */ -}}
</article>
{{- end -}}

0 comments on commit 168f1ba

Please sign in to comment.