From eccb3cc40e104fffaa89ef62b686659458021298 Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Mon, 3 Jul 2017 01:21:02 -0500 Subject: Fix generator when there are < max posts --- lib/blog.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'lib') 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}`); -- cgit From 2afa1e2b3829d704dd84ad1dce3f00a6996ec4af Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Mon, 3 Jul 2017 01:28:34 -0500 Subject: Substitute markdown for showdown It has better support for code blocks --- lib/blog.js | 5 +++-- package.json | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/blog.js b/lib/blog.js index 3b91943..f31234b 100644 --- a/lib/blog.js +++ b/lib/blog.js @@ -1,11 +1,11 @@ 'use strict'; const Fs = require('fs'); -const Markdown = require('markdown'); const Mustache = require('mustache'); const Ncp = require('ncp'); const Path = require('path'); const Rimraf = require('rimraf'); +const Showdown = require('showdown'); const Util = require('util'); const internals = { @@ -126,8 +126,9 @@ module.exports = class Blog { const postContent = await internals.fs.readFile(postContentPath, { encoding: 'utf8' }); internals.debuglog('Parsing markdown'); + const parser = new Showdown.Converter(); posts.push({ - html: Markdown.markdown.toHTML(postContent), + html: parser.makeHtml(postContent), id: i + 1 }); } diff --git a/package.json b/package.json index e5303b1..4b18dbc 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,11 @@ "homepage": "https://github.com/rbdr/blog#readme", "dependencies": { "getenv": "0.7.x", - "markdown": "0.5.x", "minimist": "1.2.x", "mustache": "2.3.x", "ncp": "2.0.x", - "rimraf": "2.6.x" + "rimraf": "2.6.x", + "showdown": "1.7.x" }, "devDependencies": { "docdash": "0.4.x", -- cgit