Compiler object is created properly
This commit is contained in:
parent
c8f23483e8
commit
782ebb3b4b
|
@ -36,7 +36,7 @@ function fileMetadata(filepath) {
|
|||
return metadata;
|
||||
}
|
||||
|
||||
module.exports = function Compiler(data) {
|
||||
function Compiler(data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ Compiler.prototype.addFile = function (filepath) {
|
|||
summary: frontMatter.attributes.summary,
|
||||
};
|
||||
|
||||
const renderedpath = path.join(config.renderPath, `${metadata.filename}.html`);
|
||||
const renderedpath = path.join(process.cwd(), config.renderPath, `${metadata.filename}.html`);
|
||||
|
||||
this.data.posts.push(post);
|
||||
writeRenderedFile(renderedpath, rendered);
|
||||
|
@ -68,8 +68,10 @@ Compiler.prototype.addFile = function (filepath) {
|
|||
};
|
||||
|
||||
Compiler.prototype.writeData = function () {
|
||||
const dataPath = path.join(process.cwd(), 'server/utils/data.json');
|
||||
jsonfile.writeFile(dataPath, data, (err) => {
|
||||
const dataPath = path.join(process.cwd(), 'src/utils/data.json');
|
||||
jsonfile.writeFile(dataPath, this.data, (err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Compiler;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"posts":[]}
|
|
@ -1,15 +1,18 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Compiler = require('./compiler');
|
||||
const config = require('../static/config/config.json');
|
||||
const data = require('./data.json');
|
||||
|
||||
module.exports = function() {
|
||||
|
||||
var compiler = Compiler(data);
|
||||
console.log(data);
|
||||
var compiler = new Compiler(data);
|
||||
|
||||
fs.readdir(config.contentPath, (err, files) => {
|
||||
files.forEach(file => {
|
||||
compiler.addFile(file);
|
||||
const filePath = path.join(process.cwd(), config.contentPath, file);
|
||||
compiler.addFile(filePath);
|
||||
});
|
||||
compiler.writeData();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue