From 450a72a1ee434c758d9467190fc7b2607b2e59a0 Mon Sep 17 00:00:00 2001 From: Gianmarco Brocchi Date: Thu, 13 Jan 2022 15:39:21 +0100 Subject: Show categories next to tags in a post (#18) Add categories in post archetype Add categories in taxonomy of exampleSite --- archetypes/post.md | 1 + exampleSite/config.toml | 3 ++- layouts/partials/categories.html | 4 ++++ layouts/post/single.html | 4 ++-- 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 layouts/partials/categories.html diff --git a/archetypes/post.md b/archetypes/post.md index 67ec913..c9ca8e8 100644 --- a/archetypes/post.md +++ b/archetypes/post.md @@ -5,4 +5,5 @@ publishdate: {{ now.Format "2006-01-02" }} lastmod: {{ now.Format "2006-01-02" }} draft: true tags: [] +categories: [] --- diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 1795e21..9b7c494 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -5,6 +5,7 @@ theme = "minimal-bootstrap-hugo-theme" [taxonomies] tag = "tags" + category = "categories" [permalinks] post = "/:filename/" @@ -77,4 +78,4 @@ theme = "minimal-bootstrap-hugo-theme" tabWidth = 4 [markup.tableOfContents] endLevel = 6 - startLevel = 2 \ No newline at end of file + startLevel = 2 diff --git a/layouts/partials/categories.html b/layouts/partials/categories.html new file mode 100644 index 0000000..85ebf1d --- /dev/null +++ b/layouts/partials/categories.html @@ -0,0 +1,4 @@ +{{ range .Params.categories }} +{{ $href := print (absURL "categories/") (urlize .) }} +[{{ . }}] +{{ end }} diff --git a/layouts/post/single.html b/layouts/post/single.html index 9e34d6c..d59e499 100644 --- a/layouts/post/single.html +++ b/layouts/post/single.html @@ -7,8 +7,8 @@ {{ with .Site.Params.customDateFormat }}{{ $customDateFormat = . }}{{ end }} {{ .PublishDate.Format $customDateFormat }}{{ if gt .Lastmod .PublishDate }}, updated {{ .Lastmod.Format $customDateFormat }}{{ end }} - {{ partial "tags" . }} + {{ partial "tags" . }} {{ partial "categories" . }}

{{ .Content }} -{{- end -}} \ No newline at end of file +{{- end -}} -- cgit v1.2.3