diff options
| author | Aditya Telange <21258296+adityatelange@users.noreply.github.com> | 2020-12-06 18:19:50 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-06 18:19:50 +0530 |
| commit | 4a4408573e0618de68f656f52e345d68234e364b (patch) | |
| tree | 1a4c456128635c633f2ee99baee34c4dd73b6828 /layouts/_default | |
| parent | c76233b350fde926c557e49b1a5f0bab8edddc55 (diff) | |
search: init Search feature (#105)
* based on https://gist.github.com/cmod/5410eae147e4318164258742dd053993
* modified working for PaperMod
* fetches current lang index.json for search
* add fuse.js v6.4.3 LICENSE: Apache License 2.0
* bundled fastsearch and fusejs as search.js
Co-authored-by: Craig Mod <stuff@craigmod.com>
Diffstat (limited to 'layouts/_default')
| -rw-r--r-- | layouts/_default/baseof.html | 2 | ||||
| -rw-r--r-- | layouts/_default/index.json | 6 | ||||
| -rw-r--r-- | layouts/_default/search.html | 38 |
3 files changed, 45 insertions, 1 deletions
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 183d1a7..0103ffe 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -6,7 +6,7 @@ </head> <body class=" -{{- if (or (ne .Kind `page` ) (eq .Layout `archives`)) -}} +{{- if (or (ne .Kind `page` ) (eq .Layout `archives`) (eq .Layout `search`)) -}} {{- print "list" -}} {{- end -}} {{- if eq $.Site.Params.defaultTheme `dark` -}} diff --git a/layouts/_default/index.json b/layouts/_default/index.json new file mode 100644 index 0000000..deef3c9 --- /dev/null +++ b/layouts/_default/index.json @@ -0,0 +1,6 @@ +{{- $.Scratch.Add "index" slice -}} +{{- range .Site.RegularPages -}} + {{- $.Scratch.Add "index" (dict "title" .Title "content" .Plain "permalink" .Permalink "summary" .Summary) -}} +{{- end -}} +{{- $.Scratch.Get "index" | jsonify -}} + diff --git a/layouts/_default/search.html b/layouts/_default/search.html new file mode 100644 index 0000000..44b72c5 --- /dev/null +++ b/layouts/_default/search.html @@ -0,0 +1,38 @@ +{{- define "main" }} + +<header class="page-header"> + <h1>{{ .Title }} + <svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24" fill="none" + stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> + <circle cx="11" cy="11" r="8"></circle> + <line x1="21" y1="21" x2="16.65" y2="16.65"></line> + </svg> + </h1> + {{- if .Params.hideMeta }}{{ else }} + <div class="post-meta"> + {{- if .IsTranslated -}} + <ul class="i18n_list"> + {{- i18n "translations" | default "Translations"}}: + {{- range .Translations }} + <li> + <a href="{{ .Permalink }}"> + {{- if (and $.Site.Params.displayFullLangName (.Language.LanguageName)) }} + {{- .Language.LanguageName | emojify | humanize -}} + {{- else }} + {{- .Lang | humanize -}} + {{- end -}} + </a> + </li> + {{- end }} + </ul> + {{- end }} + </div> + {{- end}} +</header> + +<div class="searchbox"> + <input id="searchInput" autofocus placeholder="{{.Title}} ↵" aria-label="search"> + <ul id="searchResults" aria-label="search results"></ul> +</div> + +{{- end }}{{/* end main */}} |
