-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (23 loc) · 747 Bytes
/
index.js
File metadata and controls
29 lines (23 loc) · 747 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
28
29
'use strict';
const { parse } = require('yaml');
const fs = require('fs');
const path = require('path');
const { deepMerge } = require('hexo-util');
class Util {
constructor(hexo, pluginDir) {
this.hexo = hexo;
this.pluginDir = pluginDir;
}
getFilePath(file) {
return this.pluginDir ? path.resolve(this.pluginDir, file) : file;
}
getFileContent(file) {
return fs.readFileSync(this.getFilePath(file), 'utf8');
}
defaultConfigFile(key, file) {
const defaultConfig = file ? parse(this.getFileContent(file)) : {};
this.hexo.config[key] = deepMerge(defaultConfig[key], deepMerge(this.hexo.theme.config[key] || {}, this.hexo.config[key] || {}));
return this.hexo.config[key];
}
}
module.exports = Util;