aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Beltran <ben@nsovocal.com>2017-07-03 01:21:02 -0500
committerBen Beltran <ben@nsovocal.com>2017-07-03 01:21:02 -0500
commiteccb3cc40e104fffaa89ef62b686659458021298 (patch)
tree9663d23b2aec5ce4d622b44947d1cc89d50ec6d9 /lib
parent5e265f9d81bcce30949e88850892ea5dacec7386 (diff)
Fix generator when there are < max posts
Diffstat (limited to 'lib')
-rw-r--r--lib/blog.js35
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/blog.js b/lib/blog.js
index 483577f..3b91943 100644
--- a/lib/blog.js
+++ b/lib/blog.js
@@ -112,20 +112,33 @@ module.exports = class Blog {
for (let i = 0; i < this.maxPosts; ++i) {
const sourcePath = Path.join(this.postsDirectory, `${i}`);
- const assetsSource = Path.join(sourcePath, internals.kAssetsDirectoryName);
- const postContentPath = await this._findBlogContent(sourcePath);
- internals.debuglog(`Copying ${assetsSource} to ${assetsTarget}`);
- await internals.ncp(assetsSource, assetsTarget);
+ try {
+ await internals.fs.access(this.postsDirectory);
+
+ const assetsSource = Path.join(sourcePath, internals.kAssetsDirectoryName);
+ const postContentPath = await this._findBlogContent(sourcePath);
+
+ internals.debuglog(`Copying ${assetsSource} to ${assetsTarget}`);
+ await internals.ncp(assetsSource, assetsTarget);
- internals.debuglog(`Reading ${postContentPath}`);
- const postContent = await internals.fs.readFile(postContentPath, { encoding: 'utf8' });
+ internals.debuglog(`Reading ${postContentPath}`);
+ const postContent = await internals.fs.readFile(postContentPath, { encoding: 'utf8' });
- internals.debuglog('Parsing markdown');
- posts.push({
- html: Markdown.markdown.toHTML(postContent),
- id: i + 1
- });
+ internals.debuglog('Parsing markdown');
+ posts.push({
+ html: Markdown.markdown.toHTML(postContent),
+ id: i + 1
+ });
+ }
+ catch (error) {
+ if (error.code === internals.kFileNotFoundError) {
+ internals.debuglog(`Skipping ${i}`);
+ continue;
+ }
+
+ throw error;
+ }
}
internals.debuglog(`Reading ${indexLocation}`);