From c8580018cbc630eaaec3df4bcd18189b082668e3 Mon Sep 17 00:00:00 2001 From: ctj12461 Date: Sun, 20 Feb 2022 23:37:20 +0800 Subject: [PATCH] :sparkles: Feat: add Gravatar mirror site support --- exampleSite/config.toml | 4 ++++ .../content/posts/theme-documentation-basics/index.en.md | 2 ++ .../posts/theme-documentation-basics/index.zh-cn.md | 2 ++ layouts/partials/home/profile.html | 7 +++++-- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/exampleSite/config.toml b/exampleSite/config.toml index ef6b25f0..2d94cf23 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -156,6 +156,8 @@ enableEmoji = true # Home page profile [languages.en.params.home.profile] enable = true + # Gravatar mirror site domain, default: "www.gravatar.com" since v0.2.13 + gravatarSite = "" # Gravatar Email for preferred avatar in home page gravatarEmail = "" # URL of avatar shown in home page @@ -375,6 +377,8 @@ enableEmoji = true # 主页个人信息 [languages.zh-cn.params.home.profile] enable = true + # 选择使用 Gravatar 源站或其他镜像站,若留空则为默认的 "www.gravatar.com" since v0.2.13 + gravatarSite = "" # Gravatar 邮箱,用于优先在主页显示的头像 gravatarEmail = "" # 主页显示头像的 URL diff --git a/exampleSite/content/posts/theme-documentation-basics/index.en.md b/exampleSite/content/posts/theme-documentation-basics/index.en.md index b2e7c303..7f6e0b49 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.en.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.en.md @@ -315,6 +315,8 @@ Please open the code block below to view the complete sample configuration :(far # Home page profile [params.home.profile] enable = true + # {{< version 0.2.13 >}} Gravatar mirror site domain, default: "www.gravatar.com" + gravatarSite = "" # Gravatar Email for preferred avatar in home page gravatarEmail = "" # URL of avatar shown in home page 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 6a6bb330..c85add4c 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md @@ -326,6 +326,8 @@ hugo # 主页个人信息 [params.home.profile] enable = true + # {{< version 0.2.13 >}} 选择使用 Gravatar 源站或其他镜像站,若留空则为默认的 "www.gravatar.com" + gravatarSite = "" # Gravatar 邮箱,用于优先在主页显示的头像 gravatarEmail = "" # 主页显示头像的 URL diff --git a/layouts/partials/home/profile.html b/layouts/partials/home/profile.html index 41678ff6..1dfe33b0 100644 --- a/layouts/partials/home/profile.html +++ b/layouts/partials/home/profile.html @@ -1,8 +1,11 @@ {{- $profile := .Site.Params.home.profile -}}
{{- $avatar := $profile.avatarURL -}} - {{- with $profile.gravatarEmail -}} - {{- $avatar = md5 . | printf "https://www.gravatar.com/avatar/%v?s=240&d=mp" -}} + {{- if $profile.gravatarEmail -}} + {{- with $profile -}} + {{- $site := .gravatarSite | default "www.gravatar.com" -}} + {{- $avatar = md5 .gravatarEmail | printf "https://%v/avatar/%v?s=240&d=mp" $site -}} + {{- end -}} {{- end -}} {{- if $avatar -}}