Merge pull request #10 from underscoreHao/feature/toc

feat(style): add table of contents
This commit is contained in:
Hanwen Guo 2023-04-29 14:40:57 +08:00 committed by GitHub
commit 1f0773883f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 1 deletions

View File

@ -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`. 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 ### Pro tips
#### Dark mode for images #### Dark mode for images

View File

@ -51,6 +51,11 @@ li { margin: 0.4rem 0; }
padding: 4rem 2rem; padding: 4rem 2rem;
} }
.toc {
border: thin solid black;
padding: 1rem;
}
hr { hr {
text-align: center; text-align: center;
border: 0; border: 0;

View File

@ -23,6 +23,10 @@
noHl = false noHl = false
style = 'rrt' style = 'rrt'
tabWidth = 4 tabWidth = 4
[markup.tableOfContents]
startLevel = 2
endLevel = 3
ordered = false
[params] [params]
[params.theme_config] [params.theme_config]

View File

@ -10,6 +10,12 @@
<h1>{{ .Title }}</h1> <h1>{{ .Title }}</h1>
{{ if .Params.toc }}
<aside {{ if .Params.tocBorder }} class="toc" {{ end }}>
{{ .TableOfContents }}
</aside>
{{ end }}
{{ .Content }} {{ .Content }}
</article> </article>
{{ end }} {{ end }}

View File

@ -10,6 +10,12 @@
<h1>{{ .Title }}</h1> <h1>{{ .Title }}</h1>
{{ if .Params.toc }}
<aside {{ if .Params.tocBorder }} class="toc" {{ end }}>
{{ .TableOfContents }}
</aside>
{{ end }}
{{ .Content }} {{ .Content }}
</article> </article>
{{ end }} {{ end }}