Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/models/post_asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var Schema = require('warehouse').Schema;
var pathFn = require('path');
const _ = require('lodash');

module.exports = function(ctx) {
var PostAsset = new Schema({
Expand All @@ -19,7 +20,8 @@ module.exports = function(ctx) {

// PostAsset.path is file path relative to `public_dir`
// no need to urlescape, #1562
return pathFn.join(post.path, this.slug);
// strip /\.html?$/ extensions on permalink, #2134
return pathFn.join(_.replace(post.path, /\.html?$/, ''), this.slug);
});

PostAsset.virtual('source').get(function() {
Expand Down
42 changes: 42 additions & 0 deletions test/scripts/models/post_asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,48 @@ describe('PostAsset', () => {
return PostAsset.removeById(data._id);
}));

it('path - virtual - when permalink is .html', () => {
hexo.config.permalink = ':year/:month/:day/:title.html';
return PostAsset.insert({
_id: 'source/_posts/test/foo.html',
slug: 'foo.htm',
post: post._id
}).then(data => {
data.path.should.eql(pathFn.join(post.path, data.slug));
return PostAsset.removeById(data._id);
}).finally(() => {
hexo.config.permalink = ':year/:month/:day/:title';
});
});

it('path - virtual - when permalink is .htm', () => {
hexo.config.permalink = ':year/:month/:day/:title.htm';
return PostAsset.insert({
_id: 'source/_posts/test/foo.htm',
slug: 'foo.htm',
post: post._id
}).then(data => {
data.path.should.eql(pathFn.join(post.path, data.slug));
return PostAsset.removeById(data._id);
}).finally(() => {
hexo.config.permalink = ':year/:month/:day/:title';
});
});

it('path - virtual - when permalink contains .htm not in the end', () => {
hexo.config.permalink = ':year/:month/:day/:title/.htm-foo/';
return PostAsset.insert({
_id: 'source/_posts/test/foo.html',
slug: 'foo.html',
post: post._id
}).then(data => {
data.path.should.eql(pathFn.join(post.path + '.htm-foo/', data.slug));
return PostAsset.removeById(data._id);
}).finally(() => {
hexo.config.permalink = ':year/:month/:day/:title';
});
});

it('source - virtual', () => PostAsset.insert({
_id: 'source/_posts/test/foo.jpg',
slug: 'foo.jpg',
Expand Down