Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/author avater #288

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 5 additions & 3 deletions archetypes/post-bundle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ title: "{{ replace .TranslationBaseName "-" " " | title }}"
subtitle: ""
date: {{ .Date }}
draft: true
author: ""
authorLink: ""
authorEmail: ""
author:
name: ""
link: ""
email: ""
avatar: ""
description: ""
keywords: ""
license: ""
Expand Down
8 changes: 5 additions & 3 deletions archetypes/posts.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ title: "{{ replace .TranslationBaseName "-" " " | title }}"
subtitle: ""
date: {{ .Date }}
draft: true
author: ""
authorLink: ""
authorEmail: ""
author:
name: ""
link: ""
email: ""
avatar: ""
description: ""
keywords: ""
license: ""
Expand Down
6 changes: 4 additions & 2 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion docs
Submodule docs updated 27 files
+1 −0 config/_default/author.toml
+8 −5 config/_default/params.toml
+1 −0 config/_default/params.zh-cn.toml
+6 −8 content/posts/emoji-support/index.en.md
+6 −8 content/posts/emoji-support/index.zh-cn.md
+3 −2 content/posts/extended-shortcode-bilibili/index.en.md
+3 −2 content/posts/extended-shortcode-bilibili/index.zh-cn.md
+3 −2 content/posts/extended-shortcode-echarts/index.en.md
+3 −2 content/posts/extended-shortcode-echarts/index.zh-cn.md
+3 −2 content/posts/extended-shortcode-mapbox/index.en.md
+3 −2 content/posts/extended-shortcode-mapbox/index.zh-cn.md
+3 −2 content/posts/extended-shortcode-mermaid/index.en.md
+3 −2 content/posts/extended-shortcode-mermaid/index.zh-cn.md
+3 −2 content/posts/extended-shortcode-music/index.en.md
+3 −2 content/posts/extended-shortcode-music/index.zh-cn.md
+3 −2 content/posts/extended-shortcode-typeit/index.en.md
+3 −2 content/posts/extended-shortcode-typeit/index.zh-cn.md
+9 −4 content/posts/theme-documentation-basics/index.en.md
+10 −4 content/posts/theme-documentation-basics/index.zh-cn.md
+3 −2 content/posts/theme-documentation-built-in-shortcodes/index.en.md
+3 −2 content/posts/theme-documentation-built-in-shortcodes/index.zh-cn.md
+6 −4 content/posts/theme-documentation-content-encryption/index.en.md
+6 −4 content/posts/theme-documentation-content-encryption/index.zh-cn.md
+8 −6 content/posts/theme-documentation-content/index.en.md
+8 −7 content/posts/theme-documentation-content/index.zh-cn.md
+3 −2 content/posts/theme-documentation-extended-shortcodes/index.en.md
+3 −2 content/posts/theme-documentation-extended-shortcodes/index.zh-cn.md
5 changes: 3 additions & 2 deletions layouts/partials/head/seo.html
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/home/profile.html
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
50 changes: 31 additions & 19 deletions layouts/partials/single/post-author.html
Original file line number Diff line number Diff line change
@@ -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 -}}
Expand All @@ -31,7 +43,7 @@
{{- else -}}
<span class="author">
{{- with $icon -}}
{{ . | partial "plugin/icon.html" }}
{{- . | partial "plugin/icon.html" }}
{{ end -}}
{{- $content | safeHTML -}}
</span>
Expand Down