From 7ff750ab0abde89244d6a4c0f56e33bff584a349 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 16 Feb 2023 17:07:01 +0800 Subject: [PATCH] :recycle: 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` --- 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 | 50 +++++++++++++++--------- 8 files changed, 52 insertions(+), 32 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 -}}