Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
runemadsen committed Apr 20, 2016
1 parent 8994a29 commit d4c271f
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 62 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Rewrite the plugin README to say how order comes from the .after and .before
- Add list of plugin labels to the README
- Each plugin that requires the extra liquid step should add something to each file, and then the replacement should happen as a final step in the liquid plugin.
- removePlugins should add disable flag, not remove from array.

- Ability to inline base64 SVG images
- Support pretty output: Put files in filename/index.html
Expand Down
35 changes: 0 additions & 35 deletions spec/build/filenames_spec.js

This file was deleted.

7 changes: 7 additions & 0 deletions spec/helpers/matchers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
var fs = require('fs');
var diff = require('diff');
var rimraf = require('rimraf');

beforeAll(function(done) {
rimraf("spec/support/book/tmp/*", function() {
done();
});
});

beforeEach(function () {

Expand Down
22 changes: 22 additions & 0 deletions spec/plugins/filenames_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe("Filenames plugin", function() {

it("should remove leading numbers, - and _ in filenames and folders", function(done) {
var uid = triggerBuild({
files: [
"spec/support/book/content/00_01-my-filename.md",
"spec/support/book/content/**/00-10-my-other-filename.md",
],
builds: [{
format: "html"
}],
finish: function() {
expect(buildPath(uid, "build1/00_01-my-filename.html")).not.toExist();
expect(buildPath(uid, "build1/my-filename.html")).toExist();
expect(buildPath(uid, "build1/00-01_my-chapter/00-10-my-other-filename.html")).not.toExist();
expect(buildPath(uid, "build1/my-chapter/my-other-filename.html")).toExist();
done();
}
});
});

});
17 changes: 3 additions & 14 deletions src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ var defaults = {
"markdown",
"liquid",
"layouts",
"katex",
"stylesheets",
"javascripts",
"fonts",
"images",
"html",
"pdf",
"frontmatter",
"ids",
"toc",
"katex",
"links",
"footnotes",
"navigation",
"images"
"filenames"
],

"verbose" : true,
Expand All @@ -60,18 +61,6 @@ var defaults = {
}
}

// Pipes
// --------------------------------------------

// through2 function to remove leading number, - and _
// in filenames, so people can order their files.
function removeNumbers() {
return through.obj(function (file, enc, cb) {
file.path = file.path.replace(/\/[\d-_]*/g, '/');
cb(null, file);
});
}

// Main
// --------------------------------------------

Expand Down
16 changes: 5 additions & 11 deletions src/plugins/blank.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ var through = require('through2');

// This constructor function will be called once per format
// for every build. It received a plugin registry object, which
// has .add(), .after() and .before() functions that can be used
// has .add(), .before() and .after() functions that can be used
// to register plugin functions in the pipeline.

var Plugin = function(registry){

// registry.before('convert', 'myFirstLabel', this.myFirstFunction);
// registry.after('layouts', 'mySecondLabel', this.mySecondFunction);

// registry.add('mylabel', this.myFunction);
// registry.before('markdown:convert', 'mylabel', this.myFunction);
// registry.after('layouts', 'mylabel', this.myFunction);
};

Plugin.prototype = {
Expand All @@ -23,8 +22,7 @@ Plugin.prototype = {
// stream - The transform stream with source files. Setup hook does not have this argument as files have not been loaded.
// extras - Object holding extra objects, like the markdown converter
// cb - Function that MUST be called with error/null, config, stream, extras.

myFirstFunction: function(config, stream, extras, cb) {
myFunction: function(config, stream, extras, cb) {

// IMPORTANT NOTE:
//
Expand All @@ -48,10 +46,6 @@ Plugin.prototype = {
// file.$el = undefined;
// }))

cb(null, config, stream, extras);
},

mySecondFunction: function(config, stream, extras, cb) {
cb(null, config, stream, extras);
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/filenames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var through = require('through2');
var path = require('path');

var Plugin = function(registry){
registry.before('markdown:convert', 'filenames:numbers', this.removeNumbers);
};

Plugin.prototype = {

removeNumbers :function(config, stream, extras, callback) {
stream = stream.pipe(through.obj(function (file, enc, cb) {
file.path = file.path.replace(/\/[\d-_]*/g, '/');
cb(null, file);
}));
callback(null, config, stream, extras);
}

}

module.exports = Plugin;
2 changes: 1 addition & 1 deletion src/plugins/footnotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var helpers = require('../helpers/helpers');
var markdownitFootnotes = require('./footnotes/markdown-plugin');

var Plugin = function(registry) {
registry.before('markdown:convert', 'footnotes:placeholders', this.insertPlaceholders);
registry.before('liquid', 'footnotes:placeholders', this.insertPlaceholders);
registry.after('layouts', 'footnotes:insert', this.insertFootnotes);
};

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/katex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var _ = require('lodash');
var markdownitKatex = require('markdown-it-katex');

var Plugin = function(registry) {
registry.before('javascripts:move', 'katex', this.setupKatex)
registry.before('load', 'katex', this.setupKatex)
}

Plugin.prototype = {
Expand Down

0 comments on commit d4c271f

Please sign in to comment.