/
post_permalink.js
86 lines (69 loc) · 2.06 KB
/
post_permalink.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict';
var should = require('chai').should();
var moment = require('moment');
var PERMALINK = ':year/:month/:day/:title/';
describe('post_permalink', function(){
var Hexo = require('../../../lib/hexo');
var hexo = new Hexo();
var postPermalink = require('../../../lib/plugins/filter/post_permalink').bind(hexo);
var Post = hexo.model('Post');
var post;
hexo.config.permalink = PERMALINK;
before(function(){
var id;
return hexo.init().then(function(){
return Post.insert({
source: 'foo.md',
slug: 'foo',
date: moment('2014-01-02')
});
}).then(function(post){
id = post._id;
return post.setCategories(['foo', 'bar']);
}).then(function(){
post = Post.findById(id);
});
});
it('default', function(){
postPermalink(post).should.eql('2014/01/02/foo/');
});
it('categories', function(){
hexo.config.permalink = ':category/:title/';
postPermalink(post).should.eql('foo/bar/foo/');
hexo.config.permalink = PERMALINK;
});
it('uncategorized', function(){
hexo.config.permalink = ':category/:title/';
return Post.insert({
source: 'bar.md',
slug: 'bar'
}).then(function(post){
postPermalink(post).should.eql(hexo.config.default_category + '/bar/');
hexo.config.permalink = PERMALINK;
return Post.removeById(post._id);
});
});
it('extra data', function(){
hexo.config.permalink = ':layout/:title/';
postPermalink(post).should.eql(post.layout + '/foo/');
hexo.config.permalink = PERMALINK;
});
it('id', function(){
hexo.config.permalink = ':id';
postPermalink(post).should.eql(post._id);
post.id = 1;
postPermalink(post).should.eql('1');
hexo.config.permalink = PERMALINK;
});
it('name', function(){
hexo.config.permalink = ':title/:name';
return Post.insert({
source: 'sub/bar.md',
slug: 'sub/bar'
}).then(function(post){
postPermalink(post).should.eql('sub/bar/bar');
hexo.config.permalink = PERMALINK;
return Post.removeById(post._id);
});
});
});