From 21ec731106f5d66bfde2eb08fd43aed600ff3961 Mon Sep 17 00:00:00 2001 From: Tomo Wang Date: Tue, 27 Aug 2024 23:48:31 +0800 Subject: [PATCH] feat: add author display and show author configuration. close #54 --- README.md | 1 + assets/icons/user.svg | 7 +++++++ config/_default/params.toml | 2 ++ exampleSite/config/_default/params.toml | 2 ++ .../content/post/image-process/index.md | 2 +- .../content/post/image-process/index.zh-cn.md | 2 +- layouts/_default/list.html | 1 + layouts/_default/single.html | 1 + layouts/partials/block/author.html | 21 +++++++++++++++++++ 9 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 assets/icons/user.svg create mode 100644 layouts/partials/block/author.html diff --git a/README.md b/README.md index 40a271e..5be0dcd 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ Some of the configuration options are: * `params.social_media`: social media links shown in the footer * `params.search`: search settings * `params.author`: author used in the JSON-LD + * `params.showAuthor`: show author name in article list and article page * `params.jsonLD`: enable or disable JSON-LD (default disabled) * `params.pwa`: enable or disable PWA (default disabled) diff --git a/assets/icons/user.svg b/assets/icons/user.svg new file mode 100644 index 0000000..97d5d73 --- /dev/null +++ b/assets/icons/user.svg @@ -0,0 +1,7 @@ + + + + + diff --git a/config/_default/params.toml b/config/_default/params.toml index 03d1f5a..7c9b866 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -15,6 +15,8 @@ showReadingTime = true # use structure json-ld for articles jsonLD = false +showAuthor = false + [author] name = "Hugo Author" email = "user@example.com" diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index da33714..761a892 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -8,6 +8,8 @@ contentTypeName = "post" jsonLD = true +showAuthor = true + [author] name = "Xiaoliang Wang" email = "user@example.com" diff --git a/exampleSite/content/post/image-process/index.md b/exampleSite/content/post/image-process/index.md index 13685ea..97890dc 100644 --- a/exampleSite/content/post/image-process/index.md +++ b/exampleSite/content/post/image-process/index.md @@ -1,5 +1,5 @@ +++ -author = "Hugo Authors" +# author = "Hugo Authors" title = "Image Process" date = "2023-12-01" description = "Demo of Hugo's image processing" diff --git a/exampleSite/content/post/image-process/index.zh-cn.md b/exampleSite/content/post/image-process/index.zh-cn.md index 9e0b5f7..b879de2 100644 --- a/exampleSite/content/post/image-process/index.zh-cn.md +++ b/exampleSite/content/post/image-process/index.zh-cn.md @@ -1,5 +1,5 @@ +++ -author = "Hugo Authors" +# author = "Hugo Authors" title = "图片处理" date = "2023-12-01" description = "关于Hugo中图片处理的示例" diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 4ef02b9..7e0e10d 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -32,6 +32,7 @@

{{ partial "block/taxonomies.html" .}} {{ partial "block/time.html" . }} + {{ partial "block/author.html" . }} {{ end }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 7638a92..dbc4f15 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -23,6 +23,7 @@

{{ partial "block/taxonomies.html" .}} {{ partial "block/time.html" . }} + {{ partial "block/author.html" . }} {{ if or .Params.Toc $.Site.Params.Toc }} {{ if ne .Params.Toc false }} diff --git a/layouts/partials/block/author.html b/layouts/partials/block/author.html new file mode 100644 index 0000000..ad8b8d4 --- /dev/null +++ b/layouts/partials/block/author.html @@ -0,0 +1,21 @@ +{{- if .Site.Params.showAuthor -}} +{{- $author := "" -}} + +{{- if .Params.author -}} + {{- $author = .Params.author -}} +{{- else if and .Site.Params.Author .Site.Params.Author.name -}} + {{- $author = .Site.Params.Author.name -}} +{{- end -}} + +{{- if $author -}} +
+
+ + {{ partial "icon.html" "user" }} + + {{ $author }} +
+
+{{- end -}} + +{{- end -}}