|
5 | 5 | const Util = require('@next-theme/utils'); |
6 | 6 | const utils = new Util(hexo, __dirname); |
7 | 7 |
|
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 | | - |
32 | 8 | // Add comment |
33 | 9 | hexo.extend.filter.register('theme_inject', injects => { |
34 | 10 |
|
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; |
37 | 13 |
|
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 }); |
39 | 15 |
|
40 | | - injects.bodyEnd.raw('valine', utils.getFileContent('valine.njk')); |
| 16 | + injects.bodyEnd.raw('twikoo', utils.getFileContent('twikoo.njk')); |
41 | 17 |
|
42 | 18 | }); |
43 | 19 |
|
44 | 20 | // Add post_meta |
45 | 21 | hexo.extend.filter.register('theme_inject', injects => { |
46 | 22 |
|
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; |
61 | 25 | 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') }}"> |
70 | 28 | <span class="post-meta-item-icon"> |
71 | 29 | <i class="far fa-eye"></i> |
72 | 30 | </span> |
73 | 31 | <span class="post-meta-item-text">{{ __('post.views') + __('symbol.colon') }}</span> |
74 | | - <span class="leancloud-visitors-count"></span> |
| 32 | + <span id="twikoo_visitors"></span> |
75 | 33 | </span> |
76 | 34 | `, {}, {}); |
77 | 35 | } |
|
0 commit comments