aboutsummaryrefslogtreecommitdiff
path: root/layouts
diff options
context:
space:
mode:
authorAlex Shpak <alex-shpak@users.noreply.github.com>2019-04-22 19:17:39 +0200
committerAlex Shpak <alex-shpak@users.noreply.github.com>2019-04-22 19:17:39 +0200
commit0b30289d9f3520144bb37caa009d8953cde0e3d6 (patch)
tree0f9bb8c645db952484ae1d0d98f961142184c894 /layouts
parent0084e069de16a7b6c15f50edd7479e2e49fe0874 (diff)
#43, Update tree menu rendering to support multiple sections
Diffstat (limited to 'layouts')
-rw-r--r--layouts/home.html4
-rw-r--r--layouts/partials/docs/git-footer.html2
-rw-r--r--layouts/partials/docs/menu-bundle.html5
-rw-r--r--layouts/partials/docs/menu-filetree.html76
-rw-r--r--layouts/partials/docs/menu.html6
-rw-r--r--layouts/partials/docs/shared.html25
-rw-r--r--layouts/posts/list.html6
-rw-r--r--layouts/posts/single.html4
8 files changed, 70 insertions, 58 deletions
diff --git a/layouts/home.html b/layouts/home.html
index d2db819..bf76fc7 100644
--- a/layouts/home.html
+++ b/layouts/home.html
@@ -6,7 +6,7 @@
{{ partial "docs/html-head" . }}
{{ partial "docs/inject/head" . }}
</head>
-{{- $content := `
+{{ $content := `
# Hugo Book Theme
This is a placeholder for home page.
@@ -14,7 +14,7 @@ You can override this page in:
- &#96;/content/_index.md&#96;
- &#96;/layouts/home.html&#96;
-` -}}
+` }}
<body>
<main class="flex justify-center">
<div class="book-page markdown">
diff --git a/layouts/partials/docs/git-footer.html b/layouts/partials/docs/git-footer.html
index 4b2f44d..001c9ff 100644
--- a/layouts/partials/docs/git-footer.html
+++ b/layouts/partials/docs/git-footer.html
@@ -2,7 +2,7 @@
<div class="align-center book-git-footer {{ if not .GitInfo }}justify-end{{ else }}justify-between{{ end }}">
{{ with .GitInfo }}
<div>
- {{- $date := .AuthorDate.Local.Format (default "January 2, 2006" $.Site.Params.BookDateFormat) -}}
+ {{ $date := .AuthorDate.Local.Format (default "January 2, 2006" $.Site.Params.BookDateFormat) }}
<a href="{{ $.Site.Params.BookRepo }}/commit/{{ .Hash }}" title='Last modified {{ $date }} by {{ .AuthorName }}' target="_blank" rel="noopener">
<img src="{{ "svg/code-merge.svg" | relURL }}" /> {{ $date }}
</a>
diff --git a/layouts/partials/docs/menu-bundle.html b/layouts/partials/docs/menu-bundle.html
index 5d90bbf..bfc1650 100644
--- a/layouts/partials/docs/menu-bundle.html
+++ b/layouts/partials/docs/menu-bundle.html
@@ -1,7 +1,4 @@
-{{- template "hrefhack" . -}}
+{{ template "hrefhack" . }}
{{ with .Site.GetPage .Site.Params.BookMenuBundle }}
{{- .Content -}}
{{ end }}
-{{ if .Site.Params.BookEnableJS }}
- {{- template "jsmenu" . -}}
-{{ end }} \ No newline at end of file
diff --git a/layouts/partials/docs/menu-filetree.html b/layouts/partials/docs/menu-filetree.html
index 8530656..b0f28c0 100644
--- a/layouts/partials/docs/menu-filetree.html
+++ b/layouts/partials/docs/menu-filetree.html
@@ -1,47 +1,59 @@
-<!-- Put configured sections list to .Scratch -->
-{{ template "book-get-root-section" . }}
+{{ $bookSection := default "docs" .Site.Params.BookSection }}
+{{ if eq $bookSection "*" }}
+ {{ .Scratch.Set "BookSections" .Site.Sections }}
+{{ else }}
+ {{ $bookSections := where .Site.Sections "Section" $bookSection }}
+ {{ .Scratch.Set "BookSections" $bookSections }}
+{{ end }}
-{{- range .Scratch.Get "BookSections" -}}
- {{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }}
-{{- end -}}
-{{ define "book-section" }} <!-- Single section of menu (recursive) -->
+{{ $sections := .Scratch.Get "BookSections" }}
+{{/* If there is only one section to render then render its children, else render all sections */}}
+{{ if eq (len $sections) 1 }}
+ {{ with index $sections 0 }}
+ {{ template "book-section-children" (dict "Section" . "CurrentPage" $.Permalink) }}
+ {{ end }}
+{{ else }}
<ul>
- {{ range .Section.Sections }}
- <li {{- if .Params.bookflatsection}} class="flat-section" {{ end }}>
- {{- if .Content -}}
- {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
- {{- else -}}
- {{- template "title" . -}}
- {{- end -}}
+ {{ range $sections }}
+ {{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }}
+ {{ end }}
+ </ul>
+{{ end }}
- {{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }}
- </li>
+{{ define "book-section" }}
+{{ with .Section }}
+ <li {{ if .Params.bookFlatSection}} class="book-section-flat" {{ end }}>
+ {{ if .Content }}
+ {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
+ {{ else }}
+ <span>{{ template "title" . }}</span>
{{ end }}
- {{ range .Section.Pages }}
+ {{ template "book-section-children" (dict "Section" . "CurrentPage" $.CurrentPage) }}
+ </li>
+{{ end }}
+{{ end }}
+
+{{ define "book-section-children" }}
+{{ with .Section }}
+ <ul>
+ {{ range .Sections }}
+ {{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }}
+ {{ end }}
+ {{ range .Pages }}
<li>
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
</li>
{{ end }}
</ul>
{{ end }}
+{{ end }}
{{ define "book-page-link" }}
-{{- with .Page -}}
-<a href="{{ .RelPermalink }}" {{- if eq $.CurrentPage .Permalink }} class="active"{{ end }}>
- {{- template "title" . -}}
-</a>
-{{- end -}}
+{{ with .Page }}
+ <a href="{{ .RelPermalink }}" {{ if eq $.CurrentPage .Permalink }} class="active"{{ end }}>
+ {{ template "title" . }}
+ </a>
+{{ end }}
{{ end }}
-
-{{ define "book-get-root-section" }}
-<!-- Complex logic to guess page title without .Title specified -->
- {{ $bookSection := default "docs" .Site.Params.BookSection }}
- {{ if eq $bookSection "*" }}
- {{ .Scratch.Set "BookSections" .Site.Sections }}
- {{ else }}
- {{ $bookSections := where .Site.Sections "Section" $bookSection }}
- {{ .Scratch.Set "BookSections" $bookSections }}
- {{ end }}
-{{ end }} \ No newline at end of file
diff --git a/layouts/partials/docs/menu.html b/layouts/partials/docs/menu.html
index 0ded211..238f976 100644
--- a/layouts/partials/docs/menu.html
+++ b/layouts/partials/docs/menu.html
@@ -9,4 +9,8 @@
{{ end }}
{{ partial "docs/inject/menu-after" . }}
-</nav> \ No newline at end of file
+</nav>
+
+{{ if .Site.Params.BookEnableJS }}
+ {{ template "jsmenu" . }}
+{{ end }}
diff --git a/layouts/partials/docs/shared.html b/layouts/partials/docs/shared.html
index 3fbf628..2678840 100644
--- a/layouts/partials/docs/shared.html
+++ b/layouts/partials/docs/shared.html
@@ -1,16 +1,16 @@
{{/*These templates contains some more complex logic and shared between partials*/}}
-{{- define "title" -}}
- {{- if and .File .Pages -}}
+{{ define "title" }}
+ {{ if and .File .Pages }}
{{ $sections := split (trim .File.Dir "/") "/" }}
{{ $title := index ($sections | last 1) 0 | humanize | title }}
- {{- default $title .Title -}}
- {{- else if .File -}}
- {{ $title := .File | humanize | title }}
- {{- default $title .Title -}}
- {{- end -}}
-{{- end -}}
+ {{ default $title .Title }}
+ {{ else if .File }}
+ {{ $title := .File.BaseFileName | humanize | title }}
+ {{ default $title .Title }}
+ {{ end }}
+{{ end }}
-{{- define "hrefhack" -}}
+{{ define "hrefhack" }}
{{ $attrEq := "$=" }}
{{ $attrVal := .RelPermalink }}
{{ if eq .RelPermalink "/" }}
@@ -23,17 +23,16 @@
color: {{ default "#004ed0" .Site.Params.BookMenuBundleActiveLinkColor }};
}
</style>
-{{- end -}}
+{{ end }}
-{{- define "jsmenu" -}}
+{{ 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 -}} \ No newline at end of file
+{{ end }} \ No newline at end of file
diff --git a/layouts/posts/list.html b/layouts/posts/list.html
index 18871f2..13e1ea1 100644
--- a/layouts/posts/list.html
+++ b/layouts/posts/list.html
@@ -1,15 +1,15 @@
{{ define "main" }}
- {{- $dateFormat := default "January 2, 2006" .Site.Params.BookDateFormat -}}
+ {{ $dateFormat := default "January 2, 2006" .Site.Params.BookDateFormat }}
{{ $paginator := .Paginate (where .Pages "Params.hidden" "ne" true) }}
{{ range sort .Paginator.Pages }}
- <article>
+ <article class="markdown">
<h2>
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
</h2>
<h5>
<strong>{{ .Date.Format $dateFormat }}</strong>
</h5>
- <p class="markdown">
+ <p>
{{- .Summary -}}
{{ if .Truncated }}
<a href="{{ .RelPermalink }}">...</a>
diff --git a/layouts/posts/single.html b/layouts/posts/single.html
index a7f94ed..9222a59 100644
--- a/layouts/posts/single.html
+++ b/layouts/posts/single.html
@@ -1,6 +1,6 @@
{{ define "main" }}
-{{- $dateFormat := default "January 2, 2006" .Site.Params.BookDateFormat -}}
-<header>
+{{ $dateFormat := default "January 2, 2006" .Site.Params.BookDateFormat }}
+<header class="markdown">
<h1>{{ .Title }}</h1>
<h5>
<strong>{{ .Date.Format $dateFormat }}</strong>