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
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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 }}
|
||||
Reference in New Issue
Block a user