const path = require("path"); function getNiceNameFromFilename(filename) { return (filename.charAt(0).toUpperCase() + filename.slice(1)).replace( /-/g, " " ); } function meta(config, item, meta) { const outputDir = path.join(meta.dir.replace(config.baseDir, "")); return { ...item, name: meta.name, niceName: getNiceNameFromFilename(meta.name), outputPath: `${path.join(outputDir, meta.name)}`, outputExtension: ".html" }; } function addBlurb(config, item, meta) { const introStart = item.content.indexOf("
") + 3; const introEnd = item.content.indexOf("
"); let cutoff; if (introEnd - introStart > config.cutoffLength) { cutoff = item.content.indexOf(".", introStart + config.cutoffLength) + 1; } else { cutoff = introEnd; } const blurb = item.content.substring(introStart, cutoff); return { ...item, blurb: blurb }; } module.exports = { initialState: [ { path: "./cv.md", tags: ["markdown", "content"] }, { path: "./styles.css", tags: ["styles"] }, { path: "./template.handlebars", tags: ["template"] } ], steps: [ [ { func: "readInFile", selector: state => state.selectAll() } ], [ { func: "decorateFileObject", selector: state => state.selectAll(), config: { decorators: [meta] } } ], [ { func: "markdownToHtml", selector: state => state.selectByTag("markdown") }, { func: "compileTemplates", selector: state => state.selectByTag("template") }, { func: "copy", selector: state => state.selectByTag("styles") } ], [ { func: "renderTemplate", selector: state => state.selectOne( item => item.tags.includes("markdown") && item.name === "cv" ), getConfig: state => ({ meta: { styles: state.selectOne(item => item.name === "styles") }, template: state.selectOne( item => item.tags.includes("template") && item.name === "template" ) }) } ], [ { func: "writeOutFile", selector: state => state.selectMany(item => true), config: { outputDir: "./output" } }, { func: "writeOutPDF", selector: state => state.selectMany(item => true), config: { outputDir: "./output" } } ] ] };