Skip to content

Node.js based forum software built for the modern web

fix: renderOverride to not clobber url if already set in template data

Julian Lam2066727f3e32
diff --git a/src/controllers/category.js b/src/controllers/category.js
index bf72a8cff0..dd6caeea3b 100644
--- a/src/controllers/category.js
+++ b/src/controllers/category.js
@@ -151,7 +151,7 @@ categoryController.get = async function (req, res, next) {
categoryData.selectedTags = tagData.selectedTags;
categoryData.sortOptionLabel = `[[topic:${validator.escape(String(sort)).replace(/_/g, '-')}]]`;
- if (!meta.config['feeds:disableRSS']) {
+ if (utils.isNumber(categoryData.cid) && !meta.config['feeds:disableRSS']) {
categoryData.rssFeedUrl = `${url}/category/${categoryData.cid}.rss`;
if (req.loggedIn) {
categoryData.rssFeedUrl += `?uid=${req.uid}&token=${rssToken}`;
@@ -175,10 +175,15 @@ categoryController.get = async function (req, res, next) {
res.set('Link', `<${nconf.get('url')}/category/${cid}>; rel="alternate"; type="application/activity+json"`);
// Category accessible
- const remoteOk = await privileges.categories.can('read', cid, activitypub._constants.uid);
- if (remoteOk) {
+ const federating = await privileges.categories.can('read', cid, activitypub._constants.uid);
+ if (federating) {
categoryData.handleFull = `${categoryData.handle}@${nconf.get('url_parsed').host}`;
}
+
+ // Some remote categories don't have `url`, assume same as id
+ if (!utils.isNumber(categoryData.cid) && !categoryData.hasOwnProperty('url')) {
+ categoryData.url = categoryData.cid;
+ }
}
res.render('category', categoryData);
@@ -247,7 +252,7 @@ function addTags(categoryData, res, currentPage) {
},
];
- if (!categoryData['feeds:disableRSS']) {
+ if (categoryData.rssFeedUrl && !categoryData['feeds:disableRSS']) {
res.locals.linkTags.push({
rel: 'alternate',
type: 'application/rss+xml',
diff --git a/src/middleware/render.js b/src/middleware/render.js
index 9741585428..c56a0d526b 100644
--- a/src/middleware/render.js
+++ b/src/middleware/render.js
@@ -45,7 +45,7 @@ module.exports = function (middleware) {
options.loggedInUser = await getLoggedInUser(req);
options.relative_path = relative_path;
options.template = { name: template, [template]: true };
- options.url = (req.baseUrl + req.path.replace(/^\/api/, ''));
+ options.url = options.url || (req.baseUrl + req.path.replace(/^\/api/, ''));
options.bodyClass = helpers.buildBodyClass(req, res, options);
if (req.loggedIn) {