diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index 51274d6..5c51177 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -42,6 +42,7 @@ params: article: math: false + toc: true license: enabled: true default: Licensed under CC BY-NC-SA 4.0 diff --git a/layouts/_default/single.html b/layouts/_default/single.html index d9d2f3e..49b4685 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -1,7 +1,22 @@ -{{ define "body-class" }}article-page{{ end }} +{{ define "body-class" }} + {{ $TOCEnabled := default (default true .Site.Params.article.toc) .Params.toc }} + {{- .Scratch.Set "hasTOC" (and (ge (len .TableOfContents) 100) $TOCEnabled) -}} + article-page keep-sidebar{{ if (.Scratch.Get "hasTOC") }} has-toc{{ end }} +{{ end }} + +{{ define "container-class" }} + {{ if (.Scratch.Get "hasTOC") }} + extended + {{ else }} + {{ if .Site.Params.widgets.enabled }}extended{{ else }}compact{{ end }} + {{ end }} +{{ end }} + {{ define "main" }} {{ partial "article/article.html" . }} + {{ partial "article/components/related-contents" . }} + {{ if or (not (isset .Params "comments")) (eq .Params.comments "true")}} {{ partial "comments/include" . }} {{ end }} @@ -9,4 +24,34 @@ {{ partialCached "footer/footer" . }} {{ partialCached "article/components/photoswipe" . }} +{{ end }} + +{{ define "left-sidebar" }} + {{ if (.Scratch.Get "hasTOC") }} +
+ + {{ (resources.Get "icons/back.svg").Content | safeHTML }} + Back + +
+ {{ else }} + {{ partial "sidebar/left.html" . }} + {{ end }} +{{ end }} + +{{ define "right-sidebar" }} + {{ if (.Scratch.Get "hasTOC") }} + + {{ end }} {{ end }} \ No newline at end of file diff --git a/layouts/post/single.html b/layouts/post/single.html deleted file mode 100644 index 30240a9..0000000 --- a/layouts/post/single.html +++ /dev/null @@ -1,48 +0,0 @@ -{{ define "body-class" }} - {{- .Scratch.Set "hasTOC" (ge (len .TableOfContents) 100) -}} - article-page keep-sidebar{{ if (.Scratch.Get "hasTOC") }} has-toc{{ end }} -{{ end }} -{{ define "container-class" }}extended{{ end }} -{{ define "main" }} - {{ partial "article/article.html" . }} - - {{ partial "article/components/related-contents" . }} - - {{ if or (not (isset .Params "comments")) (eq .Params.comments "true")}} - {{ partial "comments/include" . }} - {{ end }} - - {{ partialCached "footer/footer" . }} - - {{ partialCached "article/components/photoswipe" . }} -{{ end }} - -{{ define "left-sidebar" }} - {{ if (.Scratch.Get "hasTOC") }} -
- - {{ (resources.Get "icons/back.svg").Content | safeHTML }} - Back - -
- {{ else }} - {{ partial "sidebar/left.html" . }} - {{ end }} -{{ end }} - -{{ define "right-sidebar" }} - {{ if (.Scratch.Get "hasTOC") }} - - {{ end }} -{{ end }} \ No newline at end of file