-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathhexo.ts
39 lines (32 loc) · 862 Bytes
/
hexo.ts
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
import Hexo from 'hexo';
import fs from 'fs'
import {join} from 'path'
let __SECRET_HEXO_INSTANCE__: Hexo | null = null;
const initHexo = async () => {
if (__SECRET_HEXO_INSTANCE__) {
return __SECRET_HEXO_INSTANCE__;
}
const hexo = new Hexo(process.cwd(), {
silent: true,
// 在 next dev 时包含草稿
draft: process.env.NODE_ENV !== 'production'
});
const dbPath = join(hexo.base_dir, 'db.json');
if (process.env.NODE_ENV !== 'production') {
if (fs.existsSync(dbPath)) {
await fs.promises.unlink(dbPath);
}
}
await hexo.init();
await hexo.load();
if (hexo.env.init && hexo._dbLoaded) {
if (!fs.existsSync(dbPath)) {
if (process.env.NODE_ENV === 'production') {
await hexo.database.save();
}
}
}
__SECRET_HEXO_INSTANCE__ = hexo;
return hexo;
};
export default initHexo