Node.js based forum software built for the modern web
refactor: add noindex to remote topics and user profile pages
Barış Soner Uşaklı2518e718cd83
diff --git a/src/controllers/accounts/profile.js b/src/controllers/accounts/profile.jsindex a556ab6b0e..94e5fc2987 100644--- a/src/controllers/accounts/profile.js+++ b/src/controllers/accounts/profile.js@@ -134,7 +134,7 @@ async function getPosts(callerUid, userData, setSuffix) {function addTags(res, userData) {const plainAboutMe = userData.aboutme ? utils.stripHTMLTags(utils.decodeHTMLEntities(userData.aboutme)) : '';- res.locals.metaTags = [+ res.locals.metaTags.push(...[{name: 'title',content: userData.fullname || userData.username,@@ -151,7 +151,7 @@ function addTags(res, userData) {property: 'og:description',content: plainAboutMe,},- ];+ ]);if (userData.picture) {res.locals.metaTags.push(@@ -178,10 +178,6 @@ function addTags(res, userData) {rel: 'canonical',href: userData.url || userData.uid,});- res.locals.metaTags.push({- name: 'robots',- content: 'noindex',- });}if (meta.config.activitypubEnabled) {diff --git a/src/controllers/topics.js b/src/controllers/topics.jsindex f92e83dc79..47f3bd0a67 100644--- a/src/controllers/topics.js+++ b/src/controllers/topics.js@@ -268,6 +268,13 @@ async function addTags(topicData, req, res, currentPage, postAtIndex) {},];+ if (!utils.isNumber(topicData.tid)) {+ res.locals.metaTags.push({+ name: 'robots',+ content: 'noindex',+ });+ }+const description = getDescriptionFromPost(postAtIndex);if (description) {res.locals.metaTags.push(diff --git a/src/middleware/user.js b/src/middleware/user.jsindex 7466f71c80..605ee21aa6 100644--- a/src/middleware/user.js+++ b/src/middleware/user.js@@ -351,4 +351,16 @@ module.exports = function (middleware) {return !registeredAllowed && verifiedAllowed;}++ middleware.noIndexRemoteUser = function (req, res, next) {+ res.locals.metaTags = res.locals.metaTags || [];+ const isLocal = res.locals.uid > 0;+ if (!isLocal) {+ res.locals.metaTags.push({+ name: 'robots',+ content: 'noindex',+ });+ }+ next();+ };};diff --git a/src/routes/user.js b/src/routes/user.jsindex c2d1cc6f32..99f788bd21 100644--- a/src/routes/user.js+++ b/src/routes/user.js@@ -9,6 +9,7 @@ module.exports = function (app, name, middleware, controllers) {middleware.exposeUid,middleware.canViewUsers,middleware.buildAccountData,+ middleware.noIndexRemoteUser,];const accountMiddlewares = [...middlewares,