Add basic toc support

This commit is contained in:
Track3 2018-12-24 22:17:22 +08:00
parent 0abf3ea012
commit feb4c38717
6 changed files with 60 additions and 0 deletions

View file

@ -2,6 +2,7 @@
title: "{{ replace .Name "-" " " | title }}" title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }} date: {{ .Date }}
draft: true draft: true
toc: false
featuredImg: "" featuredImg: ""
tags: tags:
- tag - tag

View file

@ -587,6 +587,43 @@ hr.post-end {
} }
} }
#toc {
position: fixed;
left: 50%;
top: 0;
display: none;
}
.toc-title {
margin-left: 1em;
margin-bottom: .5em;
font-size: .8em;
font-weight: bold;
}
#TableOfContents {
font-size: .8em;
@include dimmed;
ul {
padding-left: 1em;
margin: 0;
}
&>ul {
list-style-type: none;
ul ul {
font-size: .9em;
}
}
a:hover {
border-bottom: $theme 1px solid;
}
}
.post-nav { .post-nav {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@ -662,6 +699,13 @@ hr.post-end {
hr.post-end { hr.post-end {
width: 30%; width: 30%;
} }
#toc {
top: 13em;
display: block;
margin-left: 370px;
max-width: 220px;
}
} }
@media (min-width: 1800px) { @media (min-width: 1800px) {
@ -695,6 +739,12 @@ hr.post-end {
hr.post-end { hr.post-end {
width: 30%; width: 30%;
} }
#toc {
top: 15em;
margin-left: 490px;
max-width: 300px;
}
} }
@media (max-width: 760px) { @media (max-width: 760px) {

View file

@ -8,6 +8,7 @@ tags = [
"development", "development",
] ]
date = "2014-04-02" date = "2014-04-02"
toc = true
+++ +++
Hugo uses the excellent [Go][] [html/template][gohtmltemplate] library for Hugo uses the excellent [Go][] [html/template][gohtmltemplate] library for

View file

@ -7,6 +7,7 @@ tags = [
"development", "development",
] ]
date = "2014-04-02" date = "2014-04-02"
toc = true
+++ +++
## Step 1. Install Hugo ## Step 1. Install Hugo

View file

@ -1,6 +1,7 @@
--- ---
date: 2014-03-10 date: 2014-03-10
title: Migrate to Hugo from Jekyll title: Migrate to Hugo from Jekyll
toc: true
--- ---
## Move static content to `static` ## Move static content to `static`

View file

@ -32,6 +32,12 @@
{{- end }} {{- end }}
</footer> </footer>
</article> </article>
{{- if .Params.toc }}
<aside id="toc">
<div class="toc-title">Table of Contents</div>
{{ .TableOfContents }}
</aside>
{{- end }}
<div class="post-nav thin"> <div class="post-nav thin">
{{- with .NextInSection }} {{- with .NextInSection }}
<a class="next-post" href="{{ .Permalink }}"> <a class="next-post" href="{{ .Permalink }}">