From c4bc9b1b2016b4a6c412b6e986982e198b4c8b9f Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 16 Feb 2023 12:16:06 +0800 Subject: [PATCH 1/2] backup --- layouts/partials/single/post-author.html | 45 ++++++++++++++---------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/layouts/partials/single/post-author.html b/layouts/partials/single/post-author.html index 812ad43e7..8869fcc5a 100644 --- a/layouts/partials/single/post-author.html +++ b/layouts/partials/single/post-author.html @@ -1,28 +1,35 @@ {{- $params := .Scratch.Get "params" -}} +{{- $author := .Site.Author | merge (dict "name" "Anonymous" "link" "" "email" "" "avatar" "") -}} +{{- $gravatar := .Site.Params.gravatar -}} -{{- $author := .Site.Author | merge (dict "name" "Anonymous" "link" (echoParam $params "authorlink") "email" (echoParam $params "authoremail")) -}} -{{- $avatar := .Site.Params.home.profile.avatarURL -}} -{{- if isset $params "author" | and (ne $params.author .Site.Author.name) -}} - {{- $author = dict "name" $params.author | merge $author -}} - {{- $author = dict "link" (echoParam $params "authorlink") | merge $author -}} - {{- $author = dict "email" (echoParam $params "authoremail") | merge $author -}} - {{- $avatar = "" -}} -{{- end -}} -{{- if (not $avatar | or $params.gravatarForce) | and $author.email -}} - {{- $gravatar := .Site.Params.gravatar -}} - {{- with $gravatar -}} - {{- $avatar = printf "https://%v/avatar/%v?s=32&d=%v" - (path.Clean .Host | default "www.gravatar.com") - (md5 $author.email) - (.Style | default "") - -}} +{{- if $gravatar.enable -}} + {{- if isset $params "author" | and (ne $params.author .Site.Author.name) -}} + {{- $author = dict "name" $params.author | merge $author -}} + {{- $author = dict "link" (echoParam $params "authorlink") | merge $author -}} + {{- $author = dict "email" (echoParam $params "authoremail") | merge $author -}} + {{- $author = dict "avatar" (echoParam $params "authoravatar") | merge $author -}} + {{- else -}} + {{- with $params.authorlink -}}{{- $author = dict "link" . | merge $author -}}{{- end -}} + {{- with $params.authoremail -}}{{- $author = dict "email" . | merge $author -}}{{- end -}} + {{- with $params.authoravatar -}}{{- $author = dict "avatar" . | merge $author -}}{{- end -}} + {{- end -}} + {{- if $author.email -}} + {{- with $gravatar -}} + {{- $author = dict "avatar" (printf "https://%v/avatar/%v?s=32&d=%v" + (path.Clean .Host | default "www.gravatar.com") + (md5 $author.email) + (.Style | default "")) + | merge $author + -}} + {{- end -}} {{- end -}} {{- end -}} + {{- $content := $author.name -}} {{- $icon := dict "Class" "fa-solid fa-user-circle" -}} - {{- if $avatar -}} - {{- $content = printf "%v %v" (dict "Src" $avatar "Class" "avatar" "Alt" $author.name | partial "plugin/image.html") $author.name -}} + {{- if $author.avatar -}} + {{- $content = printf "%v %v" (dict "Src" $author.avatar "Class" "avatar" "Alt" $author.name | partial "plugin/image.html") $author.name -}} {{- $icon = "" -}} {{- end -}} {{- if $author.link -}} @@ -31,7 +38,7 @@ {{- else -}} {{- with $icon -}} - {{ . | partial "plugin/icon.html" }} + {{- . | partial "plugin/icon.html" }} {{ end -}} {{- $content | safeHTML -}} From 4424155f8b921a7738c4561ff58641109bc011a6 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 16 Feb 2023 16:30:45 +0800 Subject: [PATCH 2/2] :recycle: Refactor: author's avatar of post or profile (#261) --- CHANGELOG.md | 1 + archetypes/post-bundle/index.md | 8 ++++--- archetypes/posts.md | 8 ++++--- config.toml | 6 +++-- docs | 2 +- layouts/partials/head/seo.html | 5 ++-- layouts/partials/home/profile.html | 4 ++-- layouts/partials/single/post-author.html | 29 ++++++++++++++---------- 8 files changed, 38 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 236332e4f..df167324e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file. - :bug: Fix: donate images without lazy loading (@Mejituu [#279](https://github.com/hugo-fixit/FixIt/pull/279)) - :bug: Fix: discordinvite typo (@mathieu-gilloots [#282](https://github.com/hugo-fixit/FixIt/pull/282)) - :recycle: Refactor: image lazy loading ([#283](https://github.com/hugo-fixit/FixIt/pull/283)) +- :recycle: Refactor: author's avatar of post or profile ([#261](https://github.com/hugo-fixit/FixIt/discussions/261)) - :art: Style: fix `#comments` css style conflict ([#269](https://github.com/hugo-fixit/FixIt/issues/269)) - :wrench: Chore: change the theme minimum supported Hugo versions above **0.89.0** - :arrow_up: Chore(libs): diff --git a/archetypes/post-bundle/index.md b/archetypes/post-bundle/index.md index ba796567b..43c9aff02 100644 --- a/archetypes/post-bundle/index.md +++ b/archetypes/post-bundle/index.md @@ -3,9 +3,11 @@ title: "{{ replace .TranslationBaseName "-" " " | title }}" subtitle: "" date: {{ .Date }} draft: true -author: "" -authorLink: "" -authorEmail: "" +author: + name: "" + link: "" + email: "" + avatar: "" description: "" keywords: "" license: "" diff --git a/archetypes/posts.md b/archetypes/posts.md index 27ca981ad..c307d1afd 100644 --- a/archetypes/posts.md +++ b/archetypes/posts.md @@ -3,9 +3,11 @@ title: "{{ replace .TranslationBaseName "-" " " | title }}" subtitle: "" date: {{ .Date }} draft: true -author: "" -authorLink: "" -authorEmail: "" +author: + name: "" + link: "" + email: "" + avatar: "" description: "" keywords: "" license: "" diff --git a/config.toml b/config.toml index bbea0e166..f59f45799 100644 --- a/config.toml +++ b/config.toml @@ -347,6 +347,8 @@ # FixIt 0.2.0 | CHANGED Page config [params.page] + # FixIt 0.2.18 | NEW whether to enable the author's avatar of the post + authorAvatar = true # FixIt 0.2.0 | NEW whether to hide a page from home page hiddenFromHomePage = false # FixIt 0.2.0 | NEW whether to hide a page from search results @@ -370,8 +372,6 @@ rssFullText = false # FixIt 0.2.13 | NEW Page style ["narrow", "normal", "wide", ...] pageStyle = "normal" - # FixIt 0.2.14 | NEW Gravatar is force-used as the author's avatar - gravatarForce = false # FixIt 0.2.17 | CHANGED Auto Bookmark Support # If true, save the reading progress when closing the page. autoBookmark = false @@ -755,6 +755,8 @@ # FixIt 0.2.14 | NEW Gravatar config [params.gravatar] + # FixIt 0.2.18 | NEW Depends on the author's email, if the author's email is not set, the local avatar will be used + enable = false # Gravatar host, default: "www.gravatar.com" host = "www.gravatar.com" # ["cn.gravatar.com", "gravatar.loli.net", ...] style = "" # ["", "mp", "identicon", "monsterid", "wavatar", "retro", "blank", "robohash"] diff --git a/docs b/docs index f09cc4510..d96d65c6a 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit f09cc4510a8b154de47bc844a9fa1c0ddc710b75 +Subproject commit d96d65c6a339ed5920eccff15b4821a1b3a75ddf diff --git a/layouts/partials/head/seo.html b/layouts/partials/head/seo.html index 697bdf032..ade1f46d1 100644 --- a/layouts/partials/head/seo.html +++ b/layouts/partials/head/seo.html @@ -128,7 +128,8 @@ {{- with .Site.Copyright -}} "license": {{ . | safeHTML }}, {{- end -}} - {{- $publisher := .Params.author | default .Site.Author.name | default (T "single.author") | dict "name" -}} + {{- $postAuthor := cond (reflect.IsMap .Params.author) .Params.author.name .Params.author -}} + {{- $publisher := $postAuthor | default .Site.Author.name | default (T "single.author") | dict "name" -}} {{- $publisher = $params.seo.publisher | default dict | merge $publisher -}} "publisher": { "@type": "Organization", @@ -147,7 +148,7 @@ {{- end -}} {{- end -}} }, - {{- with .Params.author | default .Site.Author.name | default (T "single.author") -}} + {{- with $postAuthor | default .Site.Author.name | default (T "single.author") -}} "author": { "@type": "Person", "name": {{ . | safeHTML }} diff --git a/layouts/partials/home/profile.html b/layouts/partials/home/profile.html index 3a1b6851d..1941b5762 100644 --- a/layouts/partials/home/profile.html +++ b/layouts/partials/home/profile.html @@ -1,8 +1,8 @@ {{- $profile := .Site.Params.home.profile -}}
{{- $avatar := $profile.avatarURL -}} - {{- if $profile.gravatarEmail -}} - {{- $gravatar := .Site.Params.gravatar -}} + {{- $gravatar := .Site.Params.gravatar -}} + {{- if $gravatar.enable | and $profile.gravatarEmail -}} {{- with $gravatar -}} {{- $avatar = printf "https://%v/avatar/%v?s=240&d=%v" (path.Clean .Host | default "www.gravatar.com") diff --git a/layouts/partials/single/post-author.html b/layouts/partials/single/post-author.html index 8869fcc5a..8e42bcdff 100644 --- a/layouts/partials/single/post-author.html +++ b/layouts/partials/single/post-author.html @@ -1,19 +1,24 @@ {{- $params := .Scratch.Get "params" -}} -{{- $author := .Site.Author | merge (dict "name" "Anonymous" "link" "" "email" "" "avatar" "") -}} +{{- $authorDefault := dict "name" "Anonymous" "link" "" "email" "" "avatar" "" -}} +{{- $author := .Site.Author | merge $authorDefault -}} +{{- $authorPost := dict -}} {{- $gravatar := .Site.Params.gravatar -}} -{{- if $gravatar.enable -}} - {{- if isset $params "author" | and (ne $params.author .Site.Author.name) -}} - {{- $author = dict "name" $params.author | merge $author -}} - {{- $author = dict "link" (echoParam $params "authorlink") | merge $author -}} - {{- $author = dict "email" (echoParam $params "authoremail") | merge $author -}} - {{- $author = dict "avatar" (echoParam $params "authoravatar") | merge $author -}} +{{- if $params.authorAvatar -}} + {{- if reflect.IsMap $params.author -}} + {{- $authorPost = $params.author -}} + {{- else if isset $params "author" -}} + {{- $authorPost = dict "name" $params.author -}} + {{- end -}} + {{- if isset $authorPost "name" | and (ne $authorPost.name .Site.Author.name) -}} + {{- $author = $authorPost | merge $authorDefault | merge $author -}} {{- else -}} - {{- with $params.authorlink -}}{{- $author = dict "link" . | merge $author -}}{{- end -}} - {{- with $params.authoremail -}}{{- $author = dict "email" . | merge $author -}}{{- end -}} - {{- with $params.authoravatar -}}{{- $author = dict "avatar" . | merge $author -}}{{- end -}} + {{- with $authorPost.link -}}{{- $author = dict "link" . | merge $author -}}{{- end -}} + {{- with $authorPost.email -}}{{- $author = dict "email" . | merge $author -}}{{- end -}} + {{- with $authorPost.avatar -}}{{- $author = dict "avatar" . | merge $author -}}{{- end -}} {{- end -}} - {{- if $author.email -}} + + {{- if $gravatar.enable | and $author.email -}} {{- with $gravatar -}} {{- $author = dict "avatar" (printf "https://%v/avatar/%v?s=32&d=%v" (path.Clean .Host | default "www.gravatar.com") @@ -28,7 +33,7 @@