From 3f296625fb66c3923858f958fb8ac387e20c65fb Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Wed, 1 Sep 2021 10:18:00 +0200 Subject: [PATCH] feat: add tags to post pages (#193) --- exampleSite/config.yaml | 4 ++ exampleSite/content/posts/hello_geekdoc.md | 2 + exampleSite/content/usage/configuration.md | 12 ++++ exampleSite/content/usage/getting-started.md | 3 + layouts/_default/list.html | 1 + layouts/partials/menu.html | 16 +++++ layouts/posts/list.html | 58 ++++++++++++++---- layouts/posts/single.html | 27 ++++++--- layouts/taxonomy/list.html | 62 ++++++++++++++++++++ layouts/taxonomy/taxonomy.html | 0 src/icons/timer.svg | 5 ++ src/sass/_base.scss | 38 +++++++++--- src/sass/_utils.scss | 4 ++ 13 files changed, 203 insertions(+), 29 deletions(-) delete mode 100644 layouts/taxonomy/taxonomy.html create mode 100644 src/icons/timer.svg diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index ace3ab1..ba93833 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -20,9 +20,13 @@ markup: startLevel: 1 endLevel: 9 +taxonomies: + tag: tags + params: # geekdocMenuBundle: true geekdocToC: 3 + geekdocTagsToMenu: true geekdocRepo: https://github.com/thegeeklab/hugo-geekdoc geekdocEditPath: edit/main/exampleSite/content diff --git a/exampleSite/content/posts/hello_geekdoc.md b/exampleSite/content/posts/hello_geekdoc.md index 8e389f3..fe025ed 100644 --- a/exampleSite/content/posts/hello_geekdoc.md +++ b/exampleSite/content/posts/hello_geekdoc.md @@ -2,6 +2,8 @@ title: Hello Geekdoc type: posts date: 2020-01-06 +tags: + - Documentation --- This is the first release of the Geekdoc theme. diff --git a/exampleSite/content/usage/configuration.md b/exampleSite/content/usage/configuration.md index 1258cce..4be4046 100644 --- a/exampleSite/content/usage/configuration.md +++ b/exampleSite/content/usage/configuration.md @@ -29,6 +29,9 @@ enableGitInfo = true startLevel = 1 endLevel = 9 +[taxonomies] + tag = "tags" + [params] # (Optional, default 6) Set how many table of contents levels to be showed on page. # Use false to hide ToC, note that 0 will default to 6 (https://gohugo.io/functions/default/) @@ -97,6 +100,9 @@ enableGitInfo = true # (Optional, default true) Display a "Back to top" link in the site footer. geekdocBackToTop = true + + # (Optional, default false) Enable or disable adding tags for post pages automatically to the navigation sidebar. + geekdocTagsToMenu = true ``` {{< /tab >}} @@ -123,6 +129,9 @@ markup: startLevel: 1 endLevel: 9 +taxonomies: + tag: tags + params: # (Optional, default 6) Set how many table of contents levels to be showed on page. # Use false to hide ToC, note that 0 will default to 6 (https://gohugo.io/functions/default/) @@ -196,6 +205,9 @@ params: # (Optional, default true) Display a "Back to top" link in the site footer. geekdocBackToTop: true + + # (Optional, default false) Enable or disable adding tags for post pages automatically to the navigation sidebar. + geekdocTagsToMenu: true ``` {{< /tab >}} diff --git a/exampleSite/content/usage/getting-started.md b/exampleSite/content/usage/getting-started.md index 433ca0e..3e5d9e6 100644 --- a/exampleSite/content/usage/getting-started.md +++ b/exampleSite/content/usage/getting-started.md @@ -63,6 +63,9 @@ To prepare your new site environment just a few steps are required: [markup.tableOfContents] startLevel = 1 endLevel = 9 + + [taxonomies] + tag = "tags" ``` 5. Test your site. diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 95c7d7b..c27218b 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,5 +1,6 @@ {{ define "main" }} {{ partial "page-header" . }} +

{{ partial "title" . }}

{{ partial "content" . }} diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html index ce21dbc..62b8b97 100644 --- a/layouts/partials/menu.html +++ b/layouts/partials/menu.html @@ -10,6 +10,22 @@ {{ end }} + {{ if and (in (slice "posts" "tags") .Section) (default false .Site.Params.GeekdocTagsToMenu) }} +
+

Tags

+
    + {{ $currentPage := .RelPermalink }} + {{ range $name, $taxonomy := .Site.Taxonomies.tags }} + {{ with $.Site.GetPage (printf "/tags/%s" $name) }} +
  • + {{ .Title }} +
  • + {{ end }} + {{ end }} +
+
+ {{ end }} +
{{ if .Site.Data.menu.more.more }}

More

diff --git a/layouts/posts/list.html b/layouts/posts/list.html index 0198293..5054bc1 100644 --- a/layouts/posts/list.html +++ b/layouts/posts/list.html @@ -3,24 +3,60 @@

{{ .Title }}

-
{{ .Summary }}
- {{ if .Truncated }}
+ {{ if .Truncated }} Read full post + {{ end }}
- {{ end }} + +
+ + + + + + + + + + + {{ $tc := 0 }} + {{ with .Params.tags }} + {{ range sort . }} + {{ $name := . }} + {{ with $.Site.GetPage (printf "/tags/%s" $name | urlize) }} + {{ if eq $tc 0 }} + + + {{ template "post-tag" dict "name" $name "page" . }} + + {{ else }} + {{ template "post-tag" dict "name" $name "page" . }} + {{ end }} + {{ end }} + {{ $tc = (add $tc 1) }} + {{ end }} + {{ end }} +
{{ end }} {{ end }} + +{{ define "post-tag" }} + +{{ end }} diff --git a/layouts/posts/single.html b/layouts/posts/single.html index 9465e3f..6961586 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -2,15 +2,24 @@

{{ .Title }}

- +
{{ partial "content" . }} diff --git a/layouts/taxonomy/list.html b/layouts/taxonomy/list.html index e69de29..5054bc1 100644 --- a/layouts/taxonomy/list.html +++ b/layouts/taxonomy/list.html @@ -0,0 +1,62 @@ +{{ define "main" }} + {{ range .Paginator.Pages }} +
+
+

{{ .Title }}

+
+
+ {{ .Summary }} +
+
+ {{ if .Truncated }} + Read full post + {{ end }} +
+ +
+ + + + + + + + + + + {{ $tc := 0 }} + {{ with .Params.tags }} + {{ range sort . }} + {{ $name := . }} + {{ with $.Site.GetPage (printf "/tags/%s" $name | urlize) }} + {{ if eq $tc 0 }} + + + {{ template "post-tag" dict "name" $name "page" . }} + + {{ else }} + {{ template "post-tag" dict "name" $name "page" . }} + {{ end }} + {{ end }} + {{ $tc = (add $tc 1) }} + {{ end }} + {{ end }} +
+
+ {{ end }} +{{ end }} + +{{ define "post-tag" }} + +{{ end }} diff --git a/layouts/taxonomy/taxonomy.html b/layouts/taxonomy/taxonomy.html deleted file mode 100644 index e69de29..0000000 diff --git a/src/icons/timer.svg b/src/icons/timer.svg new file mode 100644 index 0000000..d2da6e5 --- /dev/null +++ b/src/icons/timer.svg @@ -0,0 +1,5 @@ + + +timer + + diff --git a/src/sass/_base.scss b/src/sass/_base.scss index babada4..8a154ea 100644 --- a/src/sass/_base.scss +++ b/src/sass/_base.scss @@ -278,7 +278,7 @@ img { cursor: pointer; .icon { - font-size: 0.7rem; + font-size: $font-size-12; } } @@ -311,6 +311,7 @@ img { font-weight: bold; } + &--tags, &--more { padding-top: $padding-8; } @@ -437,14 +438,6 @@ img { } } - &__date { - margin: 1em 0; - - .icon { - font-size: 1.2em; - } - } - &:first-child { border-top: 0; @@ -468,6 +461,33 @@ img { text-decoration: none !important; } } + + &__tag { + margin: $padding-4 0 !important; + + .gdoc-button { + background: var(--body-background); + + &__link { + padding: $padding-4 $padding-8; + } + } + } + + &__meta { + padding-bottom: $padding-16; + } + + &__footer, + &__meta { + :not(:first-child).no-wrap { + margin-left: $padding-8; + } + + .icon { + font-size: $font-size-20; + } + } } .gdoc-footer { diff --git a/src/sass/_utils.scss b/src/sass/_utils.scss index d400f79..e04a716 100644 --- a/src/sass/_utils.scss +++ b/src/sass/_utils.scss @@ -57,6 +57,10 @@ text-align: center; } +.no-wrap { + white-space: nowrap; +} + .hidden { display: none; }