Merge pull request #5361 from ErisDS/fix-contexts

Fix context setup (remove dep on req.route.path)
This commit is contained in:
Jason Williams 2015-06-03 16:28:16 -05:00
commit 60e160d169
3 changed files with 11 additions and 13 deletions

View File

@ -73,25 +73,27 @@ function setResponseContext(req, res, data) {
pageParam = req.params.page !== undefined ? parseInt(req.params.page, 10) : 1,
tagPattern = new RegExp('^\\/' + config.routeKeywords.tag + '\\/'),
authorPattern = new RegExp('^\\/' + config.routeKeywords.author + '\\/'),
privatePattern = new RegExp('^\\/' + config.routeKeywords.private + '\\/');
privatePattern = new RegExp('^\\/' + config.routeKeywords.private + '\\/'),
indexPattern = new RegExp('^\\/' + config.routeKeywords.page + '\\/'),
homePattern = new RegExp('^\\/$');
// paged context
if (!isNaN(pageParam) && pageParam > 1) {
contexts.push('paged');
}
if (req.route.path === '/' + config.routeKeywords.page + '/:page/') {
if (indexPattern.test(res.locals.relativeUrl)) {
contexts.push('index');
} else if (req.route.path === '/') {
} else if (homePattern.test(res.locals.relativeUrl)) {
contexts.push('home');
contexts.push('index');
} else if (/\/rss\/(:page\/)?$/.test(req.route.path)) {
} else if (/^\/rss\//.test(res.locals.relativeUrl)) {
contexts.push('rss');
} else if (privatePattern.test(req.route.path)) {
} else if (privatePattern.test(res.locals.relativeUrl)) {
contexts.push('private');
} else if (tagPattern.test(req.route.path)) {
} else if (tagPattern.test(res.locals.relativeUrl)) {
contexts.push('tag');
} else if (authorPattern.test(req.route.path)) {
} else if (authorPattern.test(res.locals.relativeUrl)) {
contexts.push('author');
} else if (data && data.post && data.post.page) {
contexts.push('page');

View File

@ -14,10 +14,6 @@ var _ = require('lodash'),
getFeedXml,
feedCache = {};
function isPaginated(req) {
return req.route.path.indexOf(':page') !== -1;
}
function isTag(req) {
return req.originalUrl.indexOf('/' + config.routeKeywords.tag + '/') !== -1;
}
@ -209,7 +205,7 @@ generate = function generate(req, res, next) {
options = getOptions(req, pageParam, slugParam);
// No negative pages, or page 1
if (isNaN(pageParam) || pageParam < 1 || (pageParam === 1 && isPaginated(req))) {
if (isNaN(pageParam) || pageParam < 1 || (req.params.page !== undefined && pageParam === 1)) {
return res.redirect(baseUrl);
}

View File

@ -1467,7 +1467,7 @@ describe('Frontend Controller', function () {
beforeEach(function () {
res = {
locals: {version: ''},
locals: {version: '', relativeUrl: '/private/'},
render: sandbox.spy()
},
req = {