Browse files

articles somewhat working now

  • Loading branch information...
1 parent dcb246f commit fefa5a084b3359239f0d94386ec9171b80b262bc @frodare committed Sep 13, 2012
Showing with 519 additions and 460 deletions.
  1. +2 −2 LICENSE
  2. +14 −8 index.js
  3. +116 −127 lib/content.js
  4. +387 −323 lib/renderers.js
View
4 LICENSE
@@ -1,6 +1,6 @@
-Wheat is Distributed under the MIT License
+Barley is Distributed under the MIT License
-Copyright (c) 2010 Tim Caswell <tim@creationix.com>
+Copyright (c) 2012 Charles Howard <frodare@gmail.com>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
View
22 index.js
@@ -35,7 +35,7 @@ module.exports = function(root, options) {
console.log('launching Barley! ROOT[' + root + ']');
- content(root);
+ var contentGet = content(root).get;
function addRoute(regex, renderer) {
routes.push({
@@ -45,17 +45,23 @@ module.exports = function(root, options) {
}
function handleRoute(req, res, next, rendererName, match) {
- console.log('render name: ' + rendererName);
- var dfd = renderers[rendererName]();
- dfd.done(function(err, data) {
- if (err) {
+ contentGet().done(function (catalog) {
+
+ var dfd = renderers[rendererName](catalog);
+
+ dfd.done(function(data) {
+ res.writeHead(200, data.headers);
+ res.end(data.buffer);
+ }).fail(function (err) {
console.log('renderer ' + rendererName + ' error: ' + err);
return err.errno === process.ENOENT ? next() : next(err);
- }
- res.writeHead(200, data.headers);
- res.end(data.buffer);
+ });
});
+
+
+
+
}
function determineRoute(req) {
View
243 lib/content.js
@@ -3,74 +3,14 @@
*/
var fs = require('fs');
-var Deferred = require("JQDeferred");
+var jq = require("jquery-deferred");
+
module.exports = function(root) {
'use strict';
- console.log('starting upt content on: ' + root);
-
-
- /*
- * the blog catalog, a complete itemized list of articles
- * and meta information
- */
- var catalog = {
- /*
- * map of all the articles
- */
- articles: {},
- /*
- * sorted array of all article names
- */
- articleOrder: []
- };
-
- /*
- * filesystem calls wrapped in Deferreds
- */
- /*
- function stat(path) {
- var dfd = new Deferred();
- fs.stat(path, function(err, stats) {
- if (err) {
- dfd.reject(err);
- } else {
- dfd.resolve(stats);
- }
- });
- return dfd;
- }
-
-
- function readdir(path) {
- var dfd = new Deferred();
- fs.readdir(path, function(err, files) {
- if (err) {
- dfd.reject(err);
- } else {
- dfd.resolve(files);
- }
- });
- return dfd;
- }
-
-
- function readFile(path) {
- var dfd = new Deferred();
- fs.readFile(path, function(err, files) {
- if (err) {
- dfd.reject(err);
- } else {
- dfd.resolve(files);
- }
- });
- return dfd;
- }
- */
-
function fsDfd(command) {
- var dfd = new Deferred();
+ var dfd = jq.Deferred();
var i;
var args = [];
@@ -95,109 +35,158 @@ module.exports = function(root) {
return dfd;
}
+ function readFile(filename) {
+ return fsDfd('readFile', filename);
+ }
+ function readdir(dirname) {
+ return fsDfd('readdir', dirname);
+ }
- /*
- * set the root
- */
- var init = function(root) {
- //console.log('content read');
- };
-
+ function processArticle(filename, file, catalog) {
+
+ /*
+ * convert buffer to string
+ */
+ if (typeof file !== 'string') {
+ file = file.toString();
+ }
- /*
- * read the meta data (key/value headers) from the top of the article file
- */
+ /*
+ * compute the name
+ */
+ var name = filename.replace(/\.markdown$/, '');
- function processMetaData(file) {
- var meta = {};
+ var article = {};
+ /*
+ * parse the headers
+ */
while (true) {
var match = file.match(/^([a-z]+):\s*(.*)\s*\n/i);
- if(!match){
+ if (!match) {
break;
}
- meta[match[1].toLowerCase()] = match[2];
+ article[match[1].toLowerCase()] = match[2];
file = file.substr(match[0].length);
}
- return meta;
- }
+ /*
+ * add the rest of the file as the article content
+ */
+ article.content = file;
+ /*
+ * push this article onto the articles array
+ */
+ article.name = name;
+ catalog.articleIndex[name] = article;
+ catalog.articles.push(article);
- function processArticle(filename) {
+ return article;
+ }
- console.log('loading : ' + filename);
+ function readAuthors(catalog) {
+ var dfd = jq.Deferred();
+ catalog.athors = [];
+ return dfd.resolve();
+ }
+ function readArticles(catalog) {
+ var dfd = jq.Deferred();
+ catalog.articles = [];
+ catalog.articleIndex = {};
- return fsDfd('readFile', root + '/articles/' + filename).pipe(function(file) {
-
- /*
- * convert buffer to string
- */
- if (typeof file !== 'string') {
- file = file.toString();
- }
+ /*
+ * read and process all article files
+ */
+ readdir(root + '/articles').done(function(files) {
+ var aDfd = [];
- var article = {};
+ files.forEach(function(filename) {
+ /*
+ * ignore non markdown files
+ */
+ if (!(/\.markdown$/.test(filename))) {
+ return;
+ }
- article.name = filename.replace(/\.markdown$/, '');
- article.meta = processMetaData(file);
- catalog.articles[article.name] = article;
+ /*
+ * load the article
+ */
+ var articleDfd = readFile(root + '/articles/' + filename);
- console.log(article.name + 'complete');
+ /*
+ * process
+ */
+ articleDfd.done(function (file) {
+ processArticle(filename, file, catalog);
+ });
- //console.log(catalog);
- //return article;
+ aDfd.push(articleDfd);
+ });
+ /*
+ * wait for all articles to process
+ */
+ jq.when.apply(null, aDfd).done(function() {
+ dfd.resolve();
+ }).fail(function() {
+ dfd.reject();
+ });
});
+ /*
+ * Sort Articles:
+ * build the articleOrder array
+ */
+ dfd.done(function() {
+ catalog.articles.sort(function dateSorter(a, b) {
+ return (Date.parse(b.date)) - (Date.parse(a.date));
+ });
+ });
+
+ return dfd;
}
+
/*
* update the catalog
*/
var read = function() {
-
- var aDfd = [];
-
- /*
- * read article files
- */
- aDfd.push(fsDfd('readdir', root + '/articles').done(function(files) {
- var i;
- var l = files.length;
-
-
- for (i = 0; i < l; i++) {
-
- if (/\.markdown$/.test(files[i])) {
- aDfd.push(processArticle(files[i]));
- }
-
- }
-
- console.log(aDfd);
- }));
+ var catalog = {};
/*
- * read author files
+ * first build the authors
*/
-
- console.log(aDfd);
-
- Deferred.when.apply(null, aDfd).done(function () {
- console.log('Content Read Complete');
- console.log(catalog);
+ return readAuthors(catalog).pipe(function () {
+ /*
+ * then build the articles
+ */
+ return readArticles(catalog);
+ }).pipe(function () {
+ /*
+ * finally return the completed catalog
+ */
+ return catalog;
});
};
+ var readCache;
+ function get () {
+ if(readCache){
+ return readCache;
+ }
+ readCache = read();
+ return readCache;
+ }
+ get();
- read();
-
- return catalog;
+ return {
+ get: get
+ };
};
View
710 lib/renderers.js
@@ -1,347 +1,411 @@
var Git = require('git-fs'),
- Data = require('./wheat/data'),
- Tools = require('./wheat/tools'),
- Buffer = require('buffer').Buffer,
- Prettify = require('./wheat/prettify'),
- Crypto = require('crypto'),
- ChildProcess = require('child_process'),
- getMime = require('simple-mime')('application/octet-string'),
- Step = require('step'),
- Deferred = require("JQDeferred");
+ Data = require('./wheat/data'),
+ Tools = require('./wheat/tools'),
+ Buffer = require('buffer').Buffer,
+ Prettify = require('./wheat/prettify'),
+ Crypto = require('crypto'),
+ ChildProcess = require('child_process'),
+ getMime = require('simple-mime')('application/octet-string'),
+ Step = require('step'),
+ jq = require("jquery-deferred"),
+ Haml = require('haml');
// Execute a child process, feed it a buffer and get a new buffer filtered.
-
function execPipe(command, args, data, callback) {
- var child = ChildProcess.spawn(command, args);
- var stdout = [],
- stderr = [],
- size = 0;
- child.stdout.on('data', function onStdout(buffer) {
- size += buffer.length;
- stdout[stdout.length] = buffer;
- });
- child.stderr.on('data', function onStderr(buffer) {
- stderr[stderr.length] = buffer;
- });
- child.on('error', function onExit(err) {
- callback(err);
- });
- var exitCode;
- child.on('exit', function onExit(code) {
- exitCode = code;
- });
- child.on('close', function() {
- if (exitCode > 0) {
- callback(new Error(stderr.join("")));
- } else {
- var buffer = new Buffer(size);
- var start = 0;
- for (var i = 0, l = stdout.length; i < l; i++) {
- var chunk = stdout[i];
- chunk.copy(buffer, start);
- start += chunk.length;
- }
- callback(null, buffer);
- }
- });
- if (typeof data === 'string') {
- child.stdin.write(data, "binary");
- } else {
- child.stdin.write(data);
- }
- child.stdin.end();
+ var child = ChildProcess.spawn(command, args);
+ var stdout = [],
+ stderr = [],
+ size = 0;
+ child.stdout.on('data', function onStdout(buffer) {
+ size += buffer.length;
+ stdout[stdout.length] = buffer;
+ });
+ child.stderr.on('data', function onStderr(buffer) {
+ stderr[stderr.length] = buffer;
+ });
+ child.on('error', function onExit(err) {
+ callback(err);
+ });
+ var exitCode;
+ child.on('exit', function onExit(code) {
+ exitCode = code;
+ });
+ child.on('close', function() {
+ if (exitCode > 0) {
+ callback(new Error(stderr.join("")));
+ } else {
+ var buffer = new Buffer(size);
+ var start = 0;
+ for (var i = 0, l = stdout.length; i < l; i++) {
+ var chunk = stdout[i];
+ chunk.copy(buffer, start);
+ start += chunk.length;
+ }
+ callback(null, buffer);
+ }
+ });
+ if (typeof data === 'string') {
+ child.stdin.write(data, "binary");
+ } else {
+ child.stdin.write(data);
+ }
+ child.stdin.end();
}
// This writes proper headers for caching and conditional gets
// Also gzips content if it's text based and stable.
-
function postProcess(headers, buffer) {
- 'use strict';
-
- if (!headers["Content-Type"]) {
- headers["Content-Type"] = "text/html; charset=utf-8";
- }
-
- var date = new Date().toUTCString();
- headers.Date = date;
- headers.Server = "barley, mmmm beer (node.js)";
-
- /*
- if (version === 'fs') {
- delete headers["Cache-Control"];
- } else {
- var hash = Crypto.createHash('md5');
- hash.update(version + ":" + path + ":" + date);
- headers.ETag = hash.digest('hex');
- }
- */
-
- /*
- if (/html/.test(headers["Content-Type"])) {
- buffer = Tools.stringToBuffer((buffer + "").replace(/<pre><code>[^<]+<\/code><\/pre>/g, function applyHighlight(code) {
- code = code.match(/<code>([\s\S]+)<\/code>/)[1];
- code = Prettify.prettyPrintOne(code);
- return "<pre><code>" + code + "</code></pre>";
- }));
- }
- */
-
- headers["Content-Length"] = buffer.length;
-
- return {
- headers: headers,
- buffer: buffer
- };
-
+ 'use strict';
+
+ if (!headers["Content-Type"]) {
+ headers["Content-Type"] = "text/html; charset=utf-8";
+ }
+
+ var date = new Date().toUTCString();
+ headers.Date = date;
+ headers.Server = "barley, mmmm beer (node.js)";
+
+ /*
+ if (version === 'fs') {
+ delete headers["Cache-Control"];
+ } else {
+ var hash = Crypto.createHash('md5');
+ hash.update(version + ":" + path + ":" + date);
+ headers.ETag = hash.digest('hex');
+ }
+ */
+
+ /*
+ if (/html/.test(headers["Content-Type"])) {
+ buffer = Tools.stringToBuffer((buffer + "").replace(/<pre><code>[^<]+<\/code><\/pre>/g, function applyHighlight(code) {
+ code = code.match(/<code>([\s\S]+)<\/code>/)[1];
+ code = Prettify.prettyPrintOne(code);
+ return "<pre><code>" + code + "</code></pre>";
+ }));
+ }
+ */
+
+ headers["Content-Length"] = buffer.length;
+
+ return {
+ headers: headers,
+ buffer: buffer
+ };
+
}
function insertSnippets(markdown, snippets, callback) {
- Step(
-
- function() {
- Tools.compileTemplate('snippet', this);
- }, function(err, snippetTemplate) {
- if (err) {
- callback(err);
- return;
- }
- snippets.forEach(function(snippet) {
- var html = snippetTemplate({
- snippet: snippet
- });
- markdown = markdown.replace(snippet.original, html);
- });
- return markdown;
- }, callback)
+ Step(
+
+ function() {
+ Tools.compileTemplate('snippet', this);
+ }, function(err, snippetTemplate) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ snippets.forEach(function(snippet) {
+ var html = snippetTemplate({
+ snippet: snippet
+ });
+ markdown = markdown.replace(snippet.original, html);
+ });
+ return markdown;
+ }, callback)
+}
+
+
+
+/*
+
+// Loads a haml template and caches in memory.
+function loadTemplate (name) {
+ 'use strict';
+ var dfd = jq.Deferred();
+
+ Git.safe(function () {
+ Git.readFile('fs', "skin/" + name + ".haml", function (err, haml) {
+ if (err) {
+ dfd.reject(err);
+ }else{
+ dfd.resolve(Haml(haml + "", (/\.xml$/).test(name));
+ }
+ });
+ });
+
+ return dfd;
}
+
+
+
+function render(name, data) {
+ 'use strict';
+ loadTemplate(version, name, this.parallel());
+ if (!partial) {
+ loadTemplate(version, "layout", this.parallel());
+ }
+ }, function renderTemplates(err, template, layout) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ data.__proto__ = Helpers;
+ var content = template(data);
+ if (partial) {
+ return stringToBuffer(content);
+ }
+ data = {
+ content: content,
+ title: data.title || ""
+ };
+ data.__proto__ = Helpers;
+ return stringToBuffer(layout(data));
+ }, callback)
+}
+
+ */
+
var Renderers = module.exports = {
- /*
- * blog index
- */
- index: function() {
- 'use strict';
- var dfd = new Deferred();
-
-
- var page = postProcess({
- "Cache-Control": "public, max-age=3600"
- }, 'test <h1>index</h1>');
-
- dfd.resolve(null, page);
-
-
- return dfd;
- },
-
-
-
- indexOLD: Git.safe(function index(version, callback) {
- Step(
-
- function getHead() {
- Git.getHead(this);
- }, function loadData(err, head) {
- if (err) {
- callback(err);
- return;
- }
- Data.articles(version, this.parallel());
- Git.readFile(head, "description.markdown", this.parallel());
- Data.categories(version, this.parallel());
- }, function applyTemplate(err, articles, description, categories) {
- if (err) {
- callback(err);
- return;
- }
- Tools.render("index", {
- articles: articles,
- description: description,
- categories: categories
- }, this);
- }, function callPostProcess(err, buffer) {
- if (err) {
- callback(err);
- return;
- }
- postProcess({
- "Cache-Control": "public, max-age=3600"
- }, buffer, version, "index", this);
- }, callback);
- }),
-
- feed: Git.safe(function feed(version, callback) {
- var articles;
- Step(
-
- function loadData() {
- Data.fullArticles(version, this);
- }, function(err, data) {
- if (err) {
- callback(err);
- return;
- }
- articles = data;
- var group = this.group();
- articles.forEach(function(article) {
- insertSnippets(article.markdown, article.snippets, group());
- });
- }, function applyTemplate(err, markdowns) {
- if (err) {
- callback(err);
- return;
- }
- markdowns.forEach(function(markdown, i) {
- articles[i].markdown = markdown;
- });
- Tools.render("feed.xml", {
- articles: articles
- }, this, true);
- }, function finish(err, buffer) {
- if (err) {
- callback(err);
- return;
- }
- postProcess({
- "Content-Type": "application/rss+xml",
- "Cache-Control": "public, max-age=3600"
- }, buffer, version, "feed.xml", this);
- }, callback);
- }),
-
- article: Git.safe(function renderArticle(version, name, callback) {
- var article, description;
- Step(
-
- function loadData() {
- Git.getHead(this.parallel());
- Data.fullArticle(version, name, this.parallel());
- }, function(err, head, props) {
- if (err) {
- callback(err);
- return;
- }
- article = props;
- insertSnippets(article.markdown, article.snippets, this.parallel());
- Git.readFile(head, "description.markdown", this.parallel());
- }, function applyTemplate(err, markdown, description) {
- if (err) {
- callback(err);
- return;
- }
- article.markdown = markdown;
- Tools.render("article", {
- title: article.title,
- article: article,
- author: article.author,
- description: description
- }, this);
- }, function finish(err, buffer) {
- if (err) {
- callback(err);
- return;
- }
- postProcess({
- "Cache-Control": "public, max-age=3600"
- }, buffer, version, name, this);
- }, callback);
- }),
-
- categoryIndex: Git.safe(function index(version, category, callback) {
- Step(
-
- function getHead() {
- Git.getHead(this);
- }, function loadData(err, head) {
- if (err) {
- callback(err);
- return;
- }
- Data.articles(version, this.parallel());
- Git.readFile(head, "description.markdown", this.parallel());
- Data.categories(version, this.parallel());
- }, function applyTemplate(err, articles, description, categories) {
- if (err) {
- callback(err);
- return;
- }
-
- var articlesForCategory = articles.reduce(function(start, element) {
- return element.categories && element.categories.indexOf(category) >= 0 ? start.concat(element) : start;
- }, []);
-
- Tools.render("index", {
- articles: articlesForCategory,
- description: description,
- categories: categories
- }, this);
- }, function callPostProcess(err, buffer) {
- if (err) {
- callback(err);
- return;
- }
- postProcess({
- "Cache-Control": "public, max-age=3600"
- }, buffer, version, "index", this);
- }, callback);
- }),
-
- staticFile: Git.safe(function staticFile(version, path, callback) {
- Step(
-
- function loadPublicFiles() {
- Git.readFile(version, "skin/public/" + path, this);
- }, function loadArticleFiles(err, data) {
- if (err) {
- Git.readFile(version, "articles/" + path, this);
- }
- return data;
- }, function processFile(err, data) {
- if (err) {
- callback(err);
- return;
- }
- var headers = {
- "Content-Type": getMime(path),
- "Cache-Control": "public, max-age=32000000"
- };
- postProcess(headers, data, version, path, this);
- }, callback);
- }),
-
- dotFile: Git.safe(function dotFile(version, path, callback) {
- Step(
-
- function loadPublicFiles() {
- Git.readFile(version, "skin/public/" + path, this);
- }, function loadArticleFiles(err, data) {
- if (err) {
- Git.readFile(version, "articles/" + path, this);
- }
- return data;
- }, function processFile(err, data) {
- if (err) {
- callback(err);
- return;
- }
- execPipe("dot", ["-Tpng"], data, this);
- }, function finish(err, buffer) {
- if (err) {
- callback(err);
- return;
- }
- postProcess({
- "Content-Type": "image/png",
- "Cache-Control": "public, max-age=32000000"
- }, buffer, version, path, this);
- }, callback);
- })
+ /*
+ * blog index
+ */
+ index: function(catalog) {
+ 'use strict';
+ var dfd = jq.Deferred();
+
+ Tools.render("index", {
+ articles: catalog.articles,
+ categories: [],
+ description: 'description'
+ }, function(err, buffer) {
+ if (err) {
+ dfd.reject(err);
+ } else {
+ var page = postProcess({
+ "Cache-Control": "public, max-age=3600"
+ }, buffer);
+
+ dfd.resolve(page);
+ }
+
+ });
+
+
+
+ return dfd;
+ },
+
+
+
+
+
+ indexOLD: Git.safe(function index(version, callback) {
+ Step(
+
+ function getHead() {s
+ Git.getHead(this);
+ }, function loadData(err, head) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ Data.articles(version, this.parallel());
+ Git.readFile(head, "description.markdown", this.parallel());
+ Data.categories(version, this.parallel());
+ }, function applyTemplate(err, articles, description, categories) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ Tools.render("index", {
+ articles: articles,
+ description: description,
+ categories: categories
+ }, this);
+ }, function callPostProcess(err, buffer) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ postProcess({
+ "Cache-Control": "public, max-age=3600"
+ }, buffer, version, "index", this);
+ }, callback);
+ }),
+
+ feed: Git.safe(function feed(version, callback) {
+ var articles;
+ Step(
+
+ function loadData() {
+ Data.fullArticles(version, this);
+ }, function(err, data) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ articles = data;
+ var group = this.group();
+ articles.forEach(function(article) {
+ insertSnippets(article.markdown, article.snippets, group());
+ });
+ }, function applyTemplate(err, markdowns) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ markdowns.forEach(function(markdown, i) {
+ articles[i].markdown = markdown;
+ });
+ Tools.render("feed.xml", {
+ articles: articles
+ }, this, true);
+ }, function finish(err, buffer) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ postProcess({
+ "Content-Type": "application/rss+xml",
+ "Cache-Control": "public, max-age=3600"
+ }, buffer, version, "feed.xml", this);
+ }, callback);
+ }),
+
+ article: Git.safe(function renderArticle(version, name, callback) {
+ var article, description;
+ Step(
+
+ function loadData() {
+ Git.getHead(this.parallel());
+ Data.fullArticle(version, name, this.parallel());
+ }, function(err, head, props) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ article = props;
+ insertSnippets(article.markdown, article.snippets, this.parallel());
+ Git.readFile(head, "description.markdown", this.parallel());
+ }, function applyTemplate(err, markdown, description) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ article.markdown = markdown;
+ Tools.render("article", {
+ title: article.title,
+ article: article,
+ author: article.author,
+ description: description
+ }, this);
+ }, function finish(err, buffer) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ postProcess({
+ "Cache-Control": "public, max-age=3600"
+ }, buffer, version, name, this);
+ }, callback);
+ }),
+
+ categoryIndex: Git.safe(function index(version, category, callback) {
+ Step(
+
+ function getHead() {
+ Git.getHead(this);
+ }, function loadData(err, head) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ Data.articles(version, this.parallel());
+ Git.readFile(head, "description.markdown", this.parallel());
+ Data.categories(version, this.parallel());
+ }, function applyTemplate(err, articles, description, categories) {
+ if (err) {
+ callback(err);
+ return;
+ }
+
+ var articlesForCategory = articles.reduce(function(start, element) {
+ return element.categories && element.categories.indexOf(category) >= 0 ? start.concat(element) : start;
+ }, []);
+
+ Tools.render("index", {
+ articles: articlesForCategory,
+ description: description,
+ categories: categories
+ }, this);
+ }, function callPostProcess(err, buffer) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ postProcess({
+ "Cache-Control": "public, max-age=3600"
+ }, buffer, version, "index", this);
+ }, callback);
+ }),
+
+ staticFile: Git.safe(function staticFile(version, path, callback) {
+ Step(
+
+ function loadPublicFiles() {
+ Git.readFile(version, "skin/public/" + path, this);
+ }, function loadArticleFiles(err, data) {
+ if (err) {
+ Git.readFile(version, "articles/" + path, this);
+ }
+ return data;
+ }, function processFile(err, data) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ var headers = {
+ "Content-Type": getMime(path),
+ "Cache-Control": "public, max-age=32000000"
+ };
+ postProcess(headers, data, version, path, this);
+ }, callback);
+ }),
+
+ dotFile: Git.safe(function dotFile(version, path, callback) {
+ Step(
+
+ function loadPublicFiles() {
+ Git.readFile(version, "skin/public/" + path, this);
+ }, function loadArticleFiles(err, data) {
+ if (err) {
+ Git.readFile(version, "articles/" + path, this);
+ }
+ return data;
+ }, function processFile(err, data) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ execPipe("dot", ["-Tpng"], data, this);
+ }, function finish(err, buffer) {
+ if (err) {
+ callback(err);
+ return;
+ }
+ postProcess({
+ "Content-Type": "image/png",
+ "Cache-Control": "public, max-age=32000000"
+ }, buffer, version, path, this);
+ }, callback);
+ })
}

0 comments on commit fefa5a0

Please sign in to comment.