diff --git a/lib/models/post.js b/lib/models/post.js index f574b4f2d7..558faeab1c 100644 --- a/lib/models/post.js +++ b/lib/models/post.js @@ -47,7 +47,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() { diff --git a/test/scripts/helpers/list_archives.js b/test/scripts/helpers/list_archives.js index fc1371dc0b..b1e7179d9d 100644 --- a/test/scripts/helpers/list_archives.js +++ b/test/scripts/helpers/list_archives.js @@ -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(); }); }); diff --git a/test/scripts/helpers/list_categories.js b/test/scripts/helpers/list_categories.js index 39a549c8d2..45d89671c1 100644 --- a/test/scripts/helpers/list_categories.js +++ b/test/scripts/helpers/list_categories.js @@ -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'], diff --git a/test/scripts/helpers/list_posts.js b/test/scripts/helpers/list_posts.js index 0533570a4b..15dd7850a2 100644 --- a/test/scripts/helpers/list_posts.js +++ b/test/scripts/helpers/list_posts.js @@ -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(); diff --git a/test/scripts/helpers/list_tags.js b/test/scripts/helpers/list_tags.js index 4564051b3b..4c00951b0a 100644 --- a/test/scripts/helpers/list_tags.js +++ b/test/scripts/helpers/list_tags.js @@ -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'], diff --git a/test/scripts/helpers/tagcloud.js b/test/scripts/helpers/tagcloud.js index 60120095d9..66bdfdb8ff 100644 --- a/test/scripts/helpers/tagcloud.js +++ b/test/scripts/helpers/tagcloud.js @@ -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'], diff --git a/test/scripts/models/post.js b/test/scripts/models/post.js index 013d985807..e336651ec0 100644 --- a/test/scripts/models/post.js +++ b/test/scripts/models/post.js @@ -77,6 +77,7 @@ describe('Post', function() { }); it('permalink - virtual', function() { + hexo.config.root = '/'; return Post.insert({ source: 'foo.md', slug: 'bar' @@ -86,6 +87,17 @@ describe('Post', function() { }); }); + it('permalink_prefix - 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); + }); + }); + it('full_source - virtual', function() { return Post.insert({ source: 'foo.md',