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

feat(gravatar): support letter avatar with weavatar #882

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion conf/artalk.example.simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ frontend:
nestSort: DATE_ASC
gravatar:
mirror: https://www.gravatar.com/avatar/
params: d=mp&s=240
params: s=240&d=letter
pagination:
pageSize: 20
readMore: true
Expand Down
4 changes: 2 additions & 2 deletions conf/artalk.example.zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ frontend:
# 头像 Gravatar
gravatar:
# API 地址
mirror: https://cravatar.cn/avatar/
mirror: https://weavatar.com/avatar/
# API 参数
params: d=mp&s=240
params: s=240&d=letter
# 评论分页
pagination:
# 每页评论数
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/.vitepress/theme/Artalk.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function initArtalk(conf: any) {
el: el.value,
emoticons: '/assets/emoticons/default.json',
gravatar: {
mirror: 'https://cravatar.cn/avatar/',
mirror: 'https://weavatar.com/avatar/',
},
...conf,
})
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/develop/api-old.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
| `data.comment.id` | Number | - | 评论 ID |
| `data.comment.content` | String | - | 评论正文 |
| `data.comment.nick` | String | - | 评论者昵称 |
| `data.comment.email_encrypted` | String | - | 评论者邮箱 MD5 加密值 |
| `data.comment.email_encrypted` | String | - | 评论者邮箱 SHA256 加密值 |
| `data.comment.link` | String | - | 评论者链接 |
| `data.comment.ua` | String | - | 评论者 User-Agent |
| `data.comment.date` | String | - | 评论时间,格式为 `1970-01-01 00:00:00` |
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guide/backend/admin_notify.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ admin_notify:
"content": "测试内容",
"user_id": 226,
"nick": "测试用户",
"email_encrypted": "654236c1e78i4c09a17c4869c9d43910",
"email_encrypted": "68f8397b4a212a6d281a6ac8a9c25556215729054b8cb331c03882b91fe31758",
"link": "https://qwqaq.com",
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 12_4_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36",
"date": "2022-05-23 17:00:23",
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/guide/backend/email.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ email:
"comment.date": "2021-11-22",
"comment.datetime": "2021-11-22 22:22:42",
"comment.email": "[email protected]",
"comment.email_encrypted": "249898bd50e0febc5799485cf10b345a",
"comment.email_encrypted": "68f8397b4a212a6d281a6ac8a9c25556215729054b8cb331c03882b91fe31758",
"comment.id": 8100,
"comment.is_allow_reply": true,
"comment.is_collapsed": false,
Expand Down Expand Up @@ -248,7 +248,7 @@ email:
"parent_comment.date": "2021-11-22",
"parent_comment.datetime": "2021-11-22 22:21:17",
"parent_comment.email": "[email protected]",
"parent_comment.email_encrypted": "55502f40dc8b7c769880b10874abc9d0",
"parent_comment.email_encrypted": "973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b",
"parent_comment.id": 8099,
"parent_comment.is_allow_reply": true,
"parent_comment.is_collapsed": false,
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/guide/frontend/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ gravatar: {
**Gravatar 镜像地址**

- 类型:`String`
- 默认值:`"https://sdn.geekzu.org/avatar/"`
- 默认值:`"https://weavatar.com/avatar/"`

如果你觉得 Gravatar 头像加载速度不理想,可以尝试替换。

Expand All @@ -378,11 +378,11 @@ gravatar: {
**Gravatar API 参数**

- 类型:`String`
- 默认值:`"d=mp&s=240"`
- 默认值:`"s=240&d=letter"`

例如,你可以通过该配置项设置默认头像 (`d=mp`) 和头像尺寸 (`s=240`)。

参考:[Gravatar API 文档](http://cn.gravatar.org/site/implement/images/)
参考:[Gravatar API 文档](https://docs.gravatar.com/api/avatars/images/)

该配置项格式为 HTTP Query。

Expand Down
2 changes: 1 addition & 1 deletion test/ssg-test/.vitepress/theme/Artalk.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function initArtalk(conf: any) {
el: el.value,
emoticons: '/assets/emoticons/default.json',
gravatar: {
mirror: 'https://cravatar.cn/avatar/',
mirror: 'https://weavatar.com/avatar/',
},
...conf,
})
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/example_site_conf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ frontend:
nestMax: 2
nestSort: DATE_ASC
gravatar:
mirror: https://cravatar.cn/avatar/
mirror: https://weavatar.com/avatar/
default: mp
pagination:
pageSize: 20
Expand Down
3 changes: 2 additions & 1 deletion ui/artalk/src/comment/comment-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ export default class CommentNode {
return Utils.getGravatarURL({
mirror: this.opts.gravatar.mirror,
params: this.opts.gravatar.params,
emailMD5: this.data.email_encrypted,
emailHash: this.data.email_encrypted,
nick: this.data.nick,
})
}

Expand Down
4 changes: 2 additions & 2 deletions ui/artalk/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const defaults: ArtalkConfig = {
statPageKeyAttr: 'data-page-key',

gravatar: {
mirror: 'https://cravatar.cn/avatar/',
params: 'd=mp&s=240',
mirror: 'https://weavatar.com/avatar/',
params: 's=240&d=letter',
},

pagination: {
Expand Down
4 changes: 2 additions & 2 deletions ui/artalk/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ export function timeAgo(date: Date, $t: Function = (n: string) => n) {
}
}

export function getGravatarURL(opts: { params: string; mirror: string; emailMD5: string }) {
return `${opts.mirror.replace(/\/$/, '')}/${opts.emailMD5}?${opts.params.replace(/^\?/, '')}`
export function getGravatarURL(opts: { params: string; mirror: string; emailHash: string; nick: string }) {
return `${opts.mirror.replace(/\/$/, '')}/${opts.emailHash}?${opts.params.replace(/^\?/, '')}&letter=${opts.nick.charAt(0)}`
}

export function sleep(ms: number) {
Expand Down