Skip to content

Commit

Permalink
Merge branch 'hotfix/1.1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed May 28, 2013
2 parents c6dedaf + c664000 commit 576c3c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
3 changes: 2 additions & 1 deletion lib/plugins/console/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ var moment = require('moment'),
util = require('../../util'),
file = util.file;

// http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
var escape = function(str){
return str.toString().toLowerCase()
.replace(/\s/g, '-')
.replace(/\\|\/|<|>|:|"|\||\?|\*|\#/g, '');
.replace(/\/|\\|\?|%|\*|:|\||"|<|>|\./g, '');
};

// Default scaffolds
Expand Down
58 changes: 31 additions & 27 deletions lib/plugins/processor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,12 @@ var getInfoFromFilename = function(str){
return result;
};

// Percent-encoding: http://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_reserved_characters
var escapeRule = {
' ': '-',
'!': '%21',
'#': '%23',
'$': '%24',
'&': '%26',
"'": '%27',
'(': '%28',
')': '%29',
'*': '%2A',
'+': '%2B',
',': '%2C',
'/': '%2F',
':': '%3A',
';': '%3B',
'=': '%3D',
'?': '%3F',
'@': '%40',
'[': '%5B',
']': '%5D'
};

// http://tools.ietf.org/html/rfc3986#section-2.2
// http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
var escape = function(str){
var str = str.toString().replace(/\s|!|#|\$|&|'|\(|\)|\*|\+|,|\/|:|;|\*|\?|@|\[|\]/g, function(match){
return escapeRule[match];
});
var str = str.toString()
.replace(/\s/g, '-')
.replace(/:|\/|\?|#|\[|\]|@|!|\$|&|'|\(|\)|\*|\+|,|;|=|\\|%|<|>|\./g, '');

if (filenameCaps == 1){
str = str.toLowerCase();
Expand Down Expand Up @@ -311,7 +290,20 @@ extend.processor.register(/^_posts\/([^_](?:(?!\/_).)*)$/, function(file, callba
dbTags.update(data._id, {posts: {$addToSet: _id}});
tags.push(data._id);
} else {
dbTags.insert({name: tag, slug: escape(tagMap[tag] || tag), posts: [_id]}, function(tag){
var slug = escape(tagMap[tag] || tag),
related = dbTags.find({slug: new RegExp('^' + slug)});

if (related.length){
var match = related.last().slug.match(/-(\d+)$/);

if (match){
slug += '-' + (parseInt(match[1]) + 1);
} else {
slug += '-1';
}
}

dbTags.insert({name: tag, slug: slug, posts: [_id]}, function(tag){
tags.push(tag._id);
});
}
Expand Down Expand Up @@ -344,6 +336,18 @@ extend.processor.register(/^_posts\/([^_](?:(?!\/_).)*)$/, function(file, callba
dbCats.update(data._id, {posts: {$addToSet: _id}});
cats.push(data._id);
} else {
var related = dbTags.find({slug: new RegExp('^' + slug)});

if (related.length){
var match = related.last().slug.match(/-(\d+)$/);

if (match){
slug += '-' + (parseInt(match[1]) + 1);
} else {
slug += '-1';
}
}

dbCats.insert({name: item, slug: slug, posts: [_id]}, function(cat){
cats.push(cat._id);
});
Expand Down

0 comments on commit 576c3c4

Please # to comment.