add search by title
This commit is contained in:
parent
10ae1fcf36
commit
67f79b8474
8
assets/css/search.css
Normal file
8
assets/css/search.css
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#search {
|
||||||
|
height: 50px;
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
border: 2px solid;
|
||||||
|
line-height: 1.6;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
}
|
21
assets/js/search.js
Normal file
21
assets/js/search.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
(function () {
|
||||||
|
function onEvent() {
|
||||||
|
var filter = search.value.toUpperCase();
|
||||||
|
var list = document.getElementById("list");
|
||||||
|
var listItems = list.getElementsByTagName("li");
|
||||||
|
for (i = 0; i < listItems.length; i++) {
|
||||||
|
var item = listItems[i];
|
||||||
|
var text = item.innerText.toUpperCase();
|
||||||
|
if (text.indexOf(filter) > -1) {
|
||||||
|
item.style.display = "";
|
||||||
|
} else {
|
||||||
|
item.style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var search = document.getElementById("search");
|
||||||
|
if (search) {
|
||||||
|
search.addEventListener("keyup", onEvent);
|
||||||
|
}
|
||||||
|
})();
|
|
@ -26,6 +26,7 @@ params:
|
||||||
katex: true
|
katex: true
|
||||||
darkThemeAsDefault: false
|
darkThemeAsDefault: false
|
||||||
hideHeaderLinks: false
|
hideHeaderLinks: false
|
||||||
|
search: true
|
||||||
# A list of custom css files can be provided, which must be placed inside
|
# A list of custom css files can be provided, which must be placed inside
|
||||||
# 'static/'.
|
# 'static/'.
|
||||||
# This is useful to override just specific css classes, instead of copying
|
# This is useful to override just specific css classes, instead of copying
|
||||||
|
|
|
@ -1,12 +1,25 @@
|
||||||
{{ define "main" }}
|
{{ define "main" }}
|
||||||
<main id="main">
|
<main id="main">
|
||||||
<h1>{{ .Title }}</h1>
|
<h1>{{ .Title }}</h1>
|
||||||
<ul class="patterns-list">
|
{{ if site.Params.search }}
|
||||||
|
<input
|
||||||
|
id="search"
|
||||||
|
type="text"
|
||||||
|
placeholder="Search by title..."
|
||||||
|
aria-label="Search by title"
|
||||||
|
/>
|
||||||
|
{{ end }}
|
||||||
|
<ul class="patterns-list" id="list">
|
||||||
{{ range .Pages.ByPublishDate.Reverse }}
|
{{ range .Pages.ByPublishDate.Reverse }}
|
||||||
<li>
|
<li>
|
||||||
<h2>
|
<h2>
|
||||||
<a href="{{ .Permalink }}">
|
<a href="{{ .Permalink }}">
|
||||||
<svg class="bookmark" aria-hidden="true" viewBox="0 0 40 50" focusable="false">
|
<svg
|
||||||
|
class="bookmark"
|
||||||
|
aria-hidden="true"
|
||||||
|
viewBox="0 0 40 50"
|
||||||
|
focusable="false"
|
||||||
|
>
|
||||||
<use xlink:href="#bookmark"></use>
|
<use xlink:href="#bookmark"></use>
|
||||||
</svg>
|
</svg>
|
||||||
{{ .Title }}
|
{{ .Title }}
|
||||||
|
|
|
@ -3,3 +3,10 @@
|
||||||
{{ $templateDomScripts := resources.Get "js/template-dom-scripts.js" }}
|
{{ $templateDomScripts := resources.Get "js/template-dom-scripts.js" }}
|
||||||
{{ $domScripts := $templateDomScripts | resources.ExecuteAsTemplate "js/dom-scripts.js" . }}
|
{{ $domScripts := $templateDomScripts | resources.ExecuteAsTemplate "js/dom-scripts.js" . }}
|
||||||
<script src="{{ $domScripts.Permalink }}"></script>
|
<script src="{{ $domScripts.Permalink }}"></script>
|
||||||
|
|
||||||
|
{{ if site.Params.search }}
|
||||||
|
{{ $searchJs := resources.Get "js/search.js" | fingerprint }}
|
||||||
|
<script src="{{ $searchJs.RelPermalink }}"></script>
|
||||||
|
{{ $searchCss := resources.Get "css/search.css" | fingerprint }}
|
||||||
|
<link rel="stylesheet" href="{{ $searchCss.RelPermalink }}"></link>
|
||||||
|
{{ end }}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user