From 1d4501d41a0ebb32a8b9a8119e899688a34b3fe7 Mon Sep 17 00:00:00 2001 From: "Jocelyn Badgley (Twipped)" Date: Tue, 7 Apr 2020 10:35:32 -0700 Subject: [PATCH] Pages only task for faster iterative builds --- build/index.js | 31 +++++++++++++++++++++++++++++++ gulp/index.js | 8 +++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/build/index.js b/build/index.js index 216864b..68721a5 100644 --- a/build/index.js +++ b/build/index.js @@ -82,6 +82,37 @@ exports.everything = function (prod = false) { return fn; }; +exports.posts = function () { + async function fn () { + const prod = false; + // load a directory scan of the public and post folders + const [ PublicFiles, PostFiles ] = await Promise.all([ + loadPublicFiles(), + loadPostFiles(), + ]); + + // load data for all the files in that folder + await Promise.map(PublicFiles.assets, (p) => p.load()); + await Promise.map(PublicFiles.pages, (p) => p.load(PublicFiles)); + + await Promise.map(PostFiles.assets, (p) => p.load()); + await Promise.map(PostFiles.pages, (p) => p.load(PostFiles)); + + // prime tweet data for all pages + const pages = await primeTweets(PublicFiles.pages.filter((p) => !p.meta.ignore)); + + let posts = await primeTweets(PostFiles.pages.filter((p) => !p.meta.ignore)); + posts = sortBy(posts, 'date'); + posts.reverse(); + + const engines = await getEngines(prod); + const postIndex = await pageWriter(prod, engines, pages, posts); + await fs.writeFile(resolve('dist/tweets/index.json'), prod ? JSON.stringify(postIndex) : JSON.stringify(postIndex, null, 2)); + } + + fn.displayName = 'buildPages'; + return fn; +}; exports.task = function (action, prod = false) { const fn = async () => { diff --git a/gulp/index.js b/gulp/index.js index b8fadd5..0feb2dc 100644 --- a/gulp/index.js +++ b/gulp/index.js @@ -7,6 +7,8 @@ var build = require('../build'); const devBuildTask = build.everything(); const prodBuildTask = build.everything(true); +const pagesTask = build.pages(); +exports.pages = () => pagesTask(); const scss = exports.scss = build.task('scss'); const favicon = exports.favicon = build.task('favicon'); @@ -41,10 +43,10 @@ exports.testpush = pushToProd.dryrun; function watcher () { watch([ - 'public/**/*', - 'posts/**/*', + 'public/**/*.{md,hbs,html}', + 'posts/**/*.{md,hbs,html}', 'templates/*.{md,hbs,html}', - ], devBuildTask); + ], pagesTask); watch([ 'scss/*.scss',