aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrack3 <pengliabc@live.cn>2018-12-24 22:17:22 +0800
committerTrack3 <pengliabc@live.cn>2018-12-24 22:17:22 +0800
commitfeb4c387174eb035abe10354f4dd626a5c399e90 (patch)
tree6120738f2efc44585027b2570302e8c2ae06febe
parent0abf3ea0125f3666c486c0da9edb4d238e510103 (diff)
downloadhermit-feb4c387174eb035abe10354f4dd626a5c399e90.tar.gz
Add basic toc support
-rw-r--r--archetypes/posts.md1
-rw-r--r--assets/scss/style.scss50
-rw-r--r--exampleSite/content/posts/goisforlovers.md1
-rw-r--r--exampleSite/content/posts/hugoisforlovers.md1
-rw-r--r--exampleSite/content/posts/migrate-from-jekyll.md1
-rw-r--r--layouts/posts/single.html6
6 files changed, 60 insertions, 0 deletions
diff --git a/archetypes/posts.md b/archetypes/posts.md
index aaa57c6..099f5bb 100644
--- a/archetypes/posts.md
+++ b/archetypes/posts.md
@@ -2,6 +2,7 @@
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
+toc: false
featuredImg: ""
tags:
- tag
diff --git a/assets/scss/style.scss b/assets/scss/style.scss
index 49a1dc1..7424f4d 100644
--- a/assets/scss/style.scss
+++ b/assets/scss/style.scss
@@ -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 {
display: flex;
justify-content: space-between;
@@ -662,6 +699,13 @@ hr.post-end {
hr.post-end {
width: 30%;
}
+
+ #toc {
+ top: 13em;
+ display: block;
+ margin-left: 370px;
+ max-width: 220px;
+ }
}
@media (min-width: 1800px) {
@@ -695,6 +739,12 @@ hr.post-end {
hr.post-end {
width: 30%;
}
+
+ #toc {
+ top: 15em;
+ margin-left: 490px;
+ max-width: 300px;
+ }
}
@media (max-width: 760px) {
diff --git a/exampleSite/content/posts/goisforlovers.md b/exampleSite/content/posts/goisforlovers.md
index 3381ac0..41079d5 100644
--- a/exampleSite/content/posts/goisforlovers.md
+++ b/exampleSite/content/posts/goisforlovers.md
@@ -8,6 +8,7 @@ tags = [
"development",
]
date = "2014-04-02"
+toc = true
+++
Hugo uses the excellent [Go][] [html/template][gohtmltemplate] library for
diff --git a/exampleSite/content/posts/hugoisforlovers.md b/exampleSite/content/posts/hugoisforlovers.md
index 3f76e82..747ab41 100644
--- a/exampleSite/content/posts/hugoisforlovers.md
+++ b/exampleSite/content/posts/hugoisforlovers.md
@@ -7,6 +7,7 @@ tags = [
"development",
]
date = "2014-04-02"
+toc = true
+++
## Step 1. Install Hugo
diff --git a/exampleSite/content/posts/migrate-from-jekyll.md b/exampleSite/content/posts/migrate-from-jekyll.md
index 78cf3b4..d5b2f54 100644
--- a/exampleSite/content/posts/migrate-from-jekyll.md
+++ b/exampleSite/content/posts/migrate-from-jekyll.md
@@ -1,6 +1,7 @@
---
date: 2014-03-10
title: Migrate to Hugo from Jekyll
+toc: true
---
## Move static content to `static`
diff --git a/layouts/posts/single.html b/layouts/posts/single.html
index e8b37a8..a8b5c55 100644
--- a/layouts/posts/single.html
+++ b/layouts/posts/single.html
@@ -32,6 +32,12 @@
{{- end }}
</footer>
</article>
+ {{- if .Params.toc }}
+ <aside id="toc">
+ <div class="toc-title">Table of Contents</div>
+ {{ .TableOfContents }}
+ </aside>
+ {{- end }}
<div class="post-nav thin">
{{- with .NextInSection }}
<a class="next-post" href="{{ .Permalink }}">