mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-29 12:03:31 +08:00
feat: unify page layout, and add config to disable toc
This commit is contained in:
parent
b311e02b63
commit
2f099151fa
@ -42,6 +42,7 @@ params:
|
|||||||
|
|
||||||
article:
|
article:
|
||||||
math: false
|
math: false
|
||||||
|
toc: true
|
||||||
license:
|
license:
|
||||||
enabled: true
|
enabled: true
|
||||||
default: Licensed under CC BY-NC-SA 4.0
|
default: Licensed under CC BY-NC-SA 4.0
|
||||||
|
@ -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" }}
|
{{ define "main" }}
|
||||||
{{ partial "article/article.html" . }}
|
{{ partial "article/article.html" . }}
|
||||||
|
|
||||||
|
{{ partial "article/components/related-contents" . }}
|
||||||
|
|
||||||
{{ if or (not (isset .Params "comments")) (eq .Params.comments "true")}}
|
{{ if or (not (isset .Params "comments")) (eq .Params.comments "true")}}
|
||||||
{{ partial "comments/include" . }}
|
{{ partial "comments/include" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
@ -10,3 +25,33 @@
|
|||||||
|
|
||||||
{{ partialCached "article/components/photoswipe" . }}
|
{{ partialCached "article/components/photoswipe" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ define "left-sidebar" }}
|
||||||
|
{{ if (.Scratch.Get "hasTOC") }}
|
||||||
|
<div id="article-toolbar">
|
||||||
|
<a href="{{ .Site.BaseURL }}" class="back-home">
|
||||||
|
{{ (resources.Get "icons/back.svg").Content | safeHTML }}
|
||||||
|
<span>Back</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{{ else }}
|
||||||
|
{{ partial "sidebar/left.html" . }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ define "right-sidebar" }}
|
||||||
|
{{ if (.Scratch.Get "hasTOC") }}
|
||||||
|
<aside class="sidebar right-sidebar sticky">
|
||||||
|
<section class="widget archives">
|
||||||
|
<div class="widget-icon">
|
||||||
|
{{ partial "helper/icon" "hash" }}
|
||||||
|
</div>
|
||||||
|
<h2 class="widget-title section-title">Table of contents</h2>
|
||||||
|
|
||||||
|
<div class="widget--toc">
|
||||||
|
{{ .TableOfContents }}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</aside>
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
@ -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") }}
|
|
||||||
<div id="article-toolbar">
|
|
||||||
<a href="{{ .Site.BaseURL }}" class="back-home">
|
|
||||||
{{ (resources.Get "icons/back.svg").Content | safeHTML }}
|
|
||||||
<span>Back</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
{{ else }}
|
|
||||||
{{ partial "sidebar/left.html" . }}
|
|
||||||
{{ end }}
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
{{ define "right-sidebar" }}
|
|
||||||
{{ if (.Scratch.Get "hasTOC") }}
|
|
||||||
<aside class="sidebar right-sidebar sticky">
|
|
||||||
<section class="widget archives">
|
|
||||||
<div class="widget-icon">
|
|
||||||
{{ partial "helper/icon" "hash" }}
|
|
||||||
</div>
|
|
||||||
<h2 class="widget-title section-title">Table of contents</h2>
|
|
||||||
|
|
||||||
<div class="widget--toc">
|
|
||||||
{{ .TableOfContents }}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</aside>
|
|
||||||
{{ end }}
|
|
||||||
{{ end }}
|
|
Loading…
Reference in New Issue
Block a user