Skip to content

Commit

Permalink
Allow non-publication of pages with published: false
Browse files Browse the repository at this point in the history
Closes #15.
  • Loading branch information
David Clark committed Jun 12, 2017
1 parent 4946710 commit c856422
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
20 changes: 18 additions & 2 deletions bin/batfish.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ ${chalk.bold('Shared options')}
${chalk.bold(`${chalk.magenta('start')} options`)}
-p, --port Server port. Default: 8080.
--production Build as though for production.
${chalk.bold(`${chalk.magenta('build')} options`)}
--production Build for production.
-d, --debug Build for debugging, not for production.
${chalk.bold(`${chalk.magenta('serve-static')} options`)}
-p, --port Server port. Default: 8080.
Expand All @@ -57,7 +58,8 @@ const cli = meow(
alias: {
c: 'config',
V: 'verbose',
p: 'port'
p: 'port',
d: 'debug'
},
default: {
config: 'batfish.config.js'
Expand Down Expand Up @@ -87,5 +89,19 @@ try {
cli.showHelp();
}

if (cli.flags.production) {
config = Object.assign({}, config, { production: cli.flags.production });
}

if (cli.flags.debug) {
config = Object.assign({}, config, { production: !cli.flags.debug });
}
if (cli.flags.port) {
config = Object.assign({}, config, { port: cli.flags.port });
}
if (cli.flags.verbose) {
config = Object.assign({}, config, { verbose: cli.flags.verbose });
}

const executeCommand = commands[command];
executeCommand(config);
21 changes: 21 additions & 0 deletions demo/src/pages/posts/three.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*---
title: ThreeThreeThree
description: blah blah blah
published: false
---*/
'use strict';

const React = require('react');
const PageShell = require('../../components/page-shell');

class ThreeThreeThree extends React.Component {
render() {
return (
<PageShell>
ThreeThreeThree
</PageShell>
);
}
}

module.exports = ThreeThreeThree;
4 changes: 4 additions & 0 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const inlineCss = require('./inline-css');
* @return {Promise<void>} - Resolves when the build is complete.
*/
function build(rawConfig) {
if (rawConfig.production === undefined) {
rawConfig = Object.assign({}, rawConfig, { production: true });
}
const batfishConfig = validateConfig(rawConfig);
const outdir = batfishConfig.outputDirectory;

Expand Down Expand Up @@ -75,6 +78,7 @@ function build(rawConfig) {
);
})
.then(() => {
if (!batfishConfig.production) return;
const cssPath = getAssetFilePath(assets.app.css);
return inlineCss(outdir, cssPath);
});
Expand Down
20 changes: 6 additions & 14 deletions lib/get-pages-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let cache;
function getPagesData(batfishConfig) {
if (cache !== undefined) return Promise.resolve(cache);

const pagesGlob = [path.join(batfishConfig.pagesDirectory, '**/*.js')];
const base = batfishConfig.siteBasePath;

// Convert a page's file path to its URL path.
Expand All @@ -43,9 +44,12 @@ function getPagesData(batfishConfig) {

let pagesData = {};
// Returns a data object about a page.
const pageFilePathToData = filePath => {
const registerPage = filePath => {
return pify(fs.readFile)(filePath, 'utf8').then(content => {
const parsedFrontMatter = grayMatter(content, grayMatterOptions);
const published = parsedFrontMatter.data.published !== false;
if (!published && batfishConfig.production) return;

const pagePath = pageFilePathToUrlPath(filePath);
pagesData[pagePath] = {
filePath,
Expand All @@ -55,20 +59,8 @@ function getPagesData(batfishConfig) {
});
};

let pagesGlob = [path.join(batfishConfig.pagesDirectory, '**/*.js')];
// if (batfishConfig.exclude !== undefined && batfishConfig.exclude.length !== 0) {
// // For each exclusion, add a negative glob that will make the path, whether the path corresponds to
// // a specific JS file or to a directory's index.js file.
// pagesGlob = pagesGlob.concat(
// batfishConfig.exclude.map(exclusion => {
// const fileOrDirectory = exclusion.replace(/\/$/, '{.js,/index.js}');
// return `!${path.join(batfishConfig.pagesDirectory, fileOrDirectory)}`;
// })
// );
// }

return globby(pagesGlob)
.then(pageFilePaths => Promise.all(pageFilePaths.map(pageFilePathToData)))
.then(pageFilePaths => Promise.all(pageFilePaths.map(registerPage)))
.then(() => {
cache = pagesData;
return pagesData;
Expand Down

0 comments on commit c856422

Please sign in to comment.