Skip to content

Commit a3bf3b8

Browse files
Init
0 parents  commit a3bf3b8

File tree

7 files changed

+175
-0
lines changed

7 files changed

+175
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
*.log

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Hexo NexT Valine
2+
3+
![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)
5+
6+
Valine comment system for NexT. Valine is a fast, simple & efficient Leancloud based no back end comment system.
7+
8+
## Install
9+
10+
```bash
11+
npm install next-theme/hexo-next-valine
12+
```
13+
14+
## Register
15+
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)
20+
21+
## Configure
22+
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`:
24+
25+
```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
40+
```

default.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Valine
2+
# For more information: https://valine.js.org, https://github.com/xCss/Valine
3+
valine:
4+
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]

index.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* global hexo */
2+
3+
'use strict';
4+
5+
const Util = require('@next-theme/utils');
6+
const utils = new Util(hexo, __dirname);
7+
8+
function iconText(icon, key, defaultValue) {
9+
if (!defaultValue) {
10+
defaultValue = capitalize(key);
11+
}
12+
return `
13+
<span class="post-meta-item-icon">
14+
<i class="${icon}"></i>
15+
</span>
16+
{%- set post_meta_comment = __('post.comments.${key}') %}
17+
{%- if post_meta_comment == 'post.comments.${key}' %}
18+
{%- set post_meta_comment = '${defaultValue}' %}
19+
{%- endif %}
20+
<span class="post-meta-item-text">{{ post_meta_comment + __('symbol.colon') }}</span>
21+
`;
22+
}
23+
24+
function warning(...args) {
25+
hexo.log.warn(`Since ${args[0]} is turned on, the ${args[1]} is disabled to avoid potential hazards.`);
26+
};
27+
28+
// Add comment
29+
hexo.extend.filter.register('theme_inject', injects => {
30+
31+
const config = utils.defaultConfigFile('valine', 'default.yaml');
32+
if (!config.enable || !config.appId || !config.appKey) return;
33+
34+
injects.comment.raw('valine', '<div class="comments" id="valine-comments"></div>', {}, { cache: true });
35+
36+
injects.bodyEnd.raw('valine', utils.getFileContent('valine.njk'));
37+
38+
});
39+
40+
// Add post_meta
41+
hexo.extend.filter.register('theme_inject', injects => {
42+
43+
const config = utils.defaultConfigFile('valine', 'default.yaml');
44+
if (!config.enable || !config.appId || !config.appKey) return;
45+
46+
injects.postMeta.raw('valine', `
47+
{% if post.comments and (is_post() or theme.valine.comment_count) %}
48+
<span class="post-meta-item">
49+
${iconText('far fa-comment', 'valine')}
50+
<a title="valine" href="{{ url_for(post.path) }}#valine-comments" itemprop="discussionUrl">
51+
<span class="post-comments-count valine-comment-count" data-xid="{{ url_for(post.path) }}" itemprop="commentCount"></span>
52+
</a>
53+
</span>
54+
{% endif %}
55+
`, {}, {});
56+
57+
if (config.visitor) {
58+
if (hexo.theme.config.leancloud_visitors && hexo.theme.config.leancloud_visitors.enable) {
59+
warning('valine.visitor', 'leancloud_visitors');
60+
hexo.theme.config.leancloud_visitors.enable = false;
61+
return;
62+
}
63+
64+
injects.postMeta.raw('valine', `
65+
<span id="{{ url_for(post.path) }}" class="post-meta-item leancloud_visitors" data-flag-title="{{ post.title }}" title="{{ __('post.views') }}">
66+
<span class="post-meta-item-icon">
67+
<i class="far fa-eye"></i>
68+
</span>
69+
<span class="post-meta-item-text">{{ __('post.views') + __('symbol.colon') }}</span>
70+
<span class="leancloud-visitors-count"></span>
71+
</span>
72+
`, {}, {});
73+
}
74+
75+
});

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "hexo-next-valine",
3+
"version": "1.0.0",
4+
"description": "Valine comment system for NexT.",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": "next-theme/hexo-next-valine",
10+
"keywords": [
11+
"Hexo",
12+
"NexT"
13+
],
14+
"author": "Mimi <stevenjoezhang@gmail.com> (https://zhangshuqiao.org)",
15+
"license": "LGPL-3.0",
16+
"bugs": {
17+
"url": "https://github.com/next-theme/hexo-next-valine/issues"
18+
},
19+
"homepage": "https://github.com/next-theme/hexo-next-valine#readme",
20+
"dependencies": {
21+
"@next-theme/utils": "^1.1.0"
22+
}
23+
}

renovate.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": [
3+
"config:base"
4+
]
5+
}

valine.njk

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{%- set serverURLs = theme.valine.serverURLs or 'https://' + theme.valine.appId.slice(0, 8) | lower + '.api.lncldglobal.com' %}
2+
<script>
3+
NexT.utils.loadComments('#valine-comments', () => {
4+
NexT.utils.getScript('{{ theme.vendors.valine }}', () => {
5+
new Valine(Object.assign({{ theme.valine | safedump }}, {
6+
el: '#valine-comments',
7+
path: {{ url_for(page.path) | replace(r/index\.html$/, '') | safedump }},
8+
serverURLs: {{ serverURLs | safedump }}
9+
}));
10+
}, window.Valine);
11+
});
12+
</script>

0 commit comments

Comments
 (0)