-
Notifications
You must be signed in to change notification settings - Fork 18
/
data.js
69 lines (47 loc) · 1.5 KB
/
data.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
64
65
66
67
68
69
const { VEvent } = require('icalendar'),
type_map = {
doc: 'word',
docx: 'word',
xls: 'excel',
xlsx: 'excel',
ppt: 'powerpoint',
pptx: 'powerpoint'
};
function has_category(post, name) {
return Array.from(
(post.categories || '').data, ({ name }) => name
).includes( name )
}
module.exports = function (hexo) {
hexo.extend.helper.register('has_category', has_category);
hexo.extend.helper.register('file_type', path => {
var type = path.split('.');
if (! type[1]) return;
type = type.slice(-1)[0].toLowerCase();
return type_map[type] || type;
});
hexo.extend.helper.register('toDataURI', (data, type = '') =>
`data:${type};base64,${Buffer.from( data ).toString('base64')}`
);
hexo.extend.helper.register(
'eventOf', (title, description, start, end, location) => {
const event = new VEvent();
event.setSummary( title );
event.setDescription( description );
event.setDate(new Date(start), new Date(end));
event.setLocation( location );
return event;
}
);
const url_for = hexo.extend.helper.get('url_for');
hexo.extend.helper.register('partner_list', function (posts) {
return posts.map(({categories, source, title, path, thumbnail}) =>
has_category({ categories }, 'Partner') && {
name: source.match( /([^/\\]+)\.\w+$/i )[1],
title,
logo: url_for.call(this, path + thumbnail),
URL: url_for.call(this, path)
}
).filter(Boolean)
});
};