mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-05 18:34:39 +03:00
commit
c347d3fd1c
@ -30,14 +30,6 @@ function getPostPage(options) {
|
||||
}
|
||||
options.include = 'author,tags,fields';
|
||||
return api.posts.browse(options);
|
||||
}).then(function (page) {
|
||||
|
||||
// A bit of a hack for situations with no content.
|
||||
if (page.meta.pagination.pages === 0) {
|
||||
page.meta.pagination.pages = 1;
|
||||
}
|
||||
|
||||
return page;
|
||||
});
|
||||
}
|
||||
|
||||
@ -134,7 +126,7 @@ frontendControllers = {
|
||||
|
||||
// Format data for template
|
||||
response = _.extend(formatPageResponse(posts, page), {
|
||||
tag: page.aspect.tag
|
||||
tag: page.meta.filters.tags ? page.meta.filters.tags[0] : ''
|
||||
});
|
||||
|
||||
res.render(view, response);
|
||||
@ -302,8 +294,10 @@ frontendControllers = {
|
||||
feed;
|
||||
|
||||
if (tagParam) {
|
||||
title = page.aspect.tag.name + ' - ' + title;
|
||||
feedUrl = feedUrl + 'tag/' + page.aspect.tag.slug + '/';
|
||||
if (page.meta.filters.tags) {
|
||||
title = page.meta.filters.tags[0].name + ' - ' + title;
|
||||
feedUrl = feedUrl + 'tag/' + page.meta.filters.tags[0].slug + '/';
|
||||
}
|
||||
}
|
||||
|
||||
feed = new RSS({
|
||||
@ -315,13 +309,6 @@ frontendControllers = {
|
||||
ttl: '60'
|
||||
});
|
||||
|
||||
|
||||
// A bit of a hack for situations with no content.
|
||||
if (maxPage === 0) {
|
||||
maxPage = 1;
|
||||
page.meta.pagination.pages = 1;
|
||||
}
|
||||
|
||||
// If page is greater than number of pages we have, redirect to last page
|
||||
if (pageParam > maxPage) {
|
||||
if (tagParam) {
|
||||
|
@ -380,13 +380,14 @@ Post = ghostBookshelf.Model.extend({
|
||||
// Format response of data
|
||||
.then(function (resp) {
|
||||
var totalPosts = parseInt(resp[0].aggregate, 10),
|
||||
calcPages = Math.ceil(totalPosts / opts.limit),
|
||||
pagination = {},
|
||||
meta = {},
|
||||
data = {};
|
||||
|
||||
pagination['page'] = parseInt(opts.page, 10);
|
||||
pagination['limit'] = opts.limit;
|
||||
pagination['pages'] = Math.ceil(totalPosts / opts.limit);
|
||||
pagination['pages'] = calcPages === 0 ? 1 : calcPages;
|
||||
pagination['total'] = totalPosts;
|
||||
pagination['next'] = null;
|
||||
pagination['prev'] = null;
|
||||
@ -413,9 +414,10 @@ Post = ghostBookshelf.Model.extend({
|
||||
}
|
||||
|
||||
if (tagInstance) {
|
||||
data.aspect = {
|
||||
tag: tagInstance.toJSON()
|
||||
};
|
||||
meta['filters'] = {};
|
||||
if (!tagInstance.isNew()) {
|
||||
meta.filters['tags'] = [tagInstance.toJSON()];
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
|
@ -395,8 +395,8 @@ describe('Post Model', function () {
|
||||
paginationResult.meta.pagination.page.should.equal(1);
|
||||
paginationResult.meta.pagination.limit.should.equal(15);
|
||||
paginationResult.meta.pagination.pages.should.equal(1);
|
||||
paginationResult.aspect.tag.name.should.equal('bacon');
|
||||
paginationResult.aspect.tag.slug.should.equal('bacon');
|
||||
paginationResult.meta.filters.tags[0].name.should.equal('bacon');
|
||||
paginationResult.meta.filters.tags[0].slug.should.equal('bacon');
|
||||
paginationResult.posts.length.should.equal(2);
|
||||
|
||||
return PostModel.findPage({page: 1, tag: 'kitchen-sink'});
|
||||
@ -404,8 +404,8 @@ describe('Post Model', function () {
|
||||
paginationResult.meta.pagination.page.should.equal(1);
|
||||
paginationResult.meta.pagination.limit.should.equal(15);
|
||||
paginationResult.meta.pagination.pages.should.equal(1);
|
||||
paginationResult.aspect.tag.name.should.equal('kitchen sink');
|
||||
paginationResult.aspect.tag.slug.should.equal('kitchen-sink');
|
||||
paginationResult.meta.filters.tags[0].name.should.equal('kitchen sink');
|
||||
paginationResult.meta.filters.tags[0].slug.should.equal('kitchen-sink');
|
||||
paginationResult.posts.length.should.equal(2);
|
||||
|
||||
return PostModel.findPage({page: 1, tag: 'injection'});
|
||||
@ -413,8 +413,8 @@ describe('Post Model', function () {
|
||||
paginationResult.meta.pagination.page.should.equal(1);
|
||||
paginationResult.meta.pagination.limit.should.equal(15);
|
||||
paginationResult.meta.pagination.pages.should.equal(2);
|
||||
paginationResult.aspect.tag.name.should.equal('injection');
|
||||
paginationResult.aspect.tag.slug.should.equal('injection');
|
||||
paginationResult.meta.filters.tags[0].name.should.equal('injection');
|
||||
paginationResult.meta.filters.tags[0].slug.should.equal('injection');
|
||||
paginationResult.posts.length.should.equal(15);
|
||||
|
||||
return PostModel.findPage({page: 2, tag: 'injection'});
|
||||
@ -422,8 +422,8 @@ describe('Post Model', function () {
|
||||
paginationResult.meta.pagination.page.should.equal(2);
|
||||
paginationResult.meta.pagination.limit.should.equal(15);
|
||||
paginationResult.meta.pagination.pages.should.equal(2);
|
||||
paginationResult.aspect.tag.name.should.equal('injection');
|
||||
paginationResult.aspect.tag.slug.should.equal('injection');
|
||||
paginationResult.meta.filters.tags[0].name.should.equal('injection');
|
||||
paginationResult.meta.filters.tags[0].slug.should.equal('injection');
|
||||
paginationResult.posts.length.should.equal(11);
|
||||
|
||||
done();
|
||||
|
@ -189,8 +189,10 @@ describe('Frontend Controller', function () {
|
||||
page: 1,
|
||||
pages: 1,
|
||||
},
|
||||
filters: {
|
||||
tags: [mockTags[0]]
|
||||
}
|
||||
},
|
||||
aspect: {tag: mockTags[0]}
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user