Skip to content

Instantly share code, notes, and snippets.

@walterhiggins
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterhiggins/8706939 to your computer and use it in GitHub Desktop.
Save walterhiggins/8706939 to your computer and use it in GitHub Desktop.
A hypothetical server-side javascript blog-making file.
var fs = require('fs'),
_ = require('underscore'),
markdown = require('markdown').markdown,
tinymake = require('tinymake');
// all posts are .md (markdown files)
var posts = _.filter(fs.readDirSync('posts'), function(name){
return name.match(/\.md$/)
});
var pages = [];
// setup target to build entire blog
tinymake.file (
'blog', // target
pages // source
// targets with no build rule are synthetic
// make('blog') means make all of blog's pages
);
function Markdown2HTML(htmlFile, markdownFiles){
var mdContent = fs.readFileSync( markdownFiles[0], 'utf8' ),
htmlContent = markdown.toHTML(mdContent);
fs.writeFileSync(htmlFile, htmlContent, {encoding: 'utf8'});
}
// setup targets for each .md to be turned into a .html file
_.forEach(posts, function(post){
// posts/blogPost.md => blogPost.html
var page = post
.replace(/\.md$/, '.html')
.replace(/posts\//, '');
tinymake.file(
page, // target
[post], // source
Markdown2HTML // how to build target from source
);
pages.push(page);
});
tinymake.make('blog');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment