Skip to content

Commit ee374ef

Browse files
committed
update book stack
1 parent 11b27e3 commit ee374ef

File tree

8 files changed

+93
-7
lines changed

8 files changed

+93
-7
lines changed

assets/js/menu-reset.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(function() {
2+
var menu = document.querySelector("aside .book-menu-content");
3+
addEventListener("beforeunload", function(event) {
4+
localStorage.setItem("menu.scrollTop", menu.scrollTop);
5+
});
6+
menu.scrollTop = localStorage.getItem("menu.scrollTop");
7+
})();

layouts/_default/single.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{{ define "main" }}
2-
<div class="post">
3-
<div class="post__header">
4-
{{ $image := .Resources.GetMatch .Params.image }}
5-
<img class="post__image" src="{{ $image.RelPermalink }}">
2+
<aside>
3+
<div>
4+
{{ template "book-menu" . }}
65
</div>
6+
</aside>
77

8+
<div class="post">
89
{{ with .Params.tags }}
910
<div class="post__tags">
1011
{{ range . }}
@@ -23,3 +24,7 @@ <h1 id="title">{{ .Title }}</h1>
2324
</section>
2425
</div>
2526
{{ end }}
27+
28+
{{ define "book-menu" }}
29+
{{ partial "partials/book-menu" . }}
30+
{{ end }}

layouts/_default/summary.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
{{ if and .Params .Params.cover }}
12
<article class="article">
23
<a class="article__inner" href="{{ .Permalink }}">
34
<div class="article__header">
4-
{{ $image := .Resources.GetMatch .Params.image }}
5+
{{ $image := resources.Get .Params.image }}
6+
{{ if $image }}
57
<img class="article__image" src="{{ $image.RelPermalink }}">
8+
{{ end }}
69
</div>
710
<div class="article__text">
811
<h3 class="article__title">{{ .Title }}</h3>
@@ -12,3 +15,4 @@ <h3 class="article__title">{{ .Title }}</h3>
1215
<time datetime="{{ .Date }}">{{ .Date.Format "2006/01/02" }}</time>
1316
</footer>
1417
</article>
18+
{{ end }}

layouts/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{{ define "main" }}
22
{{- partial "profile.html" }}
33

4-
{{- $pages := where site.RegularPages "Type" "in" site.Params.mainSections }}
4+
{{- $pages := (where site.RegularPages "Params.cover" "eq" true) }}
5+
{{ $pages = sort $pages "Params.weight" }}
56
{{- $paginator := .Paginate $pages }}
67

78
<section class="article-list">
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{{ $bookSection := default "posts" .Site.Params.BookSection }}
2+
{{ if eq $bookSection "*" }}
3+
{{ $bookSection = "/" }}{{/* Backward compatibility */}}
4+
{{ end }}
5+
6+
{{ with .Site.GetPage $bookSection .CurrentSection.Title }}
7+
{{ template "book-section-children" (dict "Section" . "CurrentPage" $) }}
8+
{{ end }}
9+
10+
{{ define "book-section-children" }}{{/* (dict "Section" .Section "CurrentPage" .CurrentPage) */}}
11+
<ul>
12+
{{ range (where .Section.Pages "Params.bookhidden" "ne" true) }}
13+
{{ if .IsSection }}
14+
<li {{- if .Params.BookFlatSection }} class="book-section-flat" {{ end -}}>
15+
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
16+
{{ template "book-section-children" (dict "Section" . "CurrentPage" $.CurrentPage) }}
17+
</li>
18+
{{ else if and .IsPage .Content }}
19+
<li>
20+
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
21+
</li>
22+
{{ end }}
23+
{{ end }}
24+
</ul>
25+
{{ end }}
26+
27+
{{ define "book-page-link" }}{{/* (dict "Page" .Page "CurrentPage" .CurrentPage) */}}
28+
{{ $current := eq .CurrentPage .Page }}
29+
{{ $ancestor := .Page.IsAncestor .CurrentPage }}
30+
31+
{{ if .Page.Params.bookCollapseSection }}
32+
<input type="checkbox" id="section-{{ md5 .Page }}" class="toggle" {{ if or $current $ancestor }}checked{{ end }} />
33+
<label for="section-{{ md5 .Page }}" class="flex justify-between">
34+
<a {{ if .Page.Content }}href="{{ .Page.Permalink }}"{{ else }}role="button"{{ end }} class="{{ if $current }}active{{ end }}">
35+
{{- partial "title" .Page -}}
36+
</a>
37+
</label>
38+
{{ else if .Page.Content }}
39+
<a href="{{ .Page.Permalink }}" class="{{ if $current }} active{{ end }}">
40+
{{- partial "title" .Page -}}
41+
</a>
42+
{{ else }}
43+
<span>{{- partial "title" .Page -}}</span>
44+
{{ end }}
45+
{{ end }}

layouts/partials/book-menu.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<nav>
2+
{{ partial "partials/book-menu-filetree" . }}
3+
</nav>
4+
5+
<!-- Restore menu position as soon as possible to avoid flickering -->
6+
{{ $script := resources.Get "js/menu-reset.js" | resources.Minify }}
7+
{{ with $script.Content }}
8+
<script>{{ . | safeJS }}</script>
9+
{{ end }}

layouts/partials/pagination.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="pagination">
2-
{{- $pages := where site.RegularPages "Type" "in" site.Params.mainSections }}
2+
{{- $pages := (where site.RegularPages "Params.cover" "eq" true) }}
33
{{- $paginator := .Paginate $pages }}
44

55
{{ range $paginator.Pagers }}

layouts/partials/title.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!--
2+
Partial to generate page name from Title or File name.
3+
Accepts Page as context
4+
-->
5+
{{ $title := "" }}
6+
7+
{{ if .Title }}
8+
{{ $title = .Title }}
9+
{{ else if and .IsSection .File }}
10+
{{ $title = path.Base .File.Dir | humanize | title }}
11+
{{ else if and .IsPage .File }}
12+
{{ $title = .File.BaseFileName | humanize | title }}
13+
{{ end }}
14+
15+
{{ return $title }}

0 commit comments

Comments
 (0)