From 2066727f3e325058008c5eff495fa347d1882251 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 5 Nov 2025 13:42:56 -0500 Subject: [PATCH] fix: renderOverride to not clobber url if already set in template data --- src/controllers/category.js | 13 +++++++++---- src/middleware/render.js | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) 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) {