mirror of
https://github.com/hyzendust/hyzendust.github.io.git
synced 2026-09-19 02:23:17 +02:00
Add: Search bar
This commit is contained in:
@@ -1,5 +1,34 @@
|
||||
<nav class="menu language">
|
||||
<ul class="menu__list language__list">
|
||||
<li class="menu__item menu__item--search">
|
||||
<form class="site-search" action="/search-results/" method="get" role="search">
|
||||
<input
|
||||
type="search"
|
||||
name="q"
|
||||
class="site-search__input"
|
||||
placeholder="Search"
|
||||
aria-label="Search blog posts and services"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<button class="site-search__btn" type="submit" aria-label="Search">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
width="14"
|
||||
height="14"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<circle cx="11" cy="11" r="7"></circle>
|
||||
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
|
||||
</svg>
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
{{- partial "header/menu.html" (dict "menuID" "main" "page" .) -}} {{- partial
|
||||
"header/language_selector.html" . -}}
|
||||
</ul>
|
||||
|
||||
44
layouts/home.json
Normal file
44
layouts/home.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{{- /*
|
||||
Search index for the navbar search bar. Includes every page on the site
|
||||
(home, blog, services, terms, privacy, changelog, contact, future pages,
|
||||
etc.) EXCEPT the sections below, which are excluded on purpose:
|
||||
- /uninotes/ private/course notes
|
||||
- /admin/ admin panel
|
||||
- /login/ login page
|
||||
- /signup/ signup page
|
||||
- /search-results/ the search page itself
|
||||
Consumed client-side by /js/search.js.
|
||||
*/ -}}
|
||||
{{- $excludePrefixes := slice "/uninotes/" "/admin/" "/login/" "/signup/" "/search-results/" -}}
|
||||
{{- $candidates := where site.Pages "Kind" "in" (slice "home" "page" "section") -}}
|
||||
{{- $candidates = where $candidates "Draft" "ne" true -}}
|
||||
{{- $pages := slice -}}
|
||||
{{- range $candidates -}}
|
||||
{{- $permalink := .RelPermalink -}}
|
||||
{{- $excluded := false -}}
|
||||
{{- range $excludePrefixes -}}
|
||||
{{- if strings.HasPrefix $permalink . -}}
|
||||
{{- $excluded = true -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if not $excluded -}}
|
||||
{{- $pages = $pages | append . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
[
|
||||
{{- range $i, $p := $pages -}}
|
||||
{{- if $i }},{{ end -}}
|
||||
{{- $clean := $p.Content -}}
|
||||
{{- $clean = replaceRE `(?is)<script[^>]*>.*?</script>` " " $clean -}}
|
||||
{{- $clean = replaceRE `(?is)<style[^>]*>.*?</style>` " " $clean -}}
|
||||
{{- $text := $clean | plainify | htmlUnescape -}}
|
||||
{{- $text = replaceRE `\s+` " " $text -}}
|
||||
{{- $text = strings.TrimSpace $text -}}
|
||||
{
|
||||
"title": {{ $p.Title | jsonify }},
|
||||
"url": {{ $p.RelPermalink | jsonify }},
|
||||
"section": {{ (cond (eq $p.Section "") "home" $p.Section) | jsonify }},
|
||||
"content": {{ $text | jsonify }}
|
||||
}
|
||||
{{- end -}}
|
||||
]
|
||||
15
layouts/search-results/section.html
Normal file
15
layouts/search-results/section.html
Normal file
@@ -0,0 +1,15 @@
|
||||
{{ define "main" }}
|
||||
|
||||
<nav class="uninotes-breadcrumbs breadcrumbs">
|
||||
<a href="/">Home</a>
|
||||
</nav>
|
||||
|
||||
<h1>Search results <span class="search-results__query" data-search-query></span></h1>
|
||||
|
||||
<p class="search-results__status" data-search-status>Enter a search term above.</p>
|
||||
|
||||
<ul class="search-results__list" data-search-list></ul>
|
||||
|
||||
<script src="{{ "js/search.js" | relURL }}" defer></script>
|
||||
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user