aboutsummaryrefslogtreecommitdiff
path: root/layouts
diff options
context:
space:
mode:
authorAlex Shpak <alex-shpak@users.noreply.github.com>2019-07-15 18:25:21 +0200
committerAlex Shpak <alex-shpak@users.noreply.github.com>2019-08-06 11:33:42 +0200
commitdda0a0eab19457598b71f2b2b2f978b09d3f95c7 (patch)
tree035ca254fe7a8c7c7df316bce0b777f9a9dd06fe /layouts
parentb199d72e5fd7ec76b3c17fc9a6368868978d6328 (diff)
Start work on search feature with lunr
Diffstat (limited to 'layouts')
-rw-r--r--layouts/404.html1
-rw-r--r--layouts/docs/baseof.html1
-rw-r--r--layouts/home.html1
-rw-r--r--layouts/home.json10
-rw-r--r--layouts/partials/docs/brand.html2
-rw-r--r--layouts/partials/docs/html-head.html9
-rw-r--r--layouts/partials/docs/menu-bundle.html15
-rw-r--r--layouts/partials/docs/menu-filetree.html4
-rw-r--r--layouts/partials/docs/menu.html14
-rw-r--r--layouts/partials/docs/mobile-header.html4
-rw-r--r--layouts/partials/docs/search.html2
-rw-r--r--layouts/partials/docs/shared.html40
-rw-r--r--layouts/partials/docs/title.html9
-rw-r--r--layouts/posts/baseof.html1
14 files changed, 58 insertions, 55 deletions
diff --git a/layouts/404.html b/layouts/404.html
index b6b1d0e..cd7bf3a 100644
--- a/layouts/404.html
+++ b/layouts/404.html
@@ -1,5 +1,4 @@
<!DOCTYPE html>
-{{- partial "docs/shared" -}}
<html lang="{{ .Site.Language.Lang }}">
<head>
diff --git a/layouts/docs/baseof.html b/layouts/docs/baseof.html
index 29b067f..1592860 100644
--- a/layouts/docs/baseof.html
+++ b/layouts/docs/baseof.html
@@ -1,5 +1,4 @@
<!DOCTYPE html>
-{{- partial "docs/shared" -}}
<html lang="{{ .Site.Language.Lang }}">
<head>
diff --git a/layouts/home.html b/layouts/home.html
index 69054ca..37f9eeb 100644
--- a/layouts/home.html
+++ b/layouts/home.html
@@ -1,5 +1,4 @@
<!DOCTYPE html>
-{{- partial "docs/shared" -}}
<html lang="{{ .Site.Language.Lang }}">
<head>
diff --git a/layouts/home.json b/layouts/home.json
new file mode 100644
index 0000000..f090548
--- /dev/null
+++ b/layouts/home.json
@@ -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 -}}
+]
diff --git a/layouts/partials/docs/brand.html b/layouts/partials/docs/brand.html
index 5a2c9cb..7d7b721 100644
--- a/layouts/partials/docs/brand.html
+++ b/layouts/partials/docs/brand.html
@@ -1,3 +1,3 @@
<h2 class="book-brand">
<a href="{{ .Site.BaseURL }}">{{ .Site.Title }}</a>
-</h2> \ No newline at end of file
+</h2>
diff --git a/layouts/partials/docs/html-head.html b/layouts/partials/docs/html-head.html
index 5fbc549..805c2b5 100644
--- a/layouts/partials/docs/html-head.html
+++ b/layouts/partials/docs/html-head.html
@@ -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">
diff --git a/layouts/partials/docs/menu-bundle.html b/layouts/partials/docs/menu-bundle.html
index bfc1650..2aedb54 100644
--- a/layouts/partials/docs/menu-bundle.html
+++ b/layouts/partials/docs/menu-bundle.html
@@ -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 }}
diff --git a/layouts/partials/docs/menu-filetree.html b/layouts/partials/docs/menu-filetree.html
index 9ed63ea..abc6fd9 100644
--- a/layouts/partials/docs/menu-filetree.html
+++ b/layouts/partials/docs/menu-filetree.html
@@ -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 }}
diff --git a/layouts/partials/docs/menu.html b/layouts/partials/docs/menu.html
index d280713..6a72ac9 100644
--- a/layouts/partials/docs/menu.html
+++ b/layouts/partials/docs/menu.html
@@ -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>
diff --git a/layouts/partials/docs/mobile-header.html b/layouts/partials/docs/mobile-header.html
index b8fa2a9..720b83d 100644
--- a/layouts/partials/docs/mobile-header.html
+++ b/layouts/partials/docs/mobile-header.html
@@ -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>
diff --git a/layouts/partials/docs/search.html b/layouts/partials/docs/search.html
new file mode 100644
index 0000000..d4b0e65
--- /dev/null
+++ b/layouts/partials/docs/search.html
@@ -0,0 +1,2 @@
+<input type="text" placeholder="Search" class="book-search" id="book-search" />
+<ul id="book-search-results"></ul>
diff --git a/layouts/partials/docs/shared.html b/layouts/partials/docs/shared.html
deleted file mode 100644
index 2545dea..0000000
--- a/layouts/partials/docs/shared.html
+++ /dev/null
@@ -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 }}
diff --git a/layouts/partials/docs/title.html b/layouts/partials/docs/title.html
new file mode 100644
index 0000000..91d5f81
--- /dev/null
+++ b/layouts/partials/docs/title.html
@@ -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 }}
diff --git a/layouts/posts/baseof.html b/layouts/posts/baseof.html
index 6b32b2e..ba4b91c 100644
--- a/layouts/posts/baseof.html
+++ b/layouts/posts/baseof.html
@@ -1,5 +1,4 @@
<!DOCTYPE html>
-{{- partial "docs/shared" -}}
<html lang="{{ .Site.Language.Lang }}">
<head>