From ce8755c3d3834644555a073c139da0980e9d06fd Mon Sep 17 00:00:00 2001 From: John Bowdre Date: Mon, 6 Dec 2021 20:57:34 -0600 Subject: [PATCH] implement TableOfContents in sidebar for posts with more than 400 words --- config/_default/markup.toml | 4 ++ config/_default/params.toml | 1 + layouts/_default/single.html | 54 ++++++++++++++++ layouts/partials/sidebar.html | 116 ++++++++++++++++++++++++++++++++++ 4 files changed, 175 insertions(+) create mode 100644 layouts/_default/single.html create mode 100644 layouts/partials/sidebar.html diff --git a/config/_default/markup.toml b/config/_default/markup.toml index ae478b0..a2880f1 100644 --- a/config/_default/markup.toml +++ b/config/_default/markup.toml @@ -15,3 +15,7 @@ noClasses = false # style = "monokai" tabWidth = 2 +[tableOfContents] + endlevel = 6 + ordered = false + startLevel = 3 diff --git a/config/_default/params.toml b/config/_default/params.toml index 0058465..818aa8f 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -81,6 +81,7 @@ iconsDir = "images/icons/" # without a leading forward slash # Show related content at the end of an article based on the 'series' taxonomy. Can be set in post front matter. # showRelatedInArticle = false # showRelatedInSidebar = false +toc = true # website author [author] diff --git a/layouts/_default/single.html b/layouts/_default/single.html new file mode 100644 index 0000000..9ecfe43 --- /dev/null +++ b/layouts/_default/single.html @@ -0,0 +1,54 @@ +{{- define "main" }} +{{- $s := .Site.Params }} +{{- $p := .Params }} +{{- $scratch := newScratch }} +{{- if isset $p "image" }} + {{- $scratch.Set "image" $p.image }} +{{- else }} + {{ $scratch.Set "image" $s.fallBackOgImage }} +{{- end }} +{{- $image := $scratch.Get "image" }} +{{- $bg := absLangURL (path.Join "images" $image) }} +
+
+ {{- $t := .Title }} +

{{ $t }}

+ {{- partial "post-meta" . }} + {{- partial "image-feature" . }} + +
+ {{- .Content }} +
+ + {{- $showRelatedInArticle := true }} + {{- if eq $s.showRelatedInArticle false }} + {{- $showRelatedInArticle = false }} + {{- else if eq $p.showRelatedInArticle false }} + {{- $showRelatedInArticle = false }} + {{- end }} + {{- if ne $showRelatedInArticle false }} + {{- partial "related" . }} + {{- end }} + + {{- $showComments := true }} + {{- if eq $s.comments false }} + {{- $showComments = false }} + {{- else if eq $p.comments false }} + {{- $showComments = false }} + {{- end }} + {{- if ne $showComments false }} + {{- partial "comments" . }} + {{- end }} + {{- partial "i18nlist" . }} + +
+ {{- if ( ne $p.sidebar false ) }} + {{- partial "sidebar" . }} + {{ end }} +
+{{- end }} diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html new file mode 100644 index 0000000..17aa087 --- /dev/null +++ b/layouts/partials/sidebar.html @@ -0,0 +1,116 @@ +{{ $s := site.Params }} +