Start work on search feature with lunr
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
{{- partial "docs/shared" -}}
|
||||
<html lang="{{ .Site.Language.Lang }}">
|
||||
|
||||
<head>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
{{- partial "docs/shared" -}}
|
||||
<html lang="{{ .Site.Language.Lang }}">
|
||||
|
||||
<head>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
{{- partial "docs/shared" -}}
|
||||
<html lang="{{ .Site.Language.Lang }}">
|
||||
|
||||
<head>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
window.lunrData = [
|
||||
{{ range $index, $page := .Site.Pages }}
|
||||
{{- if and $index (gt $index 0) -}},{{- end }}
|
||||
{
|
||||
"href": "{{ $page.RelPermalink }}",
|
||||
"title": "{{ htmlEscape $page.Title }}",
|
||||
"content": {{ $page.Plain | jsonify }}
|
||||
}
|
||||
{{- end -}}
|
||||
]
|
||||
@@ -1,3 +1,3 @@
|
||||
<h2 class="book-brand">
|
||||
<a href="{{ .Site.BaseURL }}">{{ .Site.Title }}</a>
|
||||
</h2>
|
||||
</h2>
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{- template "title" . }} | {{ .Site.Title -}}</title>
|
||||
<title>{{ partial "docs/title" . }} | {{ .Site.Title -}}</title>
|
||||
|
||||
<!-- Theme stylesheet, you can customize scss by creatig `assets/custom.scss` in your website -->
|
||||
{{ $styles := resources.Get "book.scss" | resources.ToCSS | resources.Minify | resources.Fingerprint }}
|
||||
<!-- Theme stylesheet, you can customize scss by creating `assets/custom.scss` in your website -->
|
||||
{{- $styles := resources.Get "book.scss" | resources.ToCSS | resources.Minify | resources.Fingerprint }}
|
||||
<link rel="stylesheet" href="{{ $styles.RelPermalink }}">
|
||||
|
||||
{{- $search := resources.Get "search.js" | resources.ExecuteAsTemplate "search.js" . | resources.Minify | resources.Fingerprint }}
|
||||
<script src="{{ $search.RelPermalink }}"></script>
|
||||
|
||||
<!-- Favicon -->
|
||||
<link rel="icon" href="{{ "favicon.png" | relURL }}" type="image/x-icon">
|
||||
|
||||
|
||||
@@ -2,3 +2,18 @@
|
||||
{{ with .Site.GetPage .Site.Params.BookMenuBundle }}
|
||||
{{- .Content -}}
|
||||
{{ end }}
|
||||
|
||||
{{ define "hrefhack" }}
|
||||
{{ $attrEq := "$=" }}
|
||||
{{ $attrVal := .RelPermalink }}
|
||||
{{ if eq .RelPermalink "/" }}
|
||||
{{ $attrEq = "=" }}
|
||||
{{ $attrVal = .Permalink }}
|
||||
{{ end }}
|
||||
|
||||
<style>
|
||||
nav ul a[href{{ $attrEq }}"{{ $attrVal }}"] {
|
||||
color: {{ default "#004ed0" .Site.Params.BookMenuBundleActiveLinkColor }};
|
||||
}
|
||||
</style>
|
||||
{{ end }}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
{{ if .Content }}
|
||||
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
|
||||
{{ else }}
|
||||
<span>{{ template "title" . }}</span>
|
||||
<span>{{ partial "docs/title" . }}</span>
|
||||
{{ end }}
|
||||
|
||||
{{ template "book-section-children" (dict "Section" . "CurrentPage" $.CurrentPage) }}
|
||||
@@ -53,7 +53,7 @@
|
||||
{{ define "book-page-link" }}
|
||||
{{ with .Page }}
|
||||
<a href="{{ .RelPermalink }}" {{ if eq $.CurrentPage .Permalink }} class="active"{{ end }}>
|
||||
{{ template "title" . }}
|
||||
{{ partial "docs/title" . }}
|
||||
</a>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<nav>
|
||||
{{ partial "docs/brand" . }}
|
||||
{{ partial "docs/search" . }}
|
||||
{{ partial "docs/inject/menu-before" . }}
|
||||
|
||||
{{ if .Site.Params.BookMenuBundle }}
|
||||
@@ -11,6 +12,13 @@
|
||||
{{ partial "docs/inject/menu-after" . }}
|
||||
</nav>
|
||||
|
||||
{{ if .Site.Params.BookEnableJS }}
|
||||
{{ template "jsmenu" . }}
|
||||
{{ end }}
|
||||
<!-- Restore menu position as soon as possible to avoid flickering -->
|
||||
<script>
|
||||
(function() {
|
||||
var menu = document.querySelector("aside.book-menu nav");
|
||||
addEventListener("beforeunload", function(event) {
|
||||
localStorage.setItem("menu.scrollTop", menu.scrollTop);
|
||||
});
|
||||
menu.scrollTop = localStorage.getItem("menu.scrollTop");
|
||||
})();
|
||||
</script>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<header class="align-center justify-between book-header">
|
||||
<header class="flex align-center justify-between book-header">
|
||||
<label for="menu-control">
|
||||
<img src="{{ "svg/menu.svg" | relURL }}" alt="Menu" />
|
||||
</label>
|
||||
<strong>{{- template "title" . }}</strong>
|
||||
<strong>{{ partial "docs/title" . }}</strong>
|
||||
</header>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
<input type="text" placeholder="Search" class="book-search" id="book-search" />
|
||||
<ul id="book-search-results"></ul>
|
||||
@@ -1,40 +0,0 @@
|
||||
{{/*These templates contains some more complex logic and shared between partials*/}}
|
||||
{{ define "title" }}
|
||||
{{ if and .IsSection .File }}
|
||||
{{ $sections := split (trim .File.Dir "/") "/" }}
|
||||
{{ $title := index ($sections | last 1) 0 | humanize | title }}
|
||||
{{ default $title .Title }}
|
||||
{{ else if and .IsPage .File }}
|
||||
{{ $title := .File.BaseFileName | humanize | title }}
|
||||
{{ default $title .Title }}
|
||||
{{ else }}
|
||||
{{ .Title }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ define "hrefhack" }}
|
||||
{{ $attrEq := "$=" }}
|
||||
{{ $attrVal := .RelPermalink }}
|
||||
{{ if eq .RelPermalink "/" }}
|
||||
{{ $attrEq = "=" }}
|
||||
{{ $attrVal = .Permalink }}
|
||||
{{ end }}
|
||||
|
||||
<style>
|
||||
nav ul a[href{{ $attrEq }}"{{ $attrVal }}"] {
|
||||
color: {{ default "#004ed0" .Site.Params.BookMenuBundleActiveLinkColor }};
|
||||
}
|
||||
</style>
|
||||
{{ end }}
|
||||
|
||||
{{ define "jsmenu" }}
|
||||
<script>
|
||||
(function() {
|
||||
var menu = document.querySelector('aside.book-menu nav')
|
||||
addEventListener('beforeunload', function(event) {
|
||||
localStorage.setItem('menu.scrollTop', menu.scrollTop)
|
||||
});
|
||||
menu.scrollTop = localStorage.getItem('menu.scrollTop')
|
||||
})()
|
||||
</script>
|
||||
{{ end }}
|
||||
@@ -0,0 +1,9 @@
|
||||
{{ $title := .Title }}
|
||||
{{ if and .IsSection .File }}
|
||||
{{ $sections := split (trim .File.Dir "/") "/" }}
|
||||
{{ $title = index ($sections | last 1) 0 | humanize | title }}
|
||||
{{ else if and .IsPage .File }}
|
||||
{{ $title = .File.BaseFileName | humanize | title }}
|
||||
{{ end }}
|
||||
|
||||
{{ return $title }}
|
||||
@@ -1,5 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
{{- partial "docs/shared" -}}
|
||||
<html lang="{{ .Site.Language.Lang }}">
|
||||
|
||||
<head>
|
||||
|
||||
Reference in New Issue
Block a user