mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
closed #2122
This commit is contained in:
@@ -251,6 +251,7 @@ categoriesController.get = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.breadcrumbs = res.locals.breadcrumbs;
|
||||||
res.render('category', data);
|
res.render('category', data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -253,6 +253,7 @@ topicsController.get = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.breadcrumbs = res.locals.breadcrumbs;
|
||||||
res.render('topic', data);
|
res.render('topic', data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -196,6 +196,58 @@ middleware.checkAccountPermissions = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
middleware.buildBreadcrumbs = function(req, res, next) {
|
||||||
|
var breadcrumbs = [],
|
||||||
|
findParents = function(cid) {
|
||||||
|
var currentCategory;
|
||||||
|
async.doWhilst(function(next) {
|
||||||
|
categories.getCategoryFields(currentCategory ? currentCategory.parentCid : cid, ['name', 'slug', 'parentCid'], function(err, data) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
breadcrumbs.unshift({
|
||||||
|
text: data.name,
|
||||||
|
url: nconf.get('relative_path') + 'category/' + data.slug
|
||||||
|
});
|
||||||
|
|
||||||
|
currentCategory = data;
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
}, function() {
|
||||||
|
return !!currentCategory.parentCid && currentCategory.parentCid !== '0';
|
||||||
|
}, function(err) {
|
||||||
|
if (err) {
|
||||||
|
winston.warn('[buildBreadcrumb] Could not build breadcrumbs: ' + err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Home breadcrumb
|
||||||
|
translator.translate('[[global:home]]', meta.config.defaultLang || 'en_GB', function(translated) {
|
||||||
|
breadcrumbs.unshift({
|
||||||
|
text: translated,
|
||||||
|
url: nconf.get('relative_path')
|
||||||
|
});
|
||||||
|
|
||||||
|
res.locals.breadcrumbs = breadcrumbs || [];
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (req.params.topic_id) {
|
||||||
|
topics.getTopicFields(parseInt(req.params.topic_id, 10), ['cid', 'title', 'slug'], function(err, data) {
|
||||||
|
breadcrumbs.unshift({
|
||||||
|
text: data.title,
|
||||||
|
url: nconf.get('relative_path') + 'topic/' + data.slug
|
||||||
|
});
|
||||||
|
|
||||||
|
findParents(parseInt(data.cid, 10));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
findParents(parseInt(req.params.category_id, 10));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
middleware.buildHeader = function(req, res, next) {
|
middleware.buildHeader = function(req, res, next) {
|
||||||
res.locals.renderHeader = true;
|
res.locals.renderHeader = true;
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ function staticRoutes(app, middleware, controllers) {
|
|||||||
function topicRoutes(app, middleware, controllers) {
|
function topicRoutes(app, middleware, controllers) {
|
||||||
app.get('/api/topic/teaser/:topic_id', controllers.topics.teaser);
|
app.get('/api/topic/teaser/:topic_id', controllers.topics.teaser);
|
||||||
|
|
||||||
setupPageRoute(app, '/topic/:topic_id/:slug/:post_index?', middleware, [], controllers.topics.get);
|
setupPageRoute(app, '/topic/:topic_id/:slug/:post_index?', middleware, [middleware.buildBreadcrumbs], controllers.topics.get);
|
||||||
setupPageRoute(app, '/topic/:topic_id/:slug?', middleware, [middleware.addSlug], controllers.topics.get);
|
setupPageRoute(app, '/topic/:topic_id/:slug?', middleware, [middleware.buildBreadcrumbs, middleware.addSlug], controllers.topics.get);
|
||||||
}
|
}
|
||||||
|
|
||||||
function tagRoutes(app, middleware, controllers) {
|
function tagRoutes(app, middleware, controllers) {
|
||||||
@@ -55,8 +55,8 @@ function categoryRoutes(app, middleware, controllers) {
|
|||||||
setupPageRoute(app, '/unread', middleware, [middleware.authenticate], controllers.categories.unread);
|
setupPageRoute(app, '/unread', middleware, [middleware.authenticate], controllers.categories.unread);
|
||||||
app.get('/api/unread/total', middleware.authenticate, controllers.categories.unreadTotal);
|
app.get('/api/unread/total', middleware.authenticate, controllers.categories.unreadTotal);
|
||||||
|
|
||||||
setupPageRoute(app, '/category/:category_id/:slug/:topic_index', middleware, [], controllers.categories.get);
|
setupPageRoute(app, '/category/:category_id/:slug/:topic_index', middleware, [middleware.buildBreadcrumbs], controllers.categories.get);
|
||||||
setupPageRoute(app, '/category/:category_id/:slug?', middleware, [middleware.addSlug], controllers.categories.get);
|
setupPageRoute(app, '/category/:category_id/:slug?', middleware, [middleware.buildBreadcrumbs, middleware.addSlug], controllers.categories.get);
|
||||||
}
|
}
|
||||||
|
|
||||||
function accountRoutes(app, middleware, controllers) {
|
function accountRoutes(app, middleware, controllers) {
|
||||||
|
|||||||
Reference in New Issue
Block a user