diff --git a/hugo.toml b/hugo.toml index 3f591c8e..2968140e 100644 --- a/hugo.toml +++ b/hugo.toml @@ -661,7 +661,7 @@ orderby = "name" # Order of tags, optional values: ["name", "count"] enable = false # Gravatar Email for preferred avatar in home page gravatarEmail = "" -# URL of avatar shown in home page +# URL of avatar shown in home page, default is author's avatar avatarURL = "" # FixIt 0.2.17 | NEW identifier of avatar menu link avatarMenu = "" diff --git a/layouts/_partials/function/get-author-map.html b/layouts/_partials/function/get-author-map.html index 518f92f5..d8c45835 100644 --- a/layouts/_partials/function/get-author-map.html +++ b/layouts/_partials/function/get-author-map.html @@ -28,17 +28,9 @@ {{- with $authorParam.avatar -}}{{ $author = dict "avatar" . | merge $author }}{{- end -}} {{- end -}} -{{- $gravatar := site.Params.gravatar -}} -{{- if $gravatar.enable | and $author.email -}} - {{- with $gravatar -}} - {{- /* TODO migrate to 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 -}} +{{- $gravatar := dict "Email" $author.email "Size" "32" | partial "function/get-gravatar.html" -}} +{{- with $gravatar -}} + {{- $author = dict "avatar" . | merge $author -}} {{- end -}} {{- return $author -}} diff --git a/layouts/_partials/function/get-gravatar.html b/layouts/_partials/function/get-gravatar.html new file mode 100644 index 00000000..1a6d2fb0 --- /dev/null +++ b/layouts/_partials/function/get-gravatar.html @@ -0,0 +1,23 @@ +{{- /* + Get Gravatar URL. + @param {String} Email the email address + @param {String} Size the size in pixels (optional, default: 200) + @returns {String} the Gravatar URL + @example {{- $gravatar := dict "Email" "user@example.com" "Size" "32" | partial "function/get-gravatar.html" -}} +*/ -}} + +{{- $config := site.Params.gravatar -}} +{{- $gravatar := "" -}} +{{- if $config.enable | and .Email -}} + {{- with $config -}} + {{- $gravatar = + printf "https://%v/avatar/%v?s=%v&d=%v" + (path.Clean ($.Host | default .Host) | default "www.gravatar.com") + (md5 $.Email) + ($.Size | default 200) + (.Style | default "") + -}} + {{- end -}} +{{- end -}} + +{{- return $gravatar -}} diff --git a/layouts/_partials/home/profile.html b/layouts/_partials/home/profile.html index ea911d0a..832c8a8a 100644 --- a/layouts/_partials/home/profile.html +++ b/layouts/_partials/home/profile.html @@ -1,16 +1,8 @@ {{- $profile := .Site.Params.home.profile -}} +{{- $author := partial "function/get-author-map.html" .Params.author -}} +
- {{- $avatar := $profile.avatarURL -}} - {{- $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") - (md5 $profile.gravatarEmail) - (.Style | default "mp") - -}} - {{- end -}} - {{- end -}} + {{- $avatar := dict "Email" $profile.gravatarEmail "Size" "96" | partial "function/get-gravatar.html" | default $profile.avatarURL | default $author.avatar -}} {{- if $avatar -}}
{{- $menus := $.Site.Menus.main | default slice -}} diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index 8bb152ce..0d46fd57 100644 --- a/layouts/_partials/init/index.html +++ b/layouts/_partials/init/index.html @@ -1,4 +1,4 @@ -{{- hugo.Store.Set "version" "v0.4.0-alpha.3-20251221161325-3f145760" -}} +{{- hugo.Store.Set "version" "v0.4.0-alpha.3-20251222033541-3c7babb5" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}}