From cf91ff39630cead0fad16c16858405b3efbe7994 Mon Sep 17 00:00:00 2001 From: Ngô Ngọc Đức Huy Date: Fri, 4 Aug 2023 10:17:49 +0700 Subject: Implement table of contents --- layouts/_default/list.html | 4 ++-- layouts/partials/post-navigation-top.html | 3 +++ layouts/partials/post-navigation.html | 2 ++ layouts/partials/root-toc.html | 8 ++++++++ layouts/partials/toc.html | 11 ++++++++--- 5 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 layouts/partials/root-toc.html (limited to 'layouts') 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" }} -
+
{{ .Content }}
{{ if in .Params.categories "book" }} {{ partial "post-navigation-top.html" . }}
- {{ partial "toc.html" . }} + {{ partial "toc.html" (dict "content" . "currentLink" .RelPermalink) }}
{{ 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}} +{{ 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 @@ +
+ {{ i18n "toc" }} + {{ $currentLink := .RelPermalink }} + {{ range last 1 (where .Ancestors "Params.categories" "intersect" (slice "book") ) }} + {{ .Title }} + {{ partial "toc.html" (dict "content" . "currentLink" $currentLink) }} + {{ end }} +
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 }} - {{ trim $fullTitle " " }} + {{ if eq $currentLink .RelPermalink }} + {{ trim $fullTitle " " }} ({{ i18n "current"}}) + {{ else }} + {{ trim $fullTitle " " }} + {{ end }} {{ partial "post-info.html" . }} {{ if .IsSection}} - {{ partial "toc.html" . }} + {{ partial "toc.html" (dict "content" . "currentLink" $currentLink) }} {{ end }} {{ end }} -- cgit 1.4.1