Permalink
Browse files

Add render pipelines, add bin

  • Loading branch information...
1 parent edb5083 commit 494e06e1659add53df2af9aae90da587d8cbe5f7 @mixu committed Oct 5, 2014
Showing with 411 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 .jshintignore
  3. +19 −0 bin/default-config.json
  4. +132 −0 bin/ghost-render
  5. +1 −0 bin/usage.txt
  6. +2 −0 index.js
  7. +15 −0 lib/md/annotate-md-headings.js
  8. +21 −0 lib/md/highlight-js.js
  9. +2 −0 lib/md/index.js
  10. +215 −0 lib/pipelines.js
  11. +2 −0 package.json
View
@@ -1,2 +1,3 @@
node_modules/
tmp/
+settings.json
View
@@ -0,0 +1 @@
+node_modules/
@@ -0,0 +1,19 @@
+{
+ "blog": {
+ "url": "http://localhost:5000",
+ "title": "BLOG TITLE",
+ "description": "BLOG DESCRIPTION",
+ "logo": "http://lorempixel.com/45/45/abstract/",
+ "cover": "http://lorempixel.com/1100/425/nature/"
+ },
+ "authors": {
+ "default": {
+ "name": "AUTHOR NAME",
+ "bio": "AUTHOR BIO",
+ "website": "http://localhost:5000/author/foo",
+ "image": "http://lorempixel.com/155/155/people/",
+ "cover": "http://lorempixel.com/1100/425/animals/",
+ "slug": "foo"
+ }
+ }
+}
View
@@ -0,0 +1,132 @@
+#!/usr/bin/env node
+var fs = require('fs'),
+ path = require('path'),
+ subarg = require('subarg');
+
+var argv = subarg(process.argv.slice(2));
+
+// defaults
+
+var config = { };
+
+if (argv.init) {
+ console.log(fs.readFileSync(__dirname + '/default-config.json').toString());
+ process.exit();
+ return;
+}
+
+if (argv.help) {
+ console.log(fs.readFileSync(__dirname + '/usage.txt').toString());
+ process.exit();
+ return;
+}
+
+if (argv.settings) {
+ var settingsPath = path.resolve(process.cwd(), argv.settings);
+ var loaded = require(settingsPath);
+
+ // resolve relative to the config file location
+ ['input', 'output', 'theme'].forEach(function(key) {
+ loaded[key] = path.resolve(path.dirname(settingsPath), loaded[key]);
+ });
+
+ Object.keys(loaded).forEach(function(key) {
+ // loaded file overrides all values that were not set yet
+ if (typeof config[key] === 'undefined') {
+ config[key] = loaded[key];
+ }
+ });
+} else {
+ console.log('The --settings command line argument is required.');
+ process.exit();
+ return;
+}
+
+if (!config.input) {
+ config.input = path.resolve(process.cwd(), argv.input || './input/');
+}
+if (!config.output) {
+ config.output = path.resolve(process.cwd(), argv.output || './output/');
+}
+if (!config.theme) {
+ console.log('The --theme command line argument is required.');
+ return;
+}
+
+// process
+
+var pi = require('pipe-iterators'),
+ through = require('through2'),
+ glob = require('wildglob');
+
+var stream = require('../index.js').stream,
+ Theme = require('../index.js').Theme;
+ md = require('../index.js').md;
+
+var templatePath = config.theme,
+ assetPath = config.theme + '/assets';
+
+var meta = { blog: config.blog, authors: config.authors },
+ theme = new Theme({
+ templatePath: templatePath,
+ meta: meta
+});
+
+var pipelines = require('../index.js').pipelines(theme, config.input, config.output);
+
+glob.stream(config.input + '/**')
+ .pipe(pi.pipeFirst([
+ stream.read(),
+ md.parseHeader(),
+ md.parseMd(),
+ md.annotateMdHeadings(),
+
+ // add helper + template that uses the headings
+
+ md.highlightJs(),
+ md.convertMd(),
+
+ stream.fileToPost(meta, config.input),
+ stream.parsePublishedAt(),
+ stream.parseTags(),
+ stream.sortByPublishedAt(),
+
+ pi.fork(pipelines.page),
+
+ // no drafts, no pages past this point
+ pi.filter(function(post) { return !post.draft && !post.page; }),
+
+ pi.fork(
+ pipelines.post,
+ pipelines.index,
+ pipelines.postRSS,
+
+ pi.pipeFirst([
+ stream.groupByTag(),
+ pi.fork(
+ pipelines.tag,
+ pipelines.tagRSS
+ )
+ ]),
+ pi.pipeFirst([
+ stream.groupByAuthor(),
+ pi.fork(
+ pipelines.author,
+ pipelines.authorRSS
+ )
+ ])
+ )
+]));
+
+// copy assets
+glob.stream(assetPath + '/**' )
+ .pipe(stream.read())
+ .pipe(pi.mapKey('path', function(p) { return path.normalize(p.replace(assetPath, config.output + '/assets/')); }))
+ .pipe(pi.forEach(function(obj) { console.log('write theme asset:', obj.path); }))
+ .pipe(stream.dest());
+
+glob.stream(__dirname + '/public/assets/**' )
+ .pipe(stream.read())
+ .pipe(pi.mapKey('path', function(p) { return path.normalize(p.replace(__dirname + '/public/assets/', config.output + '/assets/')); }))
+ .pipe(pi.forEach(function(obj) { console.log('write base asset:', obj.path); }))
+ .pipe(stream.dest());
View
@@ -0,0 +1 @@
+TODO
View
@@ -1,2 +1,4 @@
exports.Theme = require('./lib/theme');
exports.stream = require('./lib/stream');
+exports.md = require('./lib/md');
+exports.pipelines = require('./lib/pipelines');
@@ -0,0 +1,15 @@
+var through = require('through2');
+
+module.exports = function() {
+ return through.obj(function annotateMarkdownHeadings(file, enc, onDone) {
+ // file content is lexer output
+ file.headings = file.contents.filter(function(token) {
+ return token.type == 'heading';
+ }).map(function(token) {
+ token.id = token.text.toLowerCase().replace(/[^a-z0-9]/g, '_');
+ return token;
+ });
+ this.push(file);
+ onDone();
+ });
+};
@@ -0,0 +1,21 @@
+var hljs = require('highlight.js'),
+ through = require('through2');
+
+
+function hl(code, lang) {
+ return '<pre class="hljs"><code>' + hljs.highlightAuto(code).value + '</code></pre>';
+}
+
+module.exports = function() {
+ // code highlighting on lexer output
+ return through.obj(function(file, enc, onDone) {
+ file.contents.forEach(function(token, index) {
+ if(token.type != 'code') {
+ return;
+ }
+ file.contents[index] = { type: 'html', pre: false, text: hl(token.text, token.lang) };
+ });
+ this.push(file);
+ onDone();
+ });
+};
View
@@ -1,3 +1,5 @@
+exports.annotateMdHeadings = require('./annotate-md-headings');
+exports.highlightJs = require('./highlight-js');
exports.parseHeader = require('./parse-header');
exports.parseMd = require('./parse-md');
exports.convertMd = require('./convert-md');
Oops, something went wrong.

0 comments on commit 494e06e

Please sign in to comment.