Skip to content

Commit

Permalink
fix post.permalink error when config.relative_link is true (#2760)
Browse files Browse the repository at this point in the history
* fix a bug that post.permalink error when config.relative_link is true

* fix jscs Illegal trailing whitespace
  • Loading branch information
tcatche authored and JLHwung committed Dec 4, 2017
1 parent 6fa2d11 commit 08a9b5f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = function(ctx) {
var self = _.assign({}, ctx.extend.helper.list(), ctx);
var config = ctx.config;
var partial_url = self.url_for(this.path);
if (config.relative_link) partial_url = '/' + partial_url;
return config.url + _.replace(partial_url, config.root, '/');
});

Expand Down
25 changes: 25 additions & 0 deletions test/scripts/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ describe('Post', () => {
});
});

it('permalink - virtual - when set relative_link', () => {
hexo.config.root = '/';
hexo.config.relative_link = true;
return Post.insert({
source: 'foo.md',
slug: 'bar'
}).then(data => {
data.permalink.should.eql(hexo.config.url + '/' + data.path);
return Post.removeById(data._id);
});
});

it('permalink_root_prefix - virtual', () => {
hexo.config.url = 'http://yoursite.com/root';
hexo.config.root = '/root/';
Expand All @@ -95,6 +107,19 @@ describe('Post', () => {
});
});

it('permalink_root_prefix - virtual - when set relative_link', () => {
hexo.config.url = 'http://yoursite.com/root';
hexo.config.root = '/root/';
hexo.config.relative_link = true;
return Post.insert({
source: 'foo.md',
slug: 'bar'
}).then(data => {
data.permalink.should.eql(hexo.config.url + '/' + data.path);
return Post.removeById(data._id);
});
});

it('full_source - virtual', () => Post.insert({
source: 'foo.md',
slug: 'bar'
Expand Down

0 comments on commit 08a9b5f

Please sign in to comment.