Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CaiJimmy/hugo-theme-stack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimmy Cai <jimmehcai@gmail.com>2021-06-21 19:44:54 +0300
committerGitHub <noreply@github.com>2021-06-21 19:44:54 +0300
commit41fa65cbf5c43301c56b74a7cb2a8bb2edc54f1e (patch)
tree596c55104597c905d4530839f583db1edc18a762 /layouts
parentdda55f87e28e5132abfe0bcb4991e93c79688e5e (diff)
feat: Table of Contents (#232)
Currently, the new table of contents is disabled by default. I will change that after several versions. ------------- * feat: Table of Content (WIP) * fix: set scratch inside define block * fix(toc): darkmode text color * feat: unify page layout, and add config to disable toc * feat: add scroll-behavior: smooth to html * fix: use <ol> for TOC. And Disable TOC by default for now * refactor: use css flexbox for article page with toc enable toc for example site * feat(i18n): add i18n entry for "Back" and "Table of Contents" * style: remove unused `keep-sidebar` class * doc: add table of contents as feature
Diffstat (limited to 'layouts')
-rw-r--r--layouts/_default/baseof.html6
-rw-r--r--layouts/_default/single.html47
-rw-r--r--layouts/post/single.html21
3 files changed, 50 insertions, 24 deletions
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index ce0ddae..8a5ff95 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -6,8 +6,10 @@
</head>
<body class="{{ block `body-class` . }}{{ end }}">
{{- partial "head/colorScheme" . -}}
- <div class="container main-container flex on-phone--column {{ if .Site.Params.widgets.enabled }}extended{{ else }}compact{{ end }} {{ block `container-class` . }}{{end}}">
- {{ partial "sidebar/left.html" . }}
+ <div class="container main-container flex {{ block `container-class` . }}on-phone--column {{ if .Site.Params.widgets.enabled }}extended{{ else }}compact{{ end }}{{ end }}">
+ {{- block "left-sidebar" . -}}
+ {{ partial "sidebar/left.html" . }}
+ {{- end -}}
<main class="main full-width">
{{- block "main" . }}{{- end }}
</main>
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index d9d2f3e..040b547 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 false .Site.Params.article.toc) .Params.toc }}
+ {{- .Scratch.Set "hasTOC" (and (ge (len .TableOfContents) 100) $TOCEnabled) -}}
+ article-page {{ if (.Scratch.Get "hasTOC") }}has-toc{{ end }}
+{{ end }}
+
+{{ define "container-class" }}
+ {{ if (.Scratch.Get "hasTOC") }}
+ extended
+ {{ else }}
+ on-phone--column {{ 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") }}
+ <div id="article-toolbar">
+ <a href="{{ .Site.BaseURL }}" class="back-home">
+ {{ (resources.Get "icons/back.svg").Content | safeHTML }}
+ <span>{{ T "article.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">{{ T "article.tableOfContents" }}</h2>
+
+ <div class="widget--toc">
+ {{ .TableOfContents }}
+ </div>
+ </section>
+ </aside>
+ {{ 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 be983ec..0000000
--- a/layouts/post/single.html
+++ /dev/null
@@ -1,21 +0,0 @@
-{{ define "container-class" }}article-page with-toolbar hide-sidebar-sm{{ end }}
-{{ define "main" }}
- <div id="article-toolbar">
- <a href="{{ .Site.BaseURL }}" class="back-home">
- {{ (resources.Get "icons/back.svg").Content | safeHTML }}
- <span>Back</span>
- </a>
- </div>
-
- {{ 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.html" . -}}
-{{ end }} \ No newline at end of file