From e0bbd7f7b8a5743c4ce9337a761a9d93eb72ba84 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Wed, 27 Apr 2022 18:04:00 +0800 Subject: [PATCH] :sparkles: Feat: add local avatar and gravatar support for post author (#125) --- CHANGELOG.md | 1 + assets/css/_page/_single.scss | 15 ++++++++ exampleSite/config.toml | 10 +++++- .../theme-documentation-basics/index.en.md | 4 ++- .../theme-documentation-basics/index.zh-cn.md | 4 ++- layouts/_default/summary.html | 7 +--- layouts/partials/single/post-author.html | 35 +++++++++++++++++++ layouts/posts/single.html | 7 +--- 8 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 layouts/partials/single/post-author.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 43c6fb6c..1894533f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. - Add download icon for downloadable links - :sparkles: Feat: link shortcode add `external-icon` option ([#96](https://github.com/Lruihao/FixIt/issues/96)) - :sparkles: Feat: add GitHub Corners support ([#106](https://github.com/Lruihao/FixIt/issues/106)) +- :sparkles: Feat: add local avatar and gravatar support for post author ([#125](https://github.com/Lruihao/FixIt/issues/125)) - :sparkles: Feat: add "Edit this page" button support ([#103](https://github.com/Lruihao/FixIt/issues/103)) - :sparkles: Feat: add count badge for taxonomy ([#122](https://github.com/Lruihao/FixIt/issues/122)) - :zap: Perf: add Gravatar config support diff --git a/assets/css/_page/_single.scss b/assets/css/_page/_single.scss index 8e03ca05..5d971144 100644 --- a/assets/css/_page/_single.scss +++ b/assets/css/_page/_single.scss @@ -33,6 +33,21 @@ .author { font-size: 1.05rem; + + img.avatar { + width: 1.3rem; + height: 1.3rem; + border-radius: 50%; + vertical-align: text-bottom; + border: 0.25px solid $global-border-color; + box-sizing: border-box; + object-position: center; + @include object-fit(cover); + + [theme='dark'] & { + border-color: $global-border-color-dark; + } + } } } diff --git a/exampleSite/config.toml b/exampleSite/config.toml index d9664ecb..039ba860 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -508,6 +508,11 @@ enableEmoji = true enable = true permalink = "https://github.com/Lruihao/FixIt" title = "在 GitHub 上查看源代码" + # Gravatar 设置 since v0.2.14 + [languages.zh-cn.params.gravatar] + # Gravatar 主机,默认:“www.gravatar.com” + host = "gravatar.loli.net" + style = "mp" # "", mp, identicon, monsterid, wavatar, retro, blank, robohash [params] # FixIt theme version @@ -670,6 +675,9 @@ enableEmoji = true # Page style ("narrow", "normal", "wide", ...) since v0.2.13 # 页面样式 ("narrow", "normal", "wide", ...) since v0.2.13 pageStyle = "normal" + # Gravatar is force-used as the author's avatar since v0.2.14 + # 强制使用 Gravatar 作为作者头像 since v0.2.14 + gravatarForce = true # Table of the contents config # 目录配置 [params.page.toc] @@ -1104,7 +1112,7 @@ enableEmoji = true # Gravatar host, default: "www.gravatar.com" # Gravatar 主机,默认:“www.gravatar.com” host = "www.gravatar.com" # "cn.gravatar.com", "gravatar.loli.net" - # style = "mp" # "", mp, identicon, monsterid, wavatar, retro, blank, robohash + style = "mp" # "", mp, identicon, monsterid, wavatar, retro, blank, robohash # Markup related configuration in Hugo # Hugo 解析文档的配置 diff --git a/exampleSite/content/posts/theme-documentation-basics/index.en.md b/exampleSite/content/posts/theme-documentation-basics/index.en.md index 102382e0..0ddb2ce7 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.en.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.en.md @@ -453,6 +453,8 @@ Please open the code block below to view the complete sample configuration :(far rssFullText = false # {{< version 0.2.13 >}} Page style ("narrow", "normal", "wide", ...) pageStyle = "normal" + # {{< version 0.2.14 >}} Gravatar is force-used as the author's avatar + gravatarForce = false # {{< version 0.2.0 >}} Table of the contents config [params.page.toc] # whether to enable the table of the contents @@ -786,7 +788,7 @@ Please open the code block below to view the complete sample configuration :(far [params.gravatar] # Gravatar host, default: "www.gravatar.com" host = "www.gravatar.com" # "cn.gravatar.com", "gravatar.loli.net" - style = "mp" # "", mp, identicon, monsterid, wavatar, retro, blank, robohash + style = "" # "", mp, identicon, monsterid, wavatar, retro, blank, robohash # Markup related configuration in Hugo [markup] diff --git a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md index afed5b28..c49d4b90 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md @@ -463,6 +463,8 @@ hugo rssFullText = false # {{< version 0.2.13 >}} 页面样式 ("narrow", "normal", "wide", ...) pageStyle = "normal" + # {{< version 0.2.14 >}} 强制使用 Gravatar 作为作者头像 + gravatarForce = true # {{< version 0.2.0 >}} 目录配置 [params.page.toc] # 是否使用目录 @@ -796,7 +798,7 @@ hugo [params.gravatar] # Gravatar 主机,默认:“www.gravatar.com” host = "www.gravatar.com" # "cn.gravatar.com", "gravatar.loli.net" - style = "mp" # "", mp, identicon, monsterid, wavatar, retro, blank, robohash + style = "" # "", mp, identicon, monsterid, wavatar, retro, blank, robohash # Hugo 解析文档的配置 [markup] diff --git a/layouts/_default/summary.html b/layouts/_default/summary.html index 6fd0163b..757a71ce 100644 --- a/layouts/_default/summary.html +++ b/layouts/_default/summary.html @@ -24,12 +24,7 @@ {{- /* Meta */ -}}
- {{- $author := $params.author | default .Site.Author.name | default (T "author") -}} - {{- $authorLink := $params.authorlink | default .Site.Author.link | default .Site.Home.RelPermalink -}} - - {{- $options := dict "Class" "author" "Destination" $authorLink "Title" "Author" "Rel" "author" "Icon" (dict "Class" "fas fa-user-circle fa-fw") "Content" $author -}} - {{- partial "plugin/link.html" $options -}} - + {{- partial "single/post-author.html" . -}} {{- with .Site.Params.dateFormat | default "2006-01-02" | .PublishDate.Format -}}   diff --git a/layouts/partials/single/post-author.html b/layouts/partials/single/post-author.html new file mode 100644 index 00000000..e109597b --- /dev/null +++ b/layouts/partials/single/post-author.html @@ -0,0 +1,35 @@ +{{- $params := .Scratch.Get "params" -}} + +{{- $author := .Site.Author | merge (dict "name" "" "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" (.Host | default "www.gravatar.com") (md5 $author.email) (.Style | default "") -}} + {{- end -}} +{{- end -}} + \ No newline at end of file diff --git a/layouts/posts/single.html b/layouts/posts/single.html index e454bffe..9c510ea6 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -29,12 +29,7 @@ {{- /* Meta */ -}}