-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (37 loc) · 1.21 KB
/
index.js
File metadata and controls
48 lines (37 loc) · 1.21 KB
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
/* global hexo */
'use strict';
const {i18n} = require('./i18n')(hexo, __dirname);
function createCoauthorPostMeta(name) {
let coauthors = hexo.theme.config.coauthors || {};
let postMeta = `<span>${name}</span>`;
let coauthor = coauthors[name];
if (!coauthor) return postMeta;
if (coauthor.nick) {
postMeta = `<span>${coauthor.nick}</span>`;
}
if (coauthor.link) {
postMeta = `<a href="${coauthor.link}">${postMeta}</a>`;
}
return postMeta;
}
hexo.extend.helper.register('coauthor_post_meta', function(names) {
if (!Array.isArray(names)) {
return createCoauthorPostMeta(names);
}
return names.map(name => createCoauthorPostMeta(name)).join(' ');
});
hexo.extend.filter.register('theme_inject', function(injects) {
let coauthors = hexo.theme.config.coauthors || {};
i18n('languages', 'coauthor');
injects.postMeta.raw('post-meta-coauthor', `
{%- if post.coauthor %}
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-copyright"></i>
</span>
<span class="post-meta-item-text">{{ __('coauthor') + __('symbol.colon') }}</span>
{{- coauthor_post_meta(post.coauthor) }}
</span>
{%- endif %}
`, {}, {}, coauthors.post_meta_order);
});