| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- 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("<p>") + 3;
- const introEnd = item.content.indexOf("</p>");
- 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" }
- }
- ]
- ]
- };
|