Skip to content

Commit

Permalink
Merge branch 'master' into v1.7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
nodebb-misty committed Nov 15, 2017
2 parents 87d621d + e68e512 commit 6be3e7c
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions public/language/en-GB/admin/settings/post.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"sorting.oldest-to-newest": "Oldest to Newest",
"sorting.newest-to-oldest": "Newest to Oldest",
"sorting.most-votes": "Most Votes",
"sorting.most-posts": "Most Posts",
"sorting.topic-default": "Default Topic Sorting",
"restrictions": "Posting Restrictions",
"restrictions.post-queue": "Enable post queue",
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ categoriesController.list = function (req, res, next) {
categories: categoryData,
};

if (req.path.startsWith('/api/categories') || req.path.startsWith('/categories')) {
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/categories') || req.originalUrl.startsWith(nconf.get('relative_path') + '/categories')) {
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: data.title }]);
}

Expand Down
8 changes: 5 additions & 3 deletions src/controllers/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ categoryController.get = function (req, res, callback) {
return helpers.redirect(res, categoryData.link);
}

buildBreadcrumbs(categoryData, next);
buildBreadcrumbs(req, categoryData, next);
},
function (categoryData, next) {
if (!categoryData.children.length) {
Expand Down Expand Up @@ -148,7 +148,7 @@ categoryController.get = function (req, res, callback) {
], callback);
};

function buildBreadcrumbs(categoryData, callback) {
function buildBreadcrumbs(req, categoryData, callback) {
var breadcrumbs = [
{
text: categoryData.name,
Expand All @@ -160,7 +160,9 @@ function buildBreadcrumbs(categoryData, callback) {
helpers.buildCategoryBreadcrumbs(categoryData.parentCid, next);
},
function (crumbs, next) {
categoryData.breadcrumbs = crumbs.concat(breadcrumbs);
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/category') || req.originalUrl.startsWith(nconf.get('relative_path') + '/category')) {
categoryData.breadcrumbs = crumbs.concat(breadcrumbs);
}
next(null, categoryData);
},
], callback);
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pubsub.on('config:update', configUpdated);
configUpdated();

module.exports = function (req, res, next) {
if (req.path !== '/' && req.path !== '/api/') {
if (req.path !== '/' && req.path !== '/api/' && req.path !== '/api') {
return next();
}

Expand All @@ -56,7 +56,7 @@ module.exports = function (req, res, next) {
});
}

req.url = req.path + route;
req.url = req.path + (!req.path.endsWith('/') ? '/' : '') + route;
next();
});
};
2 changes: 1 addition & 1 deletion src/controllers/popular.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ popularController.get = function (req, res, next) {
term: term,
};

if (req.path.startsWith('/api/popular') || req.path.startsWith('/popular')) {
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/popular') || req.originalUrl.startsWith(nconf.get('relative_path') + '/popular')) {
var breadcrumbs = [{ text: termToBreadcrumb[term] }];

if (req.params.term) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/recent.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ recentController.get = function (req, res, next) {
var pageCount = Math.max(1, Math.ceil(data.topicCount / settings.topicsPerPage));
data.pagination = pagination.create(page, pageCount, req.query);

if (req.path.startsWith('/api/recent') || req.path.startsWith('/recent')) {
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/recent') || req.originalUrl.startsWith(nconf.get('relative_path') + '/recent')) {
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[recent:title]]' }]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/unread.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';

var async = require('async');
var nconf = require('nconf');
var querystring = require('querystring');

var pagination = require('../pagination');
Expand Down Expand Up @@ -64,8 +65,7 @@ unreadController.get = function (req, res, next) {
data.categories = results.watchedCategories.categories;
data.selectedCategory = results.watchedCategories.selectedCategory;
data.selectedCids = results.watchedCategories.selectedCids;

if (req.path.startsWith('/api/unread') || req.path.startsWith('/unread')) {
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/unread') || req.originalUrl.startsWith(nconf.get('relative_path') + '/unread')) {
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[unread:title]]' }]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/views/admin/settings/post.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<select class="form-control" data-field="categoryTopicSort">
<option value="oldest_to_newest">[[admin/settings/post:sorting.oldest-to-newest]]</option>
<option value="newest_to_oldest">[[admin/settings/post:sorting.newest-to-oldest]]</option>
<option value="most_votes">[[admin/settings/post:sorting.most-votes]]</option>
<option value="most_posts">[[admin/settings/post:sorting.most-posts]]</option>
</select>
</div>
</form>
Expand Down
10 changes: 10 additions & 0 deletions test/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ describe('Controllers', function () {
});
});

it('should load not load breadcrumbs on home page route', function (done) {
request(nconf.get('url') + '/api', { json: true }, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
assert(!body.breadcrumbs);
done();
});
});

it('should redirect to custom homepage', function (done) {
meta.configs.set('homePageRoute', 'groups', function (err) {
assert.ifError(err);
Expand Down

0 comments on commit 6be3e7c

Please sign in to comment.