-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
63 lines (55 loc) · 2.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* global hexo */
'use strict';
const Util = require('@next-theme/utils');
const utils = new Util(hexo, __dirname);
// Add comment
hexo.extend.filter.register('theme_inject', (injects) => {
const config = utils.defaultConfigFile('artalk', 'default.yaml');
if (!config.enable) return;
injects.comment.raw('artalk', '<div class="comments" id="comments"></div>', {}, { cache: true });
injects.bodyEnd.raw('artalk', utils.getFileContent('artalk.njk'));
injects.head.raw('artalk', `<link rel="preconnect" href="${config.server}">`, {}, {});
});
// Add post_meta
hexo.extend.filter.register('theme_inject', (injects) => {
const config = utils.defaultConfigFile('artalk', 'default.yaml');
if (!config.enable || !config.server) return;
injects.postMeta.raw(
'artalk_pv_count',
`
{% if config.artalk.pvCount %}
<span class="post-meta-item" title="{{ __('post.views') }}">
<span class="post-meta-item-icon">
<i class="far fa-eye"></i>
</span>
<span class="post-meta-item-text">{{ __('post.views') + __('symbol.colon') }}</span>
<span id="ArtalkPV" data-page-key="{{ url_for(post.path) }}" ></span>
</span>
{% endif %}
`,
{},
{}
);
injects.postMeta.raw(
'artalk_comment_count',
`
{% if post.comments and config.artalk.commentCount %}
{%- set post_meta_comment = __('post.comments.artalk') %}
{%- if post_meta_comment == 'post.comments.artalk' %}
{%- set post_meta_comment = 'Artalk' %}
{%- endif %}
<span class="post-meta-item" title="{{ post_meta_comment }}">
<span class="post-meta-item-icon">
<i class="far fa-comment"></i>
</span>
<span class="post-meta-item-text">{{ post_meta_comment + __('symbol.colon') }}</span>
<a href="{{ url_for(post.path) }}#comments" itemprop="discussionUrl">
<span id="ArtalkCount" class="post-comments-count" data-page-key="{{ url_for(post.path) }}" itemprop="commentCount"></span>
</a>
</span>
{% endif %}
`,
{},
{}
);
});