From f642c74351a5cc977e029032446218171d0b33e5 Mon Sep 17 00:00:00 2001 From: Pavel Danov Date: Fri, 14 Apr 2023 13:44:33 +0100 Subject: [PATCH 1/2] Add simple table of contents generation --- README.md | 4 ++++ assets/css/main.scss | 5 +++++ config.toml | 4 ++++ layouts/_default/single.html | 6 ++++++ layouts/posts/single.html | 8 +++++++- 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bb5b729..10f7a85 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,10 @@ The `index.md` page should use layout `home`, which is the layout that displays Another thing you can do to customize the index page is show the description of your blog between the title and the menu. To do this, just edit `config.toml` and change `params.theme_config.show_description` to `true`. +### Adding table of contents + +You can add a table of contents by supplying the `toc: true` param to your post front matter. If you want a border around it you can also set `tocBorder: true`. The toc style behavior is handled by Goldmark and the defaults can be found in the `config.toml` file. + ### Pro tips #### Dark mode for images diff --git a/assets/css/main.scss b/assets/css/main.scss index 47502b9..c8315c7 100644 --- a/assets/css/main.scss +++ b/assets/css/main.scss @@ -51,6 +51,11 @@ li { margin: 0.4rem 0; } padding: 4rem 2rem; } +.toc { + border: thin solid black; + padding: 1rem; +} + hr { text-align: center; border: 0; diff --git a/config.toml b/config.toml index b0b53d0..95ad262 100644 --- a/config.toml +++ b/config.toml @@ -23,6 +23,10 @@ noHl = false style = 'rrt' tabWidth = 4 + [markup.tableOfContents] + startLevel = 2 + endLevel = 3 + ordered = false [params] [params.theme_config] diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 2cbaff8..431d435 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -10,6 +10,12 @@

{{ .Title }}

+ {{if .Params.toc }} + + {{ end }} + {{ .Content }} {{ end }} diff --git a/layouts/posts/single.html b/layouts/posts/single.html index 9a5c5d1..431d435 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -10,6 +10,12 @@

{{ .Title }}

+ {{if .Params.toc }} + + {{ end }} + {{ .Content }} -{{ end }} \ No newline at end of file +{{ end }} From a37ed682a1abf0137fa7f399ead7c7b1ff9ef8ff Mon Sep 17 00:00:00 2001 From: Pavel Danov Date: Fri, 14 Apr 2023 13:45:44 +0100 Subject: [PATCH 2/2] Fix spacing --- layouts/_default/single.html | 2 +- layouts/posts/single.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 431d435..a09cee2 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -10,7 +10,7 @@

{{ .Title }}

- {{if .Params.toc }} + {{ if .Params.toc }} diff --git a/layouts/posts/single.html b/layouts/posts/single.html index 431d435..a09cee2 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -10,7 +10,7 @@

{{ .Title }}

- {{if .Params.toc }} + {{ if .Params.toc }}