push
github
2250 of 2356 branches covered (95.5%)
14 of 14 new or added lines in 2 files covered. (100.0%)
8840 of 8917 relevant lines covered (99.14%)
54.13 hits per line
| 1 |
import { Pattern } from 'hexo-util';
|
1✔ |
| 2 |
import * as common from '../../plugins/processor/common'; |
1✔ |
| 3 |
|
1✔ |
| 4 |
function process(file) {
|
|
| 5 |
const Asset = this.model('Asset'); |
14✔ |
| 6 |
const id = file.source.substring(this.base_dir.length).replace(/\\/g, '/'); |
14✔ |
| 7 |
const { path } = file.params;
|
14✔ |
| 8 |
const doc = Asset.findById(id);
|
14✔ |
| 9 |
|
14✔ |
| 10 |
if (file.type === 'delete') { |
|
| 11 |
if (doc) {
|
2✔ |
| 12 |
return doc.remove();
|
2✔ |
| 13 |
} |
2✔ |
| 14 |
|
|
| 15 |
return;
|
× |
| 16 |
} |
× |
| 17 |
|
|
| 18 |
return Asset.save({
|
12✔ |
| 19 |
_id: id,
|
12✔ |
| 20 |
path, |
12✔ |
| 21 |
modified: file.type !== 'skip' |
12✔ |
| 22 |
}); |
12✔ |
| 23 |
} |
12✔ |
| 24 |
|
1✔ |
| 25 |
const pattern = new Pattern(path => { |
|
| 26 |
if (!path.startsWith('source/')) return false; |
|
| 27 |
|
|
| 28 |
path = path.substring(7);
|
16✔ |
| 29 |
if (common.isHiddenFile(path) || common.isTmpFile(path) || path.includes('node_modules')) return false; |
|
| 30 |
|
|
| 31 |
return {path};
|
11✔ |
| 32 |
}); |
1✔ |
| 33 |
|
1✔ |
| 34 |
export const source = { |
1✔ |
| 35 |
pattern, |
1✔ |
| 36 |
process |
1✔ |
| 37 |
}; |
1✔ |