-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcode.ts
More file actions
27 lines (22 loc) · 696 Bytes
/
code.ts
File metadata and controls
27 lines (22 loc) · 696 Bytes
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
import type Hexo from '../../hexo';
import Promise from 'bluebird';
import { exists } from 'hexo-fs';
import { CodeSchema } from '../../types';
import type Document from 'warehouse/dist/document';
interface CodeData {
modified: boolean;
data: string;
}
function codeGenerator(this: Hexo): Promise<any[]> {
return Promise.filter(this.model('Code').toArray(), (code: Document<CodeSchema>) => exists(code.source).tap(exist => {
if (!exist) return code.remove();
})).map((code: Document<CodeSchema>) => {
const { path } = code;
const data: CodeData = {
modified: code.modified,
data: code.content
};
return { path, data };
});
}
export = codeGenerator;