feat: add some missing canonical tags, closes #12961

This commit is contained in:
Barış Soner Uşaklı
2024-12-09 09:56:30 -05:00
parent c8a38667bb
commit e6bdbb6b23
7 changed files with 78 additions and 0 deletions

View File

@@ -1,11 +1,15 @@
'use strict';
const nconf = require('nconf');
const user = require('../../user');
const helpers = require('../helpers');
const pagination = require('../../pagination');
const followController = module.exports;
const url = nconf.get('url');
followController.getFollowing = async function (req, res, next) {
await getFollow('account/following', 'following', req, res, next);
};
@@ -39,5 +43,12 @@ async function getFollow(tpl, name, req, res, next) {
payload.breadcrumbs = helpers.buildBreadcrumbs([{ text: username, url: `/user/${userslug}` }, { text: `[[user:${name}]]` }]);
res.locals.linkTags = [
{
rel: 'canonical',
href: `${url}${req.url.replace(/^\/api/, '')}`,
},
];
res.render(tpl, payload);
}

View File

@@ -1,11 +1,15 @@
'use strict';
const nconf = require('nconf');
const user = require('../../user');
const groups = require('../../groups');
const helpers = require('../helpers');
const groupsController = module.exports;
const url = nconf.get('url');
groupsController.get = async function (req, res) {
const { username, userslug } = await user.getUserFields(res.locals.uid, ['username', 'userslug']);
@@ -21,5 +25,11 @@ groupsController.get = async function (req, res) {
payload.groups = groupsData;
payload.title = `[[pages:account/groups, ${username}]]`;
payload.breadcrumbs = helpers.buildBreadcrumbs([{ text: username, url: `/user/${userslug}` }, { text: '[[global:header.groups]]' }]);
res.locals.linkTags = [
{
rel: 'canonical',
href: `${url}${req.url.replace(/^\/api/, '')}`,
},
];
res.render('account/groups', payload);
};

View File

@@ -1,5 +1,7 @@
'use strict';
const nconf = require('nconf');
const db = require('../../database');
const user = require('../../user');
const posts = require('../../posts');
@@ -13,6 +15,8 @@ const utils = require('../../utils');
const postsController = module.exports;
const url = nconf.get('url');
const templateToData = {
'account/bookmarks': {
type: 'posts',
@@ -240,6 +244,13 @@ async function getPostsFromUserSet(template, req, res) {
option.selected = option.url.includes(`sort=${req.query.sort}`);
});
res.locals.linkTags = [
{
rel: 'canonical',
href: `${url}${req.url.replace(/^\/api/, '')}`,
},
];
res.render(template, payload);
}

View File

@@ -1,6 +1,7 @@
'use strict';
const _ = require('lodash');
const nconf = require('nconf');
const db = require('../../database');
const user = require('../../user');
@@ -14,6 +15,8 @@ const utils = require('../../utils');
const profileController = module.exports;
const url = nconf.get('url');
profileController.get = async function (req, res, next) {
const { userData } = res.locals;
if (!userData) {
@@ -151,4 +154,11 @@ function addMetaTags(res, userData) {
}
);
}
res.locals.linkTags = [
{
rel: 'canonical',
href: `${url}/user/${userData.userslug}`,
},
];
}

View File

@@ -12,6 +12,8 @@ const privileges = require('../privileges');
const groupsController = module.exports;
const url = nconf.get('url');
groupsController.list = async function (req, res) {
const sort = req.query.sort || 'alpha';
const page = parseInt(req.query.page, 10) || 1;
@@ -20,6 +22,13 @@ groupsController.list = async function (req, res) {
getGroups(req, sort, page),
]);
res.locals.linkTags = [
{
rel: 'canonical',
href: `${url}${req.url.replace(/^\/api/, '')}`,
},
];
res.render('groups/list', {
groups: groupData,
allowGroupCreation: allowGroupCreation,
@@ -101,6 +110,13 @@ groupsController.details = async function (req, res, next) {
return next();
}
res.locals.linkTags = [
{
rel: 'canonical',
href: `${url}/groups/${lowercaseSlug}`,
},
];
res.render('groups/details', {
title: `[[pages:group, ${groupData.displayName}]]`,
group: groupData,

View File

@@ -14,6 +14,8 @@ const helpers = require('./helpers');
const tagsController = module.exports;
const url = nconf.get('url');
tagsController.getTag = async function (req, res) {
const tag = validator.escape(utils.cleanUpTag(req.params.tag, meta.config.maximumTagLength));
const page = parseInt(req.query.page, 10) || 1;
@@ -89,6 +91,13 @@ tagsController.getTags = async function (req, res) {
topics.getCategoryTagsData(cids, 0, 99),
]);
res.locals.linkTags = [
{
rel: 'canonical',
href: `${url}/tags`,
},
];
res.render('tags', {
tags: tags.filter(Boolean),
displayTagSearch: canSearch,

View File

@@ -1,5 +1,7 @@
'use strict';
const nconf = require('nconf');
const user = require('../user');
const meta = require('../meta');
@@ -12,6 +14,8 @@ const utils = require('../utils');
const usersController = module.exports;
const url = nconf.get('url');
usersController.index = async function (req, res, next) {
const section = req.query.section || 'joindate';
const sectionToController = {
@@ -206,6 +210,13 @@ async function render(req, res, data) {
data['reputation:disabled'] = meta.config['reputation:disabled'];
res.locals.linkTags = [
{
rel: 'canonical',
href: `${url}${req.url.replace(/^\/api/, '')}`,
},
];
res.append('X-Total-Count', data.userCount);
res.render('users', data);
}