Skip to content

Commit

Permalink
feat: new param tocNum
Browse files Browse the repository at this point in the history
close #71
  • Loading branch information
reuixiy committed Feb 27, 2020
1 parent f8ba8aa commit f30d684
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ aliases | * | array
markup | * | string
meta | set `false` to disable post-meta | boolean, MemE only
toc | display TOC | boolean, override `enableTOC` in `config.toml`, MemE only
tocNum | display TOC number | boolean, override `displayTOCNum` in `config.toml`, MemE only
displayCopyright | display post-copyright | boolean, override `displayPostCopyright` in `config.toml`, MemE only
badge | display updated-badge | boolean, override `displayUpdatedBadge` in `config.toml`, MemE only
gitinfo | display post-gitinfo | boolean, override `displayPostGitInfo` in `config.toml`, MemE only
Expand Down
1 change: 1 addition & 0 deletions README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ aliases | * | array
markup | * | string
meta | set `false` to disable post-meta | boolean, MemE only
toc | display TOC | boolean, override `enableTOC` in `config.toml`, MemE only
tocNum | display TOC number | boolean, override `displayTOCNum` in `config.toml`, MemE only
displayCopyright | display post-copyright | boolean, override `displayPostCopyright` in `config.toml`, MemE only
badge | display updated-badge | boolean, override `displayUpdatedBadge` in `config.toml`, MemE only
gitinfo | display post-gitinfo | boolean, override `displayPostGitInfo` in `config.toml`, MemE only
Expand Down
19 changes: 19 additions & 0 deletions assets/scss/base/_data-attributes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,22 @@
margin: 0 auto;
}
}

[data-toc-num="true"] {
.contents {
ol {
counter-reset: item;
li {
&::before {
counter-increment: item;
content: counters(item, ".") ". ";
}
}
}
}
.toc li > ol > li {
&::before {
content: counters(item, ".") " ";
}
}
}
5 changes: 0 additions & 5 deletions assets/scss/layout/_single.scss
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ blockquote {
margin-top: 5em;
ol {
list-style: none;
counter-reset: item;
li::before {
content: counters(item, ".") ". ";
counter-increment: item;
}
}
}
ol.toc {
Expand Down
5 changes: 5 additions & 0 deletions config-examples/en-us/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,11 @@ uglyURLs = false

displayTOCTitle = true

displayTOCNum = true
# Note: *global settings*
# `tocNum` in post’s Front Matter
# has a higher priority than here

linkHeadingsToTOC = true


Expand Down
5 changes: 5 additions & 0 deletions config-examples/zh-cn/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,11 @@ uglyURLs = false
# 是否显示目录标题
displayTOCTitle = true

# 是否显示数字(全局设置)
displayTOCNum = true
# 说明:文章的 Front Matter 中的 `tocNum`
# 的优先级高于此处

# 是否链接文章的分节标题到目录
linkHeadingsToTOC = true

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Target":"css/meme.min.7982f1989691146b99a6c1745ad729b6cfed3f629ac37a85b1f17bcc08278114.css","MediaType":"text/css","Data":{"Integrity":"sha256-eYLxmJaRFGuZpsF0Wtcpts/tP2Kaw3qFsfF7zAgngRQ="}}
{"Target":"css/meme.min.6e4c0a998beaeedae611e936f3ff1b373c5b1f6f66765fbcb5a98f2f7d251e08.css","MediaType":"text/css","Data":{"Integrity":"sha256-bkwKmYvq7trmEek28/8bNzxbH29mdl+8tamPL30lHgg="}}
11 changes: 9 additions & 2 deletions layouts/partials/pages/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
{{- $type := .Scratch.Get "type" -}}
{{- $layout := .Scratch.Get "layout" -}}
{{- $indent := .Scratch.Get "indent" -}}
{{- $tocNum := .Scratch.Get "tocNum" -}}

<article class="content post"{{ if $smallCaps }} data-small-caps="true"{{ end }}{{ with $align }} data-align="{{ . }}"{{ end }}{{ with $type }} data-type="{{ . }}"{{ end }}{{ with $layout }} data-layout="{{ . }}"{{ end }}{{ if $indent }} data-indent="true"{{ end }}>
<article class="content post"
{{- if $smallCaps }} data-small-caps="true"{{ end }}
{{- with $align }} data-align="{{ . }}"{{ end }}
{{- with $type }} data-type="{{ . }}"{{ end }}
{{- with $layout }} data-layout="{{ . }}"{{ end }}
{{- if $indent }} data-indent="true"{{ end }}
{{- if $tocNum }} data-toc-num="true"{{ end }}>

<h1 class="post-title">{{ .Title }}</h1>

Expand Down Expand Up @@ -73,4 +80,4 @@ <h1 class="post-title">{{ .Title }}</h1>
{{ partial "components/comments.html" . }}

</div>
</main>
</main>
6 changes: 6 additions & 0 deletions layouts/partials/utils/data-attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@
{{- .Scratch.Set "indent" true -}}
{{- end -}}
{{- end -}}

<!-- TOC Number -->
{{- .Scratch.Delete "tocNum" -}}
{{- with .Params.tocNum | default .Site.Params.displayTOCNum -}}
{{- $.Scratch.Set "tocNum" . -}}
{{- end -}}

0 comments on commit f30d684

Please sign in to comment.