Skip to content

Commit

Permalink
Add root path to permalink of post
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhongjiang committed Aug 13, 2015
1 parent 4ad77fe commit 69a0e2e
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 31 deletions.
3 changes: 2 additions & 1 deletion lib/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ module.exports = function(ctx){
});

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

Post.virtual('full_source').get(function(){
Expand Down
14 changes: 8 additions & 6 deletions test/scripts/helpers/list_archives.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ describe('list_archives', function(){
}

before(function(){
return Post.insert([
{source: 'foo', slug: 'foo', date: new Date(2014, 1, 2)},
{source: 'bar', slug: 'bar', date: new Date(2013, 5, 6)},
{source: 'baz', slug: 'baz', date: new Date(2013, 9, 10)},
{source: 'boo', slug: 'boo', date: new Date(2013, 5, 8)}
]).then(function(){
return hexo.init().then(function(){
return Post.insert([
{source: 'foo', slug: 'foo', date: new Date(2014, 1, 2)},
{source: 'bar', slug: 'bar', date: new Date(2013, 5, 6)},
{source: 'baz', slug: 'baz', date: new Date(2013, 9, 10)},
{source: 'boo', slug: 'boo', date: new Date(2013, 5, 8)}
]);
}).then(function(){
resetLocals();
});
});
Expand Down
14 changes: 8 additions & 6 deletions test/scripts/helpers/list_categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ describe('list_categories', function(){
var listCategories = require('../../../lib/plugins/helper/list_categories').bind(ctx);

before(function(){
return Post.insert([
{source: 'foo', slug: 'foo'},
{source: 'bar', slug: 'bar'},
{source: 'baz', slug: 'baz'},
{source: 'boo', slug: 'boo'}
]).then(function(posts){
return hexo.init().then(function(){
return Post.insert([
{source: 'foo', slug: 'foo'},
{source: 'bar', slug: 'bar'},
{source: 'baz', slug: 'baz'},
{source: 'boo', slug: 'boo'}
]);
}).then(function(posts){
return Promise.each([
['baz'],
['baz', 'bar'],
Expand Down
12 changes: 6 additions & 6 deletions test/scripts/helpers/list_posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ describe('list_posts', function(){
hexo.config.permalink = ':title/';

before(function(){
return Post.insert([
{source: 'foo', slug: 'foo', title: 'Its', date: 1e8},
{source: 'bar', slug: 'bar', title: 'Chemistry', date: 1e8 + 1},
{source: 'baz', slug: 'baz', title: 'Bitch', date: 1e8 - 1}
]).then(function(){
return hexo.init();
return hexo.init().then(function(){
return Post.insert([
{source: 'foo', slug: 'foo', title: 'Its', date: 1e8},
{source: 'bar', slug: 'bar', title: 'Chemistry', date: 1e8 + 1},
{source: 'baz', slug: 'baz', title: 'Bitch', date: 1e8 - 1}
]);
}).then(function(){
hexo.locals.invalidate();
ctx.site = hexo.locals.toObject();
Expand Down
14 changes: 8 additions & 6 deletions test/scripts/helpers/list_tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ describe('list_tags', function(){
var listTags = require('../../../lib/plugins/helper/list_tags').bind(ctx);

before(function(){
return Post.insert([
{source: 'foo', slug: 'foo'},
{source: 'bar', slug: 'bar'},
{source: 'baz', slug: 'baz'},
{source: 'boo', slug: 'boo'}
]).then(function(posts){
return hexo.init().then(function(){
return Post.insert([
{source: 'foo', slug: 'foo'},
{source: 'bar', slug: 'bar'},
{source: 'baz', slug: 'baz'},
{source: 'boo', slug: 'boo'}
]);
}).then(function(posts){
// TODO: Warehouse needs to add a mutex lock when writing data to avoid data sync problem
return Promise.each([
['foo'],
Expand Down
14 changes: 8 additions & 6 deletions test/scripts/helpers/tagcloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ describe('tagcloud', function(){
var tagcloud = require('../../../lib/plugins/helper/tagcloud').bind(ctx);

before(function(){
return Post.insert([
{source: 'foo', slug: 'foo'},
{source: 'bar', slug: 'bar'},
{source: 'baz', slug: 'baz'},
{source: 'boo', slug: 'boo'}
]).then(function(posts){
return hexo.init().then(function(){
return Post.insert([
{source: 'foo', slug: 'foo'},
{source: 'bar', slug: 'bar'},
{source: 'baz', slug: 'baz'},
{source: 'boo', slug: 'boo'}
]);
}).then(function(posts){
// TODO: Warehouse needs to add a mutex lock when writing data to avoid data sync problem
return Promise.each([
['bcd'],
Expand Down
9 changes: 9 additions & 0 deletions test/scripts/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ describe('Post', function(){
});

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

0 comments on commit 69a0e2e

Please sign in to comment.