refactor: use cache for blogDatas generation

This commit is contained in:
endiliey 2018-07-30 15:23:56 +08:00
parent f7f063c56e
commit a80399631f
4 changed files with 25 additions and 9 deletions

14
lib/helpers/generate.js Normal file
View file

@ -0,0 +1,14 @@
const path = require('path');
const fs = require('fs-extra');
const genPath = path.resolve(__dirname, '../generated');
fs.ensureDirSync(genPath);
const genCache = new Map();
module.exports = async function(file, content) {
const cached = genCache.get(file);
if (cached !== content) {
await fs.writeFile(path.join(genPath, file), content);
genCache.set(file, content);
}
};

1
lib/helpers/index.js Normal file
View file

@ -0,0 +1 @@
exports.generate = require('./generate');