diff --git a/README.md b/README.md index f57b78c..e142b30 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,10 @@ paginate = 5 # can be overridden in a page's front-matter # TocTitle = "Table of Contents" # default + # auto numbering the titles + # can be overridden in a page's front-matter + # autonumbering = false # default + [params.twitter] # set Twitter handles for Twitter cards diff --git a/assets/css/main.scss b/assets/css/main.scss index dac8283..fe3839a 100644 --- a/assets/css/main.scss +++ b/assets/css/main.scss @@ -32,6 +32,7 @@ body { .headings--one-size { h1, h2, + .toc-title, h3, h4, h5, @@ -45,6 +46,7 @@ body { h1, h2, + .toc-title, h3 { font-size: 1.4rem; } diff --git a/assets/css/post.scss b/assets/css/post.scss index 223139b..02d3e00 100644 --- a/assets/css/post.scss +++ b/assets/css/post.scss @@ -126,3 +126,17 @@ h1:hover a, h2:hover a, h3:hover a, h4:hover a { .footnotes { color: transparentize($color, .5); } + +/* Auto Numbering */ +// https://codingnconcepts.com/hugo/auto-number-headings-hugo/ +body {counter-reset: h2} +h2 {counter-reset: h3} +h3 {counter-reset: h4} +h4 {counter-reset: h5} + +article[autonumbering] h2:before {counter-increment: h2; content: counter(h2) " "} +article[autonumbering] h3:before {counter-increment: h3; content: counter(h2) "." counter(h3) " "} +article[autonumbering] h4:before {counter-increment: h4; content: counter(h2) "." counter(h3) "." counter(h4) " "} + +article[autonumbering] .table-of-contents ul { counter-reset: item } +article[autonumbering] .table-of-contents li a:before { content: counters(item, ".") " "; counter-increment: item } diff --git a/layouts/_default/single.html b/layouts/_default/single.html index f85fc5d..5063bae 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -1,5 +1,5 @@ {{ define "main" }} -
+

{{ .Title | markdownify }}

@@ -31,9 +31,9 @@ {{ if (.Params.Toc | default .Site.Params.Toc) }}
-

+
{{ (.Params.TocTitle | default .Site.Params.TocTitle) | default "Table of Contents" }} -

+
{{ .TableOfContents }} {{ end }}