refined searchbar; added options to use a global searchbar or a search link in the menu

This commit is contained in:
Gabriele Musco 2021-04-13 16:04:16 +02:00
parent f51db60b35
commit 746a750cf1
No known key found for this signature in database
GPG Key ID: 8539FD3454380B83
5 changed files with 55 additions and 29 deletions

View File

@ -45,6 +45,8 @@ summaryLength = 70 # number of words for article summaries
highlightBgColor = "#34363b"; # card and circle navigation background color for discrete card mode
enableSearch = true # enable search page
searchbarEverywhere = true # if the searchbar should be shown in every page; requires enableSearch
searchMenuLink = false # add a search link to the navigation menu; requires enableSearch
# enable comments support with commento using the script from your server
commento = "https://example.com/js/commento.js"

View File

@ -341,6 +341,7 @@ ul.list {
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
margin: 12px 0;
.nerdlink {
display: inline-block;
cursor: pointer;
@ -359,3 +360,13 @@ ul.list {
outline: none;
}
}
.titleAndSearchContainer {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
.search {
&, #searchbar {font-size: 1em;}
}
}

View File

@ -2,10 +2,7 @@
<noscript>
You need to enable JavaScript to be able to search.
</noscript>
<div class="search">
<input id="searchbar" type="text" placeholder="{{ .Title }}" />
<a class="nerdlink" onclick="newSearch();">&#xf002;</a>
</div>
{{- partial "searchbar.html" . -}}
<div class="postlist {{ if .Site.Params.gridView }}gridView{{ end }}" id="postlist">
</div>
{{- partial "js_paginator.html" . -}}
@ -43,9 +40,5 @@
performSearch(searchTerm);
}
}
function newSearch() {
location.href = baseUrl+`?q=${searchbar.value}`;
}
searchbar.onkeyup = (ev) => {if (ev.keyCode == 13) newSearch()};
</script>
{{ end }}

View File

@ -1,27 +1,35 @@
<header>
{{- partial "inject/header-before.html" . -}}
<div id="titleContainer">
<img src='{{ .Site.Params.Logo | default "/img/icon.svg" }}' />
<div>
<h1>{{ .Site.Title | default "Ficurinia" }}</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/posts">Posts</a></li>
{{ $pagesDir := .Site.Params.Pages | default (slice "pages") }}
{{ $pagesList := where .Site.RegularPages "Section" "in" $pagesDir }}
{{ range $pagesList }}
<li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
{{ end }}
{{ if (.Site.Params.showTags | default true) }}
<li><a href="/tags">Tags</a></li>
{{ end }}
{{ if (.Site.Params.enableSearch | default true) }}
<li><a href="/search">Search</a></li>
{{ end }}
</ul>
</nav>
<div class="titleAndSearchContainer">
<div id="titleContainer">
<img src='{{ .Site.Params.Logo | default "/img/icon.svg" }}' />
<div>
<h1>{{ .Site.Title | default "Ficurinia" }}</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/posts">Posts</a></li>
{{ $pagesDir := .Site.Params.Pages | default (slice "pages") }}
{{ $pagesList := where .Site.RegularPages "Section" "in" $pagesDir }}
{{ range $pagesList }}
<li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
{{ end }}
{{ if (.Site.Params.showTags | default true) }}
<li><a href="/tags">Tags</a></li>
{{ end }}
{{ if and (.Site.Params.searchMenuLink | default false) (.Site.Params.enableSearch | default true) }}
<li><a href="/search">Search</a></li>
{{ end }}
</ul>
</nav>
</div>
</div>
{{ if and (.Site.Params.searchbarEverywhere | default true) (and (.Site.Params.enableSearch | default true) (not (eq .Title "Search"))) }}
{{- partial "searchbar.html" . -}}
<script>
document.getElementById('searchbar').
</script>
{{ end }}
</div>
<div id="links">
{{ if .Site.Params.showRss | default true }}

View File

@ -0,0 +1,12 @@
<div class="search">
<input id="searchbar" type="text" placeholder="Search" />
<a class="nerdlink" onclick="newSearch();">&#xf002;</a>
</div>
<script>
function newSearch() {
let term = searchbar.value.trim();
if (!term) return;
location.href = `/search?q=${term}`;
}
searchbar.onkeyup = (ev) => {if (ev.keyCode == 13) newSearch()};
</script>