build-pipeline.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. const path = require("path");
  2. function getNiceNameFromFilename(filename) {
  3. return (filename.charAt(0).toUpperCase() + filename.slice(1)).replace(
  4. /-/g,
  5. " "
  6. );
  7. }
  8. function meta(config, item, meta) {
  9. const outputDir = path.join(meta.dir.replace(config.baseDir, ""));
  10. return {
  11. ...item,
  12. name: meta.name,
  13. niceName: getNiceNameFromFilename(meta.name),
  14. outputPath: `${path.join(outputDir, meta.name)}`,
  15. outputExtension: ".html"
  16. };
  17. }
  18. function addBlurb(config, item, meta) {
  19. const introStart = item.content.indexOf("<p>") + 3;
  20. const introEnd = item.content.indexOf("</p>");
  21. let cutoff;
  22. if (introEnd - introStart > config.cutoffLength) {
  23. cutoff = item.content.indexOf(".", introStart + config.cutoffLength) + 1;
  24. } else {
  25. cutoff = introEnd;
  26. }
  27. const blurb = item.content.substring(introStart, cutoff);
  28. return {
  29. ...item,
  30. blurb: blurb
  31. };
  32. }
  33. module.exports = {
  34. initialState: [
  35. {
  36. path: "./cv.md",
  37. tags: ["markdown", "content"]
  38. },
  39. {
  40. path: "./styles.css",
  41. tags: ["styles"]
  42. },
  43. {
  44. path: "./template.handlebars",
  45. tags: ["template"]
  46. }
  47. ],
  48. steps: [
  49. [
  50. {
  51. func: "readInFile",
  52. selector: state => state.selectAll()
  53. }
  54. ],
  55. [
  56. {
  57. func: "decorateFileObject",
  58. selector: state => state.selectAll(),
  59. config: {
  60. decorators: [meta]
  61. }
  62. }
  63. ],
  64. [
  65. {
  66. func: "markdownToHtml",
  67. selector: state => state.selectByTag("markdown")
  68. },
  69. {
  70. func: "compileTemplates",
  71. selector: state => state.selectByTag("template")
  72. },
  73. {
  74. func: "copy",
  75. selector: state => state.selectByTag("styles")
  76. }
  77. ],
  78. [
  79. {
  80. func: "renderTemplate",
  81. selector: state =>
  82. state.selectOne(
  83. item => item.tags.includes("markdown") && item.name === "cv"
  84. ),
  85. getConfig: state => ({
  86. meta: {
  87. styles: state.selectOne(item => item.name === "styles")
  88. },
  89. template: state.selectOne(
  90. item => item.tags.includes("template") && item.name === "template"
  91. )
  92. })
  93. }
  94. ],
  95. [
  96. {
  97. func: "writeOutFile",
  98. selector: state => state.selectMany(item => true),
  99. config: { outputDir: "./output" }
  100. }
  101. ]
  102. ]
  103. };