From feb4c387174eb035abe10354f4dd626a5c399e90 Mon Sep 17 00:00:00 2001 From: Track3 Date: Mon, 24 Dec 2018 22:17:22 +0800 Subject: [PATCH] Add basic toc support --- archetypes/posts.md | 1 + assets/scss/style.scss | 50 +++++++++++++++++++ exampleSite/content/posts/goisforlovers.md | 1 + exampleSite/content/posts/hugoisforlovers.md | 1 + .../content/posts/migrate-from-jekyll.md | 1 + layouts/posts/single.html | 6 +++ 6 files changed, 60 insertions(+) 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 }} + {{- if .Params.toc }} + + {{- end }}
{{- with .NextInSection }}