♻️ Refactor: author's avatar of post or profile (#288)

1. `params.profile.gravatarEmail` only takes effect when `params.gravatar.enable=true`
2. Adjust frontmatter: `author` data type from string to **map**
3. Remove frontmatter: `gravatarForce`, `authorLink`, `authorEmail`
4. Add frontmatter: `authorAvatar`
5. Add `params.gravatar.enable`
This commit is contained in:
Cell
2023-02-16 17:07:01 +08:00
committed by GitHub
parent 22149b2082
commit 7ff750ab0a
8 changed files with 52 additions and 32 deletions
+1
View File
@@ -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):
+5 -3
View File
@@ -3,9 +3,11 @@ title: "{{ replace .TranslationBaseName "-" " " | title }}"
subtitle: ""
date: {{ .Date }}
draft: true
author: ""
authorLink: ""
authorEmail: ""
author:
name: ""
link: ""
email: ""
avatar: ""
description: ""
keywords: ""
license: ""
+5 -3
View File
@@ -3,9 +3,11 @@ title: "{{ replace .TranslationBaseName "-" " " | title }}"
subtitle: ""
date: {{ .Date }}
draft: true
author: ""
authorLink: ""
authorEmail: ""
author:
name: ""
link: ""
email: ""
avatar: ""
description: ""
keywords: ""
license: ""
+4 -2
View File
@@ -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"]
+1 -1
Submodule docs updated: f09cc4510a...d96d65c6a3
+3 -2
View File
@@ -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 }}
+2 -2
View File
@@ -1,8 +1,8 @@
{{- $profile := .Site.Params.home.profile -}}
<div class="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")
+31 -19
View File
@@ -1,28 +1,40 @@
{{- $params := .Scratch.Get "params" -}}
{{- $authorDefault := dict "name" "Anonymous" "link" "" "email" "" "avatar" "" -}}
{{- $author := .Site.Author | merge $authorDefault -}}
{{- $authorPost := dict -}}
{{- $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 $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 $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 $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")
(md5 $author.email)
(.Style | default ""))
| merge $author
-}}
{{- end -}}
{{- end -}}
{{- end -}}
<span class="post-author">
{{- $content := $author.name -}}
{{- $icon := dict "Class" "fa-solid fa-user-circle" -}}
{{- if $avatar -}}
{{- $content = printf "%v&nbsp;%v" (dict "Src" $avatar "Class" "avatar" "Alt" $author.name | partial "plugin/image.html") $author.name -}}
{{- if $author.avatar | and $params.authorAvatar -}}
{{- $content = printf "%v&nbsp;%v" (dict "Src" $author.avatar "Class" "avatar" "Alt" $author.name | partial "plugin/image.html") $author.name -}}
{{- $icon = "" -}}
{{- end -}}
{{- if $author.link -}}
@@ -31,7 +43,7 @@
{{- else -}}
<span class="author">
{{- with $icon -}}
{{ . | partial "plugin/icon.html" }}
{{- . | partial "plugin/icon.html" }}
{{ end -}}
{{- $content | safeHTML -}}
</span>