-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.js
118 lines (110 loc) · 2.49 KB
/
router.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var subscribes;
subscribes = new SubsManager({
cacheLimit: 10,
expireIn: 5
});
//預設依日期由舊到新排序
if (Meteor.isClient) {
Session.setDefault('order', 1);
}
//首頁轉頁
Router.route('/', {
name: 'index',
template: 'postsList',
onRun: function() {
if (!Session.get('postLimit') && Blog.settings.pageSize) {
Session.set('postLimit', Blog.settings.pageSize);
}
return this.next();
},
waitOn: function() {
if (typeof Session !== 'undefined') {
return [subscribes.subscribe('posts', Session.get('postLimit')), subscribes.subscribe('authors')];
}
},
fastRender: true,
data: function() {
return {
posts: Blog.Post.where(
{
published: true
},
{
sort: {
//依發表日期序排序
publishedAt: Session.get('order')
}
}
)
};
}
});
//tag篩選
Router.route('/tag/:tag', {
name: 'searchTagged',
template: 'postsList',
waitOn: function() {
return [subscribes.subscribe('taggedPosts', this.params.tag), subscribes.subscribe('authors')];
},
fastRender: true,
data: function() {
return {
posts: Blog.Post.where(
{
tags: this.params.tag,
published: true
},
{
sort: {
//依發表日期序排序
publishedAt: Session.get('order')
}
}
)
};
}
});
//顯示文章
Router.route('/article/:slug', {
name: 'postShow',
template: 'postShow',
onRun: function() {
Session.set('slug', this.params.slug);
return this.next();
},
onBeforeAction: function() {
var images = Blog.Post.first({
slug: this.params.slug
}).featuredImage;
if (images && images.length) {
Session.set('postHasFeaturedImage', true);
}
else {
Session.set('postHasFeaturedImage', false);
}
return this.next();
},
action: function() {
if (this.ready()) {
return this.render();
}
},
waitOn: function() {
return [
subscribes.subscribe('singlePostBySlug', this.params.slug),
subscribes.subscribe('commentsBySlug', this.params.slug),
subscribes.subscribe('authors')
];
},
fastRender: true,
data: function() {
return Blog.Post.first({
slug: this.params.slug
});
}
});
//作者介紹
//顯示文章
Router.route('/author', {
name: 'author'
});