Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
woodyrew committed Jul 24, 2018
1 parent 13e598e commit 14f7d3d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
40 changes: 20 additions & 20 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ module.exports = plugin;
* Metalsmith plugin that renames files so that they're permalinked properly
* for a static site, aka that `about.html` becomes `about/index.html`.
*
* @param {Object} options
* @param {Object} options
* @property {String} pattern
* @property {String or Function} date
* @property {String/Function} date
*
* @return {Function}
*/

function plugin(options){
function plugin(options) {
options = normalize(options);

var linksets = options.linksets;
Expand All @@ -40,7 +40,8 @@ function plugin(options){
defaultLinkset = {
pattern: options.pattern,
relative: options.relative,
date: options.date
date: options.date,
slug: options.slug || { mode: 'rfc3986' }
};
}

Expand All @@ -67,14 +68,13 @@ function plugin(options){
return set || defaultLinkset;
}

return function(files, metalsmith, done){
return function(files, metalsmith, done) {
setImmediate(done);
Object.keys(files).forEach(function(file){
Object.keys(files).forEach(function(file) {
var data = files[file];
debug('checking file: %s', file);

if (!html(file)) return;
var data = files[file];
if (data['permalink'] === false) return;

var linkset = merge({}, findLinkset(data), defaultLinkset);
Expand Down Expand Up @@ -105,7 +105,7 @@ function plugin(options){

// add duplicates for relative files after processing to avoid double-dipping
// note: `dupes` will be empty if `options.relative` is false
Object.keys(dupes).forEach(function(dupe){
Object.keys(dupes).forEach(function(dupe) {
files[dupe] = dupes[dupe];
});
};
Expand All @@ -114,11 +114,11 @@ function plugin(options){
/**
* Normalize an options argument.
*
* @param {String or Object} options
* @param {String/Object} options
*
* @return {Object}
*/

function normalize(options){
function normalize(options) {
if ('string' == typeof options) options = { pattern: options };
options = options || {};
options.date =
Expand All @@ -129,7 +129,7 @@ function normalize(options){
? options.relative
: true;
options.linksets = options.linksets || [];
options.slug = options.hasOwnProperty('slug') ? options.slug : { mode: 'rfc3986' };
options.slug = options.slug || { mode: 'rfc3986' };
return options;
}

Expand All @@ -140,8 +140,8 @@ function normalize(options){
* @return {Function}
*/

function format(string){
return function(date){
function format(string) {
return function(date) {
return moment(date)
.utc()
.format(string);
Expand All @@ -156,7 +156,7 @@ function format(string){
* @return {Object}
*/

function family(file, files){
function family(file, files) {
var dir = dirname(file);
var ret = {};

Expand All @@ -180,7 +180,7 @@ function family(file, files){
* @return {String}
*/

function resolve(path){
function resolve(path) {
var ret = dirname(path);
var base = basename(path, extname(path));
if (base != 'index') ret = join(ret, base).replace('\\', '/');
Expand All @@ -196,7 +196,7 @@ function resolve(path){
* @return {String or Null}
*/

function replace(pattern, data, options){
function replace(pattern, data, options) {
if (!pattern) return null;
var keys = params(pattern);
var ret = {};
Expand All @@ -221,7 +221,7 @@ function replace(pattern, data, options){
* @return {Array}
*/

function params(pattern){
function params(pattern) {
var matcher = /:(\w+)/g;
var ret = [];
var m;
Expand All @@ -236,6 +236,6 @@ function params(pattern){
* @return {Boolean}
*/

function html(path){
function html(path) {
return '.html' === extname(path);
}
26 changes: 15 additions & 11 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,24 @@ describe('metalsmith-permalinks', function() {
});
});

it('should accept options for slug module', function(done){
it('should accept options for slug module', function(done) {
Metalsmith('test/fixtures/slug-options')
.use(permalinks({
pattern: ':title',
slug: {
remove: /[.]/g,
lower: false
}
}))
.build(function(err){
.use(
permalinks({
pattern: ':title',
slug: {
remove: /[.]/g,
lower: false
}
})
)
.build(function(err) {
if (err) return done(err);
equal('test/fixtures/slug-options/expected', 'test/fixtures/slug-options/build');
equal(
'test/fixtures/slug-options/expected',
'test/fixtures/slug-options/build'
);
done();
});
});

});

0 comments on commit 14f7d3d

Please sign in to comment.