Skip to content

Commit

Permalink
Support permanlink style that ends with a slash.
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Nov 23, 2013
1 parent ee3e811 commit 7bd3f22
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/sdk/filters.js
Expand Up @@ -61,6 +61,10 @@ exports.contextfunctions = {
}

url = path.relative(basepath, url);
// path.relative will strip the end `/`
if (permalink.slice(-1) === '/') {
url += '/';
}
url = url.replace(/\/index(\.html)?$/, '/');
url = url.replace(/\\/g, '/');
if (url === 'index') {
Expand Down
1 change: 0 additions & 1 deletion lib/sdk/post.js
Expand Up @@ -37,7 +37,6 @@ exports.permalink = function(item, format) {
if (!ret) {
return ret;
}
ret = encode.filepath(ret);
ret = ret.replace(/\\\\/g, '/');
if (/^\//.test(ret)) {
ret = ret.slice(1);
Expand Down
13 changes: 11 additions & 2 deletions lib/writers/core.js
Expand Up @@ -22,7 +22,11 @@ PostWriter.prototype.renderPosts = function(items, relative) {

_.each(items, function(item, i) {
item = post.read(item.filepath);
var dest = post.permalink(item, option.get('permalink'));
var permalink = option.get('permalink');
var dest = post.permalink(item, permalink);
if (permalink.slice(-1) === '/') {
dest += 'index.html';
}
dest = path.join(outputdir, dest);

if (relative && i < len) {
Expand Down Expand Up @@ -74,7 +78,12 @@ PageWriter.prototype._create = function(item) {
var outputdir = option.get('outputdir');
// user can change the name of page template in config
var template = option.get('page_template') || 'page';
var dest = post.permalink(item, '{{directory}}/{{filename}}.html');
var permalink = option.get('permalink');
var permalink_style = '{{directory}}/{{filename}}.html';
if (permalink.slice(-1) === '/') {
permalink_style = '{{directory}}/{{filename}}/index.html';
}
var dest = post.permalink(item, permalink_style);
dest = path.join(outputdir, dest);
this.render({
destination: dest,
Expand Down

0 comments on commit 7bd3f22

Please sign in to comment.