Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for displaying TOC on the side of page #398

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/scss/layout/_single.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ blockquote {
}

.contents {
position: $tocPosition;
margin-top: 5em;
ol, ul {
list-style: none;
Expand Down
7 changes: 7 additions & 0 deletions assets/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
$enableSmoothScroll: false;
{{ end }}


{{ if .Site.Params.displayTOConSide }}
$tocPosition: fixed;
{{ else }}
$tocPosition: inherit;
{{ end }}

$baseRelURL: "{{ "" | relURL | strings.TrimSuffix "/" }}";


Expand Down
3 changes: 3 additions & 0 deletions config-examples/zh-cn/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,9 @@ uglyURLs = false
# 是否链接文章的分节标题到目录
linkHeadingsToTOC = true

# 是否将目录置于页面左侧
displayTOConSide = false


######################################
# 分节标题锚点
Expand Down
12 changes: 10 additions & 2 deletions layouts/partials/pages/post.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<main class="main single" id="main">

{{ $enableTOC := .Params.toc | default .Site.Params.enableTOC -}}
{{ $displayTOConSide := default .Site.Params.displayTOConSide -}}
{{- if and $enableTOC $displayTOConSide -}}
{{- partial "utils/toc.html" . -}}
{{- end -}}

<div class="main-inner">

{{ $attrs := partial "utils/data-attributes.html" . }}
Expand Down Expand Up @@ -29,9 +36,10 @@ <h1 class="post-title p-name">{{ (partial "utils/title.html" (dict "$" $ "title"
{{ partial "components/post-meta.html" (dict "$" . "isHome" false) }}
{{ end }}

{{ $enableTOC := .Params.toc | default .Site.Params.enableTOC -}}
{{- if $enableTOC -}}
{{- partial "utils/toc.html" . -}}
{{- if not $displayTOConSide -}}
{{- partial "utils/toc.html" . -}}
{{- end -}}
{{- end -}}

<div class="post-body e-content">
Expand Down