Skip to content

Commit

Permalink
feat: add parent cids to body class
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Mar 26, 2020
1 parent aabddea commit 2357122
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/controllers/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ async function buildBreadcrumbs(req, categoryData) {
{
text: categoryData.name,
url: nconf.get('relative_path') + '/category/' + categoryData.slug,
cid: categoryData.cid,
},
];
const crumbs = await helpers.buildCategoryBreadcrumbs(categoryData.parentCid);
Expand Down
1 change: 1 addition & 0 deletions src/controllers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ helpers.buildCategoryBreadcrumbs = async function (cid) {
breadcrumbs.unshift({
text: String(data.name),
url: nconf.get('relative_path') + '/category/' + data.slug,
cid: cid,
});
}
cid = data.parentCid;
Expand Down
1 change: 1 addition & 0 deletions src/controllers/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ async function buildBreadcrumbs(topicData) {
{
text: topicData.category.name,
url: nconf.get('relative_path') + '/category/' + topicData.category.slug,
cid: topicData.category.cid,
},
{
text: topicData.title,
Expand Down
7 changes: 7 additions & 0 deletions src/middleware/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ module.exports = function (middleware) {
parts.push('page-topic-category-' + templateData.category.cid);
parts.push('page-topic-category-' + utils.slugify(templateData.category.name));
}
if (templateData.breadcrumbs) {
templateData.breadcrumbs.forEach(function (crumb) {
if (crumb.hasOwnProperty('cid')) {
parts.push('parent-category-' + crumb.cid);
}
});
}

parts.push('page-status-' + res.statusCode);
return parts.join(' ');
Expand Down

0 comments on commit 2357122

Please sign in to comment.