Skip to content

Commit 08a9b5f

Browse files
tcatcheJLHwung
authored andcommitted
fix post.permalink error when config.relative_link is true (#2760)
* fix a bug that post.permalink error when config.relative_link is true * fix jscs Illegal trailing whitespace
1 parent 6fa2d11 commit 08a9b5f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/models/post.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module.exports = function(ctx) {
5858
var self = _.assign({}, ctx.extend.helper.list(), ctx);
5959
var config = ctx.config;
6060
var partial_url = self.url_for(this.path);
61+
if (config.relative_link) partial_url = '/' + partial_url;
6162
return config.url + _.replace(partial_url, config.root, '/');
6263
});
6364

test/scripts/models/post.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ describe('Post', () => {
8383
});
8484
});
8585

86+
it('permalink - virtual - when set relative_link', () => {
87+
hexo.config.root = '/';
88+
hexo.config.relative_link = true;
89+
return Post.insert({
90+
source: 'foo.md',
91+
slug: 'bar'
92+
}).then(data => {
93+
data.permalink.should.eql(hexo.config.url + '/' + data.path);
94+
return Post.removeById(data._id);
95+
});
96+
});
97+
8698
it('permalink_root_prefix - virtual', () => {
8799
hexo.config.url = 'http://yoursite.com/root';
88100
hexo.config.root = '/root/';
@@ -95,6 +107,19 @@ describe('Post', () => {
95107
});
96108
});
97109

110+
it('permalink_root_prefix - virtual - when set relative_link', () => {
111+
hexo.config.url = 'http://yoursite.com/root';
112+
hexo.config.root = '/root/';
113+
hexo.config.relative_link = true;
114+
return Post.insert({
115+
source: 'foo.md',
116+
slug: 'bar'
117+
}).then(data => {
118+
data.permalink.should.eql(hexo.config.url + '/' + data.path);
119+
return Post.removeById(data._id);
120+
});
121+
});
122+
98123
it('full_source - virtual', () => Post.insert({
99124
source: 'foo.md',
100125
slug: 'bar'

0 commit comments

Comments
 (0)