Skip to content

Commit d98becd

Browse files
committed
init hexo-next-twikoo
1 parent c8fa54e commit d98becd

File tree

6 files changed

+47
-110
lines changed

6 files changed

+47
-110
lines changed

README.md

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,31 @@
1-
# Hexo NexT Valine
1+
# Hexo NexT Twikoo
22

33
![Theme Version](https://img.shields.io/badge/NexT-v7.3.0+-blue?style=flat-square)
4-
![Package Version](https://img.shields.io/github/package-json/v/next-theme/hexo-next-valine?style=flat-square)
4+
![Package Version](https://img.shields.io/github/package-json/v/imaegoo/hexo-next-twikoo?style=flat-square)
55

6-
Valine comment system for NexT. Valine is a fast, simple & efficient Leancloud based no back end comment system.
6+
Twikoo comment system for NexT. Twikoo is a simple, safe, free comment system.
77

88
## Install
99

1010
```bash
11-
npm install next-theme/hexo-next-valine
11+
npm install hexo-next-twikoo
1212
```
1313

1414
## Register
1515

16-
1. Create an account or log into [LeanCloud](https://www.leancloud.cn/dashboard/login.html#/signin), and then click on the bottom left corner to [create the application](https://www.leancloud.cn/dashboard/applist.html#/newapp) in [dashboard](https://www.leancloud.cn/dashboard/applist.html#/apps).
17-
![Valine](https://theme-next.js.org/images/valine-1.png)
18-
2. Go to the application you just created, select `Settings → App Keys` in the lower left corner, and you will see your APP ID and APP Key.
19-
![Valine](https://theme-next.js.org/images/valine-2.png)
16+
Please refer to https://twikoo.js.org/quick-start.html
2017

2118
## Configure
2219

23-
Set the value `enable` to `true`, add the obtained APP ID (`appId`) and APP Key (`appKey`), and edit other configurations in `valine` section in the config file as following. You can config those in both **hexo** or **theme** `_config.yml`:
20+
Set the value `enable` to `true`, add the obtained env ID (`envId`), and edit other configurations in `twikoo` section in the config file as following. You can config those in both **hexo** or **theme** `_config.yml`:
2421

2522
```yml next/_config.yml
26-
# Valine
27-
# For more information: https://valine.js.org, https://github.com/xCss/Valine
28-
valine:
29-
enable: false
30-
appId: # your leancloud application appid
31-
appKey: # your leancloud application appkey
32-
serverURLs: # When the custom domain name is enabled, fill it in here
33-
placeholder: Just go go # comment box placeholder
34-
avatar: mm # gravatar style
35-
meta: [nick, mail, link] # Custom comment header
36-
pageSize: 10 # pagination size
37-
visitor: false # leancloud-counter-security is not supported for now. When visitor is set to be true, appid and appkey are recommended to be the same as leancloud_visitors' for counter compatibility. Article reading statistic https://valine.js.org/visitor.html
38-
comment_count: true # If false, comment count will only be displayed in post page, not in home page
39-
recordIP: false # Whether to record the commenter IP
23+
# Twikoo
24+
# For more information: https://twikoo.js.org, https://github.com/imaegoo/twikoo
25+
twikoo:
26+
enable: true
27+
visitor: true
28+
envId: twikoo-1gs9l0fb17e7897a # 环境 ID,搭建教程:https://twikoo.js.org/quick-start.html
29+
# region: ap-guangzhou # 环境地域,默认为 ap-shanghai
30+
# path: 'window.location.pathname' # 自定义文章路径
4031
```

default.yaml

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
# Valine
2-
# For more information: https://valine.js.org, https://github.com/xCss/Valine
3-
valine:
1+
# Twikoo
2+
# For more information: https://twikoo.js.org, https://github.com/imaegoo/twikoo
3+
twikoo:
44
enable: false
5-
appId: # Your leancloud application appid
6-
appKey: # Your leancloud application appkey
7-
serverURLs: # When the custom domain name is enabled, fill it in here
8-
placeholder: Just go go # Comment box placeholder
9-
avatar: mm # Gravatar style
10-
meta: [nick, mail, link] # Custom comment header
11-
pageSize: 10 # Pagination size
12-
lang: # Language, available values: en, zh-cn
13-
# Warning: Do not enable both `valine.visitor` and `leancloud_visitors`.
14-
visitor: false # Article reading statistic
15-
comment_count: true # If false, comment count will only be displayed in post page, not in home page
16-
recordIP: false # Whether to record the commenter IP
17-
enableQQ: false # Whether to enable the Nickname box to automatically get QQ Nickname and QQ Avatar
18-
requiredFields: [] # Set required fields: [nick] | [nick, mail]
5+
visitor: false
6+
envId: twikoo-1gs9l0fb17e7897a # 环境 ID,搭建教程:https://twikoo.js.org/quick-start.html
7+
# region: ap-guangzhou # 环境地域,默认为 ap-shanghai
8+
# path: 'window.location.pathname' # 自定义文章路径

index.js

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,31 @@
55
const Util = require('@next-theme/utils');
66
const utils = new Util(hexo, __dirname);
77

8-
function capitalize(input) {
9-
return input.toString().charAt(0).toUpperCase() + input.toString().substr(1);
10-
}
11-
12-
function iconText(icon, key, defaultValue) {
13-
if (!defaultValue) {
14-
defaultValue = capitalize(key);
15-
}
16-
return `
17-
<span class="post-meta-item-icon">
18-
<i class="${icon}"></i>
19-
</span>
20-
{%- set post_meta_comment = __('post.comments.${key}') %}
21-
{%- if post_meta_comment == 'post.comments.${key}' %}
22-
{%- set post_meta_comment = '${defaultValue}' %}
23-
{%- endif %}
24-
<span class="post-meta-item-text">{{ post_meta_comment + __('symbol.colon') }}</span>
25-
`;
26-
}
27-
28-
function warning(...args) {
29-
hexo.log.warn(`Since ${args[0]} is turned on, the ${args[1]} is disabled to avoid potential hazards.`);
30-
};
31-
328
// Add comment
339
hexo.extend.filter.register('theme_inject', injects => {
3410

35-
const config = utils.defaultConfigFile('valine', 'default.yaml');
36-
if (!config.enable || !config.appId || !config.appKey) return;
11+
const config = utils.defaultConfigFile('twikoo', 'default.yaml');
12+
if (!config.enable || !config.envId) return;
3713

38-
injects.comment.raw('valine', '<div class="comments" id="valine-comments"></div>', {}, { cache: true });
14+
injects.comment.raw('twikoo', '<div class="comments"><div id="twikoo-comments"></div></div>', {}, { cache: true });
3915

40-
injects.bodyEnd.raw('valine', utils.getFileContent('valine.njk'));
16+
injects.bodyEnd.raw('twikoo', utils.getFileContent('twikoo.njk'));
4117

4218
});
4319

4420
// Add post_meta
4521
hexo.extend.filter.register('theme_inject', injects => {
4622

47-
const config = utils.defaultConfigFile('valine', 'default.yaml');
48-
if (!config.enable || !config.appId || !config.appKey) return;
49-
50-
injects.postMeta.raw('valine', `
51-
{% if post.comments and (is_post() or theme.valine.comment_count) %}
52-
<span class="post-meta-item">
53-
${iconText('far fa-comment', 'valine')}
54-
<a title="valine" href="{{ url_for(post.path) }}#valine-comments" itemprop="discussionUrl">
55-
<span class="post-comments-count valine-comment-count" data-xid="{{ url_for(post.path) }}" itemprop="commentCount"></span>
56-
</a>
57-
</span>
58-
{% endif %}
59-
`, {}, {});
60-
23+
const config = utils.defaultConfigFile('twikoo', 'default.yaml');
24+
if (!config.enable || !config.envId) return;
6125
if (config.visitor) {
62-
if (hexo.theme.config.leancloud_visitors && hexo.theme.config.leancloud_visitors.enable) {
63-
warning('valine.visitor', 'leancloud_visitors');
64-
hexo.theme.config.leancloud_visitors.enable = false;
65-
return;
66-
}
67-
68-
injects.postMeta.raw('valine', `
69-
<span id="{{ url_for(post.path) }}" class="post-meta-item leancloud_visitors" data-flag-title="{{ post.title }}" title="{{ __('post.views') }}">
26+
injects.postMeta.raw('twikoo', `
27+
<span id="{{ url_for(post.path) }}" class="post-meta-item twikoo_visitors" data-flag-title="{{ post.title }}" title="{{ __('post.views') }}">
7028
<span class="post-meta-item-icon">
7129
<i class="far fa-eye"></i>
7230
</span>
7331
<span class="post-meta-item-text">{{ __('post.views') + __('symbol.colon') }}</span>
74-
<span class="leancloud-visitors-count"></span>
32+
<span id="twikoo_visitors"></span>
7533
</span>
7634
`, {}, {});
7735
}

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
{
2-
"name": "hexo-next-valine",
2+
"name": "hexo-next-twikoo",
33
"version": "1.0.0",
4-
"description": "Valine comment system for NexT.",
4+
"description": "Twikoo comment system for NexT.",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
9-
"repository": "next-theme/hexo-next-valine",
9+
"repository": "https://github.com/imaegoo/hexo-next-twikoo",
1010
"keywords": [
1111
"Hexo",
12-
"NexT"
12+
"NexT",
13+
"twikoo"
1314
],
14-
"author": "Mimi <stevenjoezhang@gmail.com> (https://zhangshuqiao.org)",
15+
"author": "imaegoo <hello@imaegoo.com> (https://github.com/imaegoo)",
1516
"license": "LGPL-3.0",
1617
"bugs": {
17-
"url": "https://github.com/next-theme/hexo-next-valine/issues"
18+
"url": "https://github.com/imaegoo/hexo-next-twikoo/issues"
1819
},
19-
"homepage": "https://github.com/next-theme/hexo-next-valine#readme",
20+
"homepage": "https://github.com/imaegoo/hexo-next-twikoo#readme",
2021
"dependencies": {
2122
"@next-theme/utils": "^1.1.0"
2223
}

twikoo.njk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
NexT.utils.loadComments('#twikoo-comments', () => {
3+
NexT.utils.getScript('https://cdn.jsdelivr.net/npm/twikoo/dist/twikoo.all.min.js', () => {
4+
twikoo.init(Object.assign({{ config.twikoo | safedump }}, {
5+
el: '#twikoo-comments'
6+
}));
7+
}, window.twikoo);
8+
});
9+
</script>

valine.njk

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)