| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- const typeDecorator = require("./decorators/typeDecorator");
- const outputDecorator = require("./decorators/outputDecorator");
- const articleDecorator = require("./decorators/articleDecorator");
- function toNameContentObject(items) {
- return items.reduce(
- (contentObject, item) =>
- Object.assign({}, contentObject, {
- [item.name]: item.content
- }),
- {}
- );
- }
- module.exports = {
- steps: [
- [
- {
- func: "rmrf",
- item: {
- path: "./output/*"
- }
- }
- ],
- [
- {
- name: "Read in markdown for index",
- func: "listDirectory",
- selector: state => [
- { path: "./content", tags: ["markdown"], outputExtension: ".html" },
- { path: "./images" },
- { path: "./static" },
- { path: "./styles", outputExtension: ".css" },
- { path: "./partials" },
- { path: "./helpers" },
- { path: "./fonts" },
- { path: "./js", outputExtension: ".js" },
- { path: "./pages" }
- ]
- }
- ],
- [
- {
- func: "decorateFileObject",
- selector: state => state.selectAll(),
- config: {
- decorators: [typeDecorator],
- defaultName: "Home"
- }
- }
- ],
- [
- {
- func: "decorateFileObject",
- selector: state =>
- state
- .matchingAnyTag(["fonts", "content", "js", "styles"])
- .and(state.selectByTag("images").not(state.selectByTag("favicon"))),
- config: {
- decorators: [outputDecorator],
- baseDir: "content"
- }
- },
- {
- func: "decorateFileObject",
- selector: state => state.selectByTag("favicon"),
- config: {
- decorators: [outputDecorator],
- baseDir: "images",
- outputExtension: ".ico"
- }
- },
- {
- func: "decorateFileObject",
- selector: state => state.selectByTag("static"),
- config: {
- decorators: [outputDecorator],
- baseDir: "static"
- }
- },
- {
- func: "copy",
- selector: state =>
- state.matchingAnyTag(["helpers", "partials", "svgs", "pages"])
- }
- ],
- [
- {
- func: "copyFileTo",
- selector: state => state.matchingAnyTag(["fonts", "static"]),
- config: { outputDir: "./output" }
- },
- {
- func: "imageMin",
- allowEmpty: true,
- selector: state =>
- state.selectByTag("images").not(state.selectByTag("svgs")),
- config: {
- outputDir: "./output"
- }
- },
- {
- func: "readInFile",
- selector: state => {
- return state.not(
- state
- .selectByTag("images")
- .not(state.selectByTag("svgs").and(state.selectByTag("fonts")))
- );
- }
- }
- ],
- [
- {
- func: "markdownToHtml",
- selector: state => state.selectByTag("markdown")
- },
- {
- func: "compileTemplates",
- selector: state => state.selectByTag("pages"),
- getConfig: state => ({
- partials: state.selectByTag("partials"),
- helpers: state.selectByTag("helpers")
- })
- },
- {
- func: "copy",
- selector: state => state.matchingAnyTag(["styles", "svgs", "js"])
- }
- ],
- [
- {
- func: "decorateFileObject",
- selector: state =>
- state
- .selectByTag("content")
- .selectByTag("markdown")
- .not(state.selectByTag("index")),
- config: {
- decorators: [articleDecorator],
- cutoffLength: 180
- }
- },
- {
- func: "copy",
- selector: state => {
- return state.matchingAnyTag([
- "pages",
- "styles",
- "svgs",
- "index",
- "work",
- "js"
- ]);
- }
- }
- ],
- [
- {
- func: "renderTemplate",
- deferConfig: true,
- selector: state => state.selectByTag("content"),
- getConfig: (state, currentItem) => {
- const matchingTemplate = state
- .selectByTag("pages")
- .mostMatchingTags(currentItem.tags);
- console.log(
- `Rendering ${currentItem.dir}/${currentItem.name} with ${
- matchingTemplate.dir
- }/${matchingTemplate.name}`
- );
- const entries = state
- .selectByTag("content")
- .selectByTag("markdown")
- .matchingAllTags(currentItem.dirPath)
- .not(state.selectByTag("index"))
- .selectMany(item => item.depth <= currentItem.depth);
- const sections = state
- .matchingAllTags(currentItem.dirPath)
- .selectByTag("index")
- .not([currentItem])
- .selectMany(item => item.depth <= currentItem.depth + 1);
- const isIndex = currentItem.tags.includes("index");
- return {
- meta: {
- title: currentItem.niceName,
- name: currentItem.name,
- now: new Date().toLocaleString(),
- context: currentItem.dirPath[1],
- isIndex: isIndex,
- svgs: toNameContentObject(state.selectByTag("svgs")),
- partials: toNameContentObject(state.selectByTag("partials")),
- entries: entries,
- sections: sections,
- trail: [...currentItem.dirPath.slice(1), currentItem.name]
- },
- template: matchingTemplate
- };
- }
- },
- {
- func: "copy",
- selector: state =>
- state.selectByTag("styles").and(state.selectByTag("js"))
- }
- ],
- [
- {
- func: "minifyHtml",
- selector: state => state.selectAll().not(state.selectByTag("js"))
- },
- {
- func: "minifyJS",
- selector: state => state.selectByTag("js")
- }
- ],
- [
- {
- func: "writeOutFile",
- selector: state => state.selectAll(),
- config: { outputDir: "./output" }
- }
- ]
- ]
- };
|