Merge branch 'master' into develop

isekai-main
Barış Soner Uşaklı 2 years ago
commit 4971610cc6

@ -58,9 +58,10 @@ helpers.buildQueryString = function (query, key, value) {
helpers.addLinkTags = function (params) { helpers.addLinkTags = function (params) {
params.res.locals.linkTags = params.res.locals.linkTags || []; params.res.locals.linkTags = params.res.locals.linkTags || [];
const page = params.page > 1 ? `?page=${params.page}` : '';
params.res.locals.linkTags.push({ params.res.locals.linkTags.push({
rel: 'canonical', rel: 'canonical',
href: `${url}/${params.url}`, href: `${url}/${params.url}${page}`,
}); });
params.tags.forEach((rel) => { params.tags.forEach((rel) => {

@ -91,7 +91,12 @@ recentController.getData = async function (req, url, sort) {
const pageCount = Math.max(1, Math.ceil(data.topicCount / settings.topicsPerPage)); const pageCount = Math.max(1, Math.ceil(data.topicCount / settings.topicsPerPage));
data.pagination = pagination.create(page, pageCount, req.query); data.pagination = pagination.create(page, pageCount, req.query);
helpers.addLinkTags({ url: url, res: req.res, tags: data.pagination.rel }); helpers.addLinkTags({
url: url,
res: req.res,
tags: data.pagination.rel,
page: page,
});
return data; return data;
}; };

@ -61,7 +61,12 @@ tagsController.getTag = async function (req, res) {
const pageCount = Math.max(1, Math.ceil(topicCount / settings.topicsPerPage)); const pageCount = Math.max(1, Math.ceil(topicCount / settings.topicsPerPage));
templateData.pagination = pagination.create(page, pageCount, req.query); templateData.pagination = pagination.create(page, pageCount, req.query);
helpers.addLinkTags({ url: `tags/${tag}`, res: req.res, tags: templateData.pagination.rel }); helpers.addLinkTags({
url: `tags/${tag}`,
res: req.res,
tags: templateData.pagination.rel,
page: page,
});
templateData['feeds:disableRSS'] = meta.config['feeds:disableRSS']; templateData['feeds:disableRSS'] = meta.config['feeds:disableRSS'];
templateData.rssFeedUrl = `${nconf.get('relative_path')}/tags/${tag}.rss`; templateData.rssFeedUrl = `${nconf.get('relative_path')}/tags/${tag}.rss`;

@ -72,17 +72,17 @@ topicsController.get = async function getTopic(req, res, next) {
const sort = req.query.sort || settings.topicPostSort; const sort = req.query.sort || settings.topicPostSort;
const set = sort === 'most_votes' ? `tid:${tid}:posts:votes` : `tid:${tid}:posts`; const set = sort === 'most_votes' ? `tid:${tid}:posts:votes` : `tid:${tid}:posts`;
const reverse = sort === 'newest_to_oldest' || sort === 'most_votes'; const reverse = sort === 'newest_to_oldest' || sort === 'most_votes';
if (settings.usePagination) {
if (!req.query.page) { if (!req.query.page) {
currentPage = calculatePageFromIndex(postIndex, settings); currentPage = calculatePageFromIndex(postIndex, settings);
} else { }
if (settings.usePagination && req.query.page) {
const top = ((currentPage - 1) * settings.postsPerPage) + 1; const top = ((currentPage - 1) * settings.postsPerPage) + 1;
const bottom = top + settings.postsPerPage; const bottom = top + settings.postsPerPage;
if (!req.params.post_index || (postIndex < top || postIndex > bottom)) { if (!req.params.post_index || (postIndex < top || postIndex > bottom)) {
postIndex = top; postIndex = top;
} }
} }
}
const { start, stop } = calculateStartStop(currentPage, postIndex, settings); const { start, stop } = calculateStartStop(currentPage, postIndex, settings);
await topics.getTopicWithPosts(topicData, set, req.uid, start, stop, reverse); await topics.getTopicWithPosts(topicData, set, req.uid, start, stop, reverse);
@ -115,7 +115,7 @@ topicsController.get = async function getTopic(req, res, next) {
await Promise.all([ await Promise.all([
buildBreadcrumbs(topicData), buildBreadcrumbs(topicData),
addOldCategory(topicData, userPrivileges), addOldCategory(topicData, userPrivileges),
addTags(topicData, req, res), addTags(topicData, req, res, currentPage),
incrementViewCount(req, tid), incrementViewCount(req, tid),
markAsRead(req, tid), markAsRead(req, tid),
analytics.increment([`pageviews:byCid:${topicData.category.cid}`]), analytics.increment([`pageviews:byCid:${topicData.category.cid}`]),
@ -201,7 +201,7 @@ async function addOldCategory(topicData, userPrivileges) {
} }
} }
async function addTags(topicData, req, res) { async function addTags(topicData, req, res, currentPage) {
const postIndex = parseInt(req.params.post_index, 10) || 0; const postIndex = parseInt(req.params.post_index, 10) || 0;
const postAtIndex = topicData.posts.find(p => parseInt(p.index, 10) === parseInt(Math.max(0, postIndex - 1), 10)); const postAtIndex = topicData.posts.find(p => parseInt(p.index, 10) === parseInt(Math.max(0, postIndex - 1), 10));
let description = ''; let description = '';
@ -256,10 +256,11 @@ async function addTags(topicData, req, res) {
await addOGImageTags(res, topicData, postAtIndex); await addOGImageTags(res, topicData, postAtIndex);
const page = currentPage > 1 ? `?page=${currentPage}` : '';
res.locals.linkTags = [ res.locals.linkTags = [
{ {
rel: 'canonical', rel: 'canonical',
href: `${url}/topic/${topicData.slug}`, href: `${url}/topic/${topicData.slug}${page}`,
}, },
]; ];

@ -51,7 +51,12 @@ unreadController.get = async function (req, res) {
data.pageCount = Math.max(1, Math.ceil(data.topicCount / userSettings.topicsPerPage)); data.pageCount = Math.max(1, Math.ceil(data.topicCount / userSettings.topicsPerPage));
data.pagination = pagination.create(page, data.pageCount, req.query); data.pagination = pagination.create(page, data.pageCount, req.query);
helpers.addLinkTags({ url: 'unread', res: req.res, tags: data.pagination.rel }); helpers.addLinkTags({
url: 'unread',
res: req.res,
tags: data.pagination.rel,
page: page,
});
if (userSettings.usePagination && (page < 1 || page > data.pageCount)) { if (userSettings.usePagination && (page < 1 || page > data.pageCount)) {
req.query.page = Math.max(1, Math.min(data.pageCount, page)); req.query.page = Math.max(1, Math.min(data.pageCount, page));

@ -12,7 +12,9 @@ const languages = require('../languages');
module.exports = function (User) { module.exports = function (User) {
User.getSettings = async function (uid) { User.getSettings = async function (uid) {
if (parseInt(uid, 10) <= 0) { if (parseInt(uid, 10) <= 0) {
return await onSettingsLoaded(0, {}); return await onSettingsLoaded(uid, {
usePagination: parseInt(uid, 10) === -1 ? 1 : undefined, // force spiders to use pagination
});
} }
let settings = await db.getObject(`user:${uid}:settings`); let settings = await db.getObject(`user:${uid}:settings`);
settings = settings || {}; settings = settings || {};

Loading…
Cancel
Save