Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Pre plugins #15

Merged
merged 1 commit into from

2 participants

@wlaurance

Run this set of plugins before markdown is applied.

@wlaurance wlaurance Pre plugins
Run this set of plugins before markdown is applied.
2f4d6b5
@guyht
Owner

Meant to take a look at this last night but didnt have time, will try to do it tonight.

G

@guyht guyht merged commit fd1c73b into guyht:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 3, 2012
  1. @wlaurance

    Pre plugins

    wlaurance authored
    Run this set of plugins before markdown is applied.
This page is out of date. Refresh to see the latest.
Showing with 58 additions and 11 deletions.
  1. +51 −10 lib/glog.js
  2. +6 −1 plugins/example.js
  3. +1 −0  test/glog_tests.js
View
61 lib/glog.js
@@ -150,7 +150,7 @@ Glog.prototype.load_articles = function(options, cb) {
var parts = data.split('\n\n');
var header = JSON.parse(parts[0]);
parts.splice(0,1);
- var body = marked(parts.join('\n\n'));
+ var body = parts.join('\n\n');
console.log('Read articles with headers: ');
console.log(header);
@@ -188,15 +188,56 @@ Glog.prototype.load_articles = function(options, cb) {
'body' : body,
'url' : [year, month, (header.url || header.title.replace(/\s/g, '-'))].join('/')
});
- if (files.length === articles.length && fn.articlePostPlugins.length > 1){
- fn.articlePostPlugins[0] = function(wcb){
- wcb(null, articles);
- };
- fn.articlePostPlugins[fn.articlePostPlugins.length] = function(result){
- cb(result.reverse());
- };
- async.waterfall(fn.articlePostPlugins);
- } else if (files.length === articles.length && fn.articlePostPlugins.length === 1) {
+ if (files.length === articles.length && (fn.articlePostPlugins.length > 1 || fn.articlePrePlugins.length > 1)){
+ var plugins = [];
+ var postlength = Number(fn.articlePostPlugins.length);
+ var prelength = Number(fn.articlePrePlugins.length);
+ if(fn.articlePrePlugins.length > 1){
+ console.log('preplugins');
+ fn.articlePrePlugins[0] = function(wcb){
+ wcb(null, articles);
+ }
+ fn.articlePrePlugins[fn.articlePrePlugins.length] = function(result, wcb){
+ if(postlength > 1){
+ console.info('moving on to post plugins');
+ wcb(null, result);
+ } else {
+ for(var k in result){
+ result[k].body = marked(result[k].body);
+ }
+ cb(result.reverse());
+ }
+ }
+ for(var p in fn.articlePrePlugins){
+ plugins.push(fn.articlePrePlugins[p]);
+ }
+ }
+ if(fn.articlePostPlugins.length > 1){
+ if(prelength > 1){
+ fn.articlePostPlugins[0] = function(result, wcb){
+ for(var k in result){
+ result[k].body = marked(result[k].body);
+ }
+ wcb(null, result);
+ }
+ } else {
+ fn.articlePostPlugins[0] = function(wcb){
+ wcb(null, articles);
+ };
+ }
+ fn.articlePostPlugins[fn.articlePostPlugins.length] = function(result){
+ cb(result.reverse());
+ };
+ }
+ for(var f in fn.articlePostPlugins){
+ plugins.push(fn.articlePostPlugins[f]);
+ }
+ async.waterfall(plugins);
+ } else if (files.length === articles.length && fn.articlePostPlugins.length === 1 && fn.articlePrePlugins.length === 1) {
+ for(var g in articles){
+ articles[g].body = marked(articles[g].body);
+ }
+
cb(articles.reverse());
}
View
7 plugins/example.js
@@ -14,5 +14,10 @@ module.exports.load = function(glog) {
}
cb(null, articles);
});
-
+ glog.registerPreArticleHook(function(articles, cb) {
+ for(var i=0;i<articles.length;i++){
+ articles[i].year = '1988'
+ }
+ cb(null, articles);
+ });
}
View
1  test/glog_tests.js
@@ -75,6 +75,7 @@ describe('Glog', function() {
glog.load_articles(options, function(articles) {
glog.render_blog(options, articles, function() {
assert.equal(articles[0].title, 'Title changed by plugin');
+ assert.equal(articles[0].year, '1988');
done();
});
});
Something went wrong with that request. Please try again.