about summary refs log tree commit diff
path: root/layouts
diff options
context:
space:
mode:
authorNgô Ngọc Đức Huy <huyngo@disroot.org>2023-08-04 10:17:49 +0700
committerNgô Ngọc Đức Huy <huyngo@disroot.org>2023-08-04 10:19:36 +0700
commitcf91ff39630cead0fad16c16858405b3efbe7994 (patch)
tree3ead000d81c815cdc0fb8403f6a3d7c294cba1eb /layouts
parent3f8ec96f3436b1b1a1c91807694280cb08fe7ce9 (diff)
downloadvictor-cf91ff39630cead0fad16c16858405b3efbe7994.tar.gz
Implement table of contents
Diffstat (limited to 'layouts')
-rw-r--r--layouts/_default/list.html4
-rw-r--r--layouts/partials/post-navigation-top.html3
-rw-r--r--layouts/partials/post-navigation.html2
-rw-r--r--layouts/partials/root-toc.html8
-rw-r--r--layouts/partials/toc.html11
5 files changed, 23 insertions, 5 deletions
diff --git a/layouts/_default/list.html b/layouts/_default/list.html
index 9a4672e..0f104a4 100644
--- a/layouts/_default/list.html
+++ b/layouts/_default/list.html
@@ -5,13 +5,13 @@ SPDX-License-Identifier: MIT
 */}}
 
 {{ define "main" }}
-  <section class="index-content">
+  <section class="index-content" id="main">
     {{ .Content }}
   </section>
   {{ if in .Params.categories "book" }}
   {{ partial "post-navigation-top.html" . }}
   <section class="toc">
-    {{ partial "toc.html" . }}
+    {{ partial "toc.html" (dict "content" . "currentLink" .RelPermalink) }}
   </section>
   {{ else if in .Params.categories "blog" }}
     {{ partial "feed.html" . }}
diff --git a/layouts/partials/post-navigation-top.html b/layouts/partials/post-navigation-top.html
index 3bcc39f..a7470c0 100644
--- a/layouts/partials/post-navigation-top.html
+++ b/layouts/partials/post-navigation-top.html
@@ -1,2 +1,5 @@
+{{ if or (in .Params.categories "book") (in .CurrentSection.Params.categories "book") }}
 {{ partial "breadcrumbs.html" .}}
+{{ partial "root-toc.html" .}}
+{{ end}}
 {{ partial "post-navigation.html" .}}
diff --git a/layouts/partials/post-navigation.html b/layouts/partials/post-navigation.html
index b88d91f..edd1333 100644
--- a/layouts/partials/post-navigation.html
+++ b/layouts/partials/post-navigation.html
@@ -1,3 +1,4 @@
+{{ if not .IsSection}}
 <nav>
 	{{ if .NextInSection }}
 	<a class="nav-next" href="{{ .NextInSection.RelPermalink }}">{{ .NextInSection.Title }}</a>
@@ -7,3 +8,4 @@
 	<a  class="nav-prev"href="{{ .PrevInSection.RelPermalink }}">{{ .PrevInSection.Title }}</a>
 	{{ end }}
 </nav>
+{{ end }}
diff --git a/layouts/partials/root-toc.html b/layouts/partials/root-toc.html
new file mode 100644
index 0000000..2792ce9
--- /dev/null
+++ b/layouts/partials/root-toc.html
@@ -0,0 +1,8 @@
+	<details class="toc-collapse">
+		<summary>{{ i18n "toc" }}</summary>
+		{{ $currentLink := .RelPermalink }}
+		{{ range last 1 (where .Ancestors "Params.categories" "intersect" (slice "book") ) }}
+		<a href="{{ .RelPermalink }}">{{ .Title }}</a>
+		{{ partial "toc.html" (dict "content" . "currentLink" $currentLink) }}
+		{{ end }}
+	</details>
diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html
index 607e7f0..3b5a822 100644
--- a/layouts/partials/toc.html
+++ b/layouts/partials/toc.html
@@ -1,4 +1,5 @@
-{{ $chapters := .Page.Pages }}
+{{ $chapters := .content.Page.Pages }}
+{{ $currentLink := .currentLink}}
 {{ range .Page.Translations }}
 {{ $chapters = $chapters | lang.Merge .Pages }}
 {{ end}}
@@ -9,10 +10,14 @@
     {{ with .Params.chapterName }}
       {{ $fullTitle = printf "%s – %s" $fullTitle . }}
     {{ end }}
-    <a href="{{ .RelPermalink }}">{{ trim $fullTitle " " }}</a>
+    {{ if eq $currentLink .RelPermalink }}
+      <a aria-current="page">{{ trim $fullTitle " " }}</a> ({{ i18n "current"}})
+    {{ else }}
+      <a href="{{ .RelPermalink }}">{{ trim $fullTitle " " }}</a>
+    {{ end }}
     {{ partial "post-info.html" . }}
     {{ if .IsSection}}
-      {{ partial "toc.html" . }}
+      {{ partial "toc.html" (dict "content" . "currentLink" $currentLink) }}
     {{ end }}
   </li>
   {{ end }}