Skip to content

Commit 69a0e2e

Browse files
committed
Add root path to permalink of post
1 parent 4ad77fe commit 69a0e2e

File tree

7 files changed

+49
-31
lines changed

7 files changed

+49
-31
lines changed

lib/models/post.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ module.exports = function(ctx){
4949
});
5050

5151
Post.virtual('permalink').get(function(){
52-
return ctx.config.url + '/' + this.path;
52+
var url_for = ctx.extend.helper.get('url_for');
53+
return ctx.config.url + url_for.call(ctx, this.path);
5354
});
5455

5556
Post.virtual('full_source').get(function(){

test/scripts/helpers/list_archives.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ describe('list_archives', function(){
2222
}
2323

2424
before(function(){
25-
return Post.insert([
26-
{source: 'foo', slug: 'foo', date: new Date(2014, 1, 2)},
27-
{source: 'bar', slug: 'bar', date: new Date(2013, 5, 6)},
28-
{source: 'baz', slug: 'baz', date: new Date(2013, 9, 10)},
29-
{source: 'boo', slug: 'boo', date: new Date(2013, 5, 8)}
30-
]).then(function(){
25+
return hexo.init().then(function(){
26+
return Post.insert([
27+
{source: 'foo', slug: 'foo', date: new Date(2014, 1, 2)},
28+
{source: 'bar', slug: 'bar', date: new Date(2013, 5, 6)},
29+
{source: 'baz', slug: 'baz', date: new Date(2013, 9, 10)},
30+
{source: 'boo', slug: 'boo', date: new Date(2013, 5, 8)}
31+
]);
32+
}).then(function(){
3133
resetLocals();
3234
});
3335
});

test/scripts/helpers/list_categories.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ describe('list_categories', function(){
1818
var listCategories = require('../../../lib/plugins/helper/list_categories').bind(ctx);
1919

2020
before(function(){
21-
return Post.insert([
22-
{source: 'foo', slug: 'foo'},
23-
{source: 'bar', slug: 'bar'},
24-
{source: 'baz', slug: 'baz'},
25-
{source: 'boo', slug: 'boo'}
26-
]).then(function(posts){
21+
return hexo.init().then(function(){
22+
return Post.insert([
23+
{source: 'foo', slug: 'foo'},
24+
{source: 'bar', slug: 'bar'},
25+
{source: 'baz', slug: 'baz'},
26+
{source: 'boo', slug: 'boo'}
27+
]);
28+
}).then(function(posts){
2729
return Promise.each([
2830
['baz'],
2931
['baz', 'bar'],

test/scripts/helpers/list_posts.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ describe('list_posts', function(){
1818
hexo.config.permalink = ':title/';
1919

2020
before(function(){
21-
return Post.insert([
22-
{source: 'foo', slug: 'foo', title: 'Its', date: 1e8},
23-
{source: 'bar', slug: 'bar', title: 'Chemistry', date: 1e8 + 1},
24-
{source: 'baz', slug: 'baz', title: 'Bitch', date: 1e8 - 1}
25-
]).then(function(){
26-
return hexo.init();
21+
return hexo.init().then(function(){
22+
return Post.insert([
23+
{source: 'foo', slug: 'foo', title: 'Its', date: 1e8},
24+
{source: 'bar', slug: 'bar', title: 'Chemistry', date: 1e8 + 1},
25+
{source: 'baz', slug: 'baz', title: 'Bitch', date: 1e8 - 1}
26+
]);
2727
}).then(function(){
2828
hexo.locals.invalidate();
2929
ctx.site = hexo.locals.toObject();

test/scripts/helpers/list_tags.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ describe('list_tags', function(){
1818
var listTags = require('../../../lib/plugins/helper/list_tags').bind(ctx);
1919

2020
before(function(){
21-
return Post.insert([
22-
{source: 'foo', slug: 'foo'},
23-
{source: 'bar', slug: 'bar'},
24-
{source: 'baz', slug: 'baz'},
25-
{source: 'boo', slug: 'boo'}
26-
]).then(function(posts){
21+
return hexo.init().then(function(){
22+
return Post.insert([
23+
{source: 'foo', slug: 'foo'},
24+
{source: 'bar', slug: 'bar'},
25+
{source: 'baz', slug: 'baz'},
26+
{source: 'boo', slug: 'boo'}
27+
]);
28+
}).then(function(posts){
2729
// TODO: Warehouse needs to add a mutex lock when writing data to avoid data sync problem
2830
return Promise.each([
2931
['foo'],

test/scripts/helpers/tagcloud.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ describe('tagcloud', function(){
1818
var tagcloud = require('../../../lib/plugins/helper/tagcloud').bind(ctx);
1919

2020
before(function(){
21-
return Post.insert([
22-
{source: 'foo', slug: 'foo'},
23-
{source: 'bar', slug: 'bar'},
24-
{source: 'baz', slug: 'baz'},
25-
{source: 'boo', slug: 'boo'}
26-
]).then(function(posts){
21+
return hexo.init().then(function(){
22+
return Post.insert([
23+
{source: 'foo', slug: 'foo'},
24+
{source: 'bar', slug: 'bar'},
25+
{source: 'baz', slug: 'baz'},
26+
{source: 'boo', slug: 'boo'}
27+
]);
28+
}).then(function(posts){
2729
// TODO: Warehouse needs to add a mutex lock when writing data to avoid data sync problem
2830
return Promise.each([
2931
['bcd'],

test/scripts/models/post.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ describe('Post', function(){
7777
});
7878

7979
it('permalink - virtual', function(){
80+
hexo.config.root = '/root/';
81+
return Post.insert({
82+
source: 'foo.md',
83+
slug: 'bar'
84+
}).then(function(data){
85+
data.permalink.should.eql(hexo.config.url + '/root/' + data.path);
86+
return Post.removeById(data._id);
87+
});
88+
hexo.config.root = '/';
8089
return Post.insert({
8190
source: 'foo.md',
8291
slug: 'bar'

0 commit comments

Comments
 (0)