push
github
2339 of 2460 branches covered (95.08%)
8396 of 8538 relevant lines covered (98.34%)
55.31 hits per line
1 |
'use strict';
|
|
2 |
|
1✔ |
3 |
const { Pattern } = require('hexo-util');
|
1✔ |
4 |
const { extname } = require('path');
|
1✔ |
5 |
|
1✔ |
6 |
module.exports = ctx => ({ |
|
7 |
pattern: new Pattern('_data/*path'), |
68✔ |
8 |
|
68✔ |
9 |
process: function dataProcessor(file) { |
|
10 |
const Data = ctx.model('Data');
|
5✔ |
11 |
const { path } = file.params; |
5✔ |
12 |
const id = path.substring(0, path.length - extname(path).length);
|
5✔ |
13 |
const doc = Data.findById(id); |
5✔ |
14 |
|
5✔ |
15 |
if (file.type === 'skip' && doc) { |
|
16 |
return;
|
× |
17 |
} |
× |
18 |
|
5✔ |
19 |
if (file.type === 'delete') { |
|
20 |
if (doc) {
|
1✔ |
21 |
return doc.remove();
|
1✔ |
22 |
} |
1✔ |
23 |
|
|
24 |
return;
|
× |
25 |
} |
× |
26 |
|
|
27 |
return file.render().then(result => {
|
|
28 |
if (result == null) return; |
|
29 |
|
4✔ |
30 |
return Data.save({
|
4✔ |
31 |
_id: id,
|
4✔ |
32 |
data: result
|
4✔ |
33 |
}); |
4✔ |
34 |
}); |
4✔ |
35 |
} |
5✔ |
36 |
}); |
1✔ |