Skip to content

Commit 878b6c9

Browse files
authored
Update post meta (#5)
* Update post meta * Edit README * Edit post meta text settings
1 parent edb363e commit 878b6c9

File tree

6 files changed

+125
-49
lines changed

6 files changed

+125
-49
lines changed

README-CN.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# 用于 Hexo NexT 的 Artalk 插件
2+
3+
> [English](https://github.com/leirock/hexo-next-artalk/blob/main/README.md)
4+
5+
[![NPM version](https://img.shields.io/npm/v/hexo-next-artalk?color=red&logo=npm&style=flat-square)](https://www.npmjs.com/package/hexo-next-artalk)
6+
[![NPM downloads](https://img.shields.io/npm/dm/hexo-next-artalk?color=red&logo=npm&style=flat-square)](https://www.npmjs.com/package/hexo-next-artalk)
7+
[![Theme Version](https://img.shields.io/badge/NexT-v7.3.0+-blue?style=flat-square)](https://github.com/next-theme/hexo-theme-next)
8+
[![Artalk Version](https://img.shields.io/badge/Artalk-v2.3.1+-558fb5?style=flat-square)](https://github.com/ArtalkJS/Artalk)
9+
10+
这是一款适用于 Hexo NexT 的 [Artalk](https://artalk.js.org) 评论插件。
11+
12+
## 安装
13+
14+
```bash
15+
npm install hexo-next-artalk
16+
```
17+
18+
## 配置
19+
20+
将下列配置添加到 Hexo 的根配置文件 `_config.yml` 之中,把 `enable` 设为 `true`,然后将 `artalk` 下的其他配置项修改为您自己的值。
21+
22+
```yaml
23+
# Artalk 配置文件
24+
# 更多信息: https://artalk.js.org
25+
26+
artalk:
27+
enable: false
28+
29+
# 后端程序 API 地址,请修改为您自己的 API 地址
30+
server: https://artalk.example.com
31+
32+
# 网站名称,请指定后段程序中的一个网站,留空即默认站点
33+
site:
34+
35+
# 前端资源 CDN 地址,您可以修改为偏好的其他 CDN 镜像
36+
## 参考:https://artalk.js.org/guide/frontend/install.html
37+
jsUrl: https://unpkg.com/artalk@2/dist/Artalk.js
38+
cssUrl: https://unpkg.com/artalk@2/dist/Artalk.css
39+
40+
# 文章阅读数统计
41+
pvCount: true
42+
43+
# 评论数统计
44+
commentCount: true
45+
46+
# 黑暗模式
47+
darkMode: auto
48+
49+
# 在后端控制前端
50+
## 参考:https://artalk.js.org/guide/backend/fe-control.html
51+
useBackendConf: false
52+
```
53+
54+
## 贴士
55+
56+
在文章信息栏中,评论数的默认显示文字是“Artalk”。如果您希望修改此处,例如,改为简体中文的“评论数”:
57+
58+
1. 在 Hexo 博客文件夹下创建文件 `/source/_data/languages.yml`;
59+
2. 编辑该文件如下并保存。
60+
61+
```yaml
62+
zh-CN:
63+
post:
64+
comments:
65+
artalk: 评论数
66+
```

README.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Artalk for Hexo NexT
22

3+
> [中文](https://github.com/leirock/hexo-next-artalk/blob/main/README-CN.md)
4+
35
[![NPM version](https://img.shields.io/npm/v/hexo-next-artalk?color=red&logo=npm&style=flat-square)](https://www.npmjs.com/package/hexo-next-artalk)
46
[![NPM downloads](https://img.shields.io/npm/dm/hexo-next-artalk?color=red&logo=npm&style=flat-square)](https://www.npmjs.com/package/hexo-next-artalk)
57
[![Theme Version](https://img.shields.io/badge/NexT-v7.3.0+-blue?style=flat-square)](https://github.com/next-theme/hexo-theme-next)
68
[![Artalk Version](https://img.shields.io/badge/Artalk-v2.3.1+-558fb5?style=flat-square)](https://github.com/ArtalkJS/Artalk)
79

8-
[Artalk](https://artalk.js.org) comment plugin for Hexo NexT.
10+
This is an [Artalk](https://artalk.js.org) comment plugin for Hexo NexT.
911

1012
## Install
1113

@@ -15,29 +17,28 @@ npm install hexo-next-artalk
1517

1618
## Configure
1719

18-
Set the value `enable` to `true`, add `server`, and edit other configurations in `artalk` section in the config file as following. You can config those in Hexo's root config file `_config.yml`:
20+
Add the following configurations in Hexo's root config file `_config.yml`, set `enable` to `true`, and edit other configurations in `artalk` section as your own values.
1921

2022
```yaml
2123
# Artalk Config File
22-
# For more information: https://artalk.js.org
24+
## For more information: https://artalk.js.org
2325

2426
artalk:
2527
enable: false
2628

27-
# Server address url, you should set this to your own link
29+
# Backend server API, you should set this to your own server API
2830
server: https://artalk.example.com
2931

3032
# Site name, you can set this to specify site for server
3133
# or leave blank to use default site
3234
site:
3335

34-
# JS CDN url, you can set this to your preferred CDN
36+
# Frontend resources CDN, you can set this to your preferred CDN
37+
## Reference: https://artalk.js.org/guide/frontend/install.html
3538
jsUrl: https://unpkg.com/artalk@2/dist/Artalk.js
36-
37-
# CSS styles CDN url, you can set this to your preferred CDN
3839
cssUrl: https://unpkg.com/artalk@2/dist/Artalk.css
3940

40-
# PV count
41+
# Page views count
4142
pvCount: true
4243

4344
# Comments count
@@ -47,5 +48,20 @@ artalk:
4748
darkMode: auto
4849

4950
# Use backend to config
50-
# useBackendConf: true
51+
## Reference: https://artalk.js.org/guide/backend/fe-control.html
52+
useBackendConf: false
53+
```
54+
55+
## Tips
56+
57+
The default text of comments count in post meta is "Artalk". If you would like to change it, for example, to simplified Chinese "评论数":
58+
59+
1. Create a file `/source/_data/languages.yml` in your Hexo blog folder;
60+
2. Edit this file as follows and then save it.
61+
62+
```yaml
63+
zh-CN:
64+
post:
65+
comments:
66+
artalk: 评论数
5167
```

artalk.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{ next_data('artalk', config.artalk, {
2-
el: '#artalk',
2+
el: '#comments',
33
pageKey: url_for(page.path) | replace(r/index\.html$/, ''),
44
pageTitle: page.title,
55
locale: page.lang | default('zh-CN', true)

default.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
# Artalk Config File
2-
# For more information: https://artalk.js.org
2+
## For more information: https://artalk.js.org
33

44
artalk:
55
enable: false
66

7-
# Server address url, you should set this to your own link
7+
# Backend server API, you should set this to your own server API
88
server: https://artalk.example.com
99

1010
# Site name, you can set this to specify site for server
1111
# or leave blank to use default site
1212
site:
13-
14-
# JS CDN url, you can set this to your preferred CDN
15-
jsUrl: https://unpkg.com/artalk@2/dist/Artalk.js
1613

17-
# CSS styles CDN url, you can set this to your preferred CDN
14+
# Frontend resources CDN, you can set this to your preferred CDN
15+
## Reference: https://artalk.js.org/guide/frontend/install.html
16+
jsUrl: https://unpkg.com/artalk@2/dist/Artalk.js
1817
cssUrl: https://unpkg.com/artalk@2/dist/Artalk.css
1918

20-
# PV count
19+
# Page views count
2120
pvCount: true
2221

2322
# Comments count
@@ -27,4 +26,5 @@ artalk:
2726
darkMode: auto
2827

2928
# Use backend to config
30-
# useBackendConf: true
29+
## Reference: https://artalk.js.org/guide/backend/fe-control.html
30+
useBackendConf: false

index.js

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,50 @@ hexo.extend.filter.register('theme_inject', (injects) => {
1010
const config = utils.defaultConfigFile('artalk', 'default.yaml');
1111
if (!config.enable) return;
1212

13-
injects.comment.raw('artalk', '<div class="comments" id="artalk"></div>', {}, { cache: true });
13+
injects.comment.raw('artalk', '<div class="comments" id="comments"></div>', {}, { cache: true });
1414
injects.bodyEnd.raw('artalk', utils.getFileContent('artalk.njk'));
1515
injects.head.raw('artalk', `<link rel="preconnect" href="${config.server}">`, {}, {});
1616
});
1717

1818
// Add post_meta
19-
const capitalize = (input) => input.toString().charAt(0).toUpperCase() + input.toString().substr(1);
20-
const iconText = (icon, key, defaultValue = capitalize(key)) =>
21-
`
22-
<span class="post-meta-item-icon">
23-
<i class="${icon}"></i>
24-
</span>
25-
{%- set post_meta_comment = __('post.comments.${key}') %}
26-
{%- if post_meta_comment == 'post.comments.${key}' %}
27-
{%- set post_meta_comment = '${defaultValue}' %}
28-
{%- endif %}
29-
<span class="post-meta-item-text">{{ post_meta_comment + __('symbol.colon') }}</span>
30-
`;
31-
3219
hexo.extend.filter.register('theme_inject', (injects) => {
3320
const config = utils.defaultConfigFile('artalk', 'default.yaml');
3421
if (!config.enable || !config.server) return;
3522

3623
injects.postMeta.raw(
37-
'artalk_comment_count',
24+
'artalk_pv_count',
3825
`
39-
{% if post.comments and config.artalk.commentCount %}
40-
<span class="post-meta-item">
41-
${iconText('far fa-comment', 'artalk')}
42-
<a title="artalk" href="{{ url_for(post.path) }}#artalk" itemprop="discussionUrl">
43-
<span id="ArtalkCount" class="post-comments-count" data-page-key="{{ url_for(post.path) }}" itemprop="commentCount"></span>
44-
</a>
45-
</span>
26+
{% if config.artalk.pvCount %}
27+
<span class="post-meta-item" title="{{ __('post.views') }}">
28+
<span class="post-meta-item-icon">
29+
<i class="far fa-eye"></i>
30+
</span>
31+
<span class="post-meta-item-text">{{ __('post.views') + __('symbol.colon') }}</span>
32+
<span id="ArtalkPV" data-page-key="{{ url_for(post.path) }}" ></span>
33+
</span>
4634
{% endif %}
4735
`,
4836
{},
4937
{}
5038
);
5139

5240
injects.postMeta.raw(
53-
'artalk_pv_count',
41+
'artalk_comment_count',
5442
`
55-
{% if config.artalk.pvCount %}
56-
<span class="post-meta-item" title="{{ __('post.views') }}">
57-
<span class="post-meta-item-icon">
58-
<i class="far fa-eye"></i>
43+
{% if post.comments and config.artalk.commentCount %}
44+
{%- set post_meta_comment = __('post.comments.artalk') %}
45+
{%- if post_meta_comment == 'post.comments.artalk' %}
46+
{%- set post_meta_comment = 'Artalk' %}
47+
{%- endif %}
48+
<span class="post-meta-item" title="{{ post_meta_comment }}">
49+
<span class="post-meta-item-icon">
50+
<i class="far fa-comment"></i>
51+
</span>
52+
<span class="post-meta-item-text">{{ post_meta_comment + __('symbol.colon') }}</span>
53+
<a href="{{ url_for(post.path) }}#comments" itemprop="discussionUrl">
54+
<span id="ArtalkCount" class="post-comments-count" data-page-key="{{ url_for(post.path) }}" itemprop="commentCount"></span>
55+
</a>
5956
</span>
60-
<span class="post-meta-item-text">{{ __('post.views') + __('symbol.colon') }}</span>
61-
<span id="ArtalkPV" data-page-key="{{ url_for(post.path) }}" ></span>
62-
</span>
6357
{% endif %}
6458
`,
6559
{},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hexo-next-artalk",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Artalk comment plugin for Hexo NexT.",
55
"keywords": [
66
"Hexo",

0 commit comments

Comments
 (0)