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) {
params.res.locals.linkTags = params.res.locals.linkTags || [];
const page = params.page > 1 ? `?page=${params.page}` : '';
params.res.locals.linkTags.push({
rel: 'canonical',
href: `${url}/${params.url}`,
href: `${url}/${params.url}${page}`,
});
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));
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;
};

@ -61,7 +61,12 @@ tagsController.getTag = async function (req, res) {
const pageCount = Math.max(1, Math.ceil(topicCount / settings.topicsPerPage));
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.rssFeedUrl = `${nconf.get('relative_path')}/tags/${tag}.rss`;

@ -72,15 +72,15 @@ topicsController.get = async function getTopic(req, res, next) {
const sort = req.query.sort || settings.topicPostSort;
const set = sort === 'most_votes' ? `tid:${tid}:posts:votes` : `tid:${tid}:posts`;
const reverse = sort === 'newest_to_oldest' || sort === 'most_votes';
if (settings.usePagination) {
if (!req.query.page) {
currentPage = calculatePageFromIndex(postIndex, settings);
} else {
const top = ((currentPage - 1) * settings.postsPerPage) + 1;
const bottom = top + settings.postsPerPage;
if (!req.params.post_index || (postIndex < top || postIndex > bottom)) {
postIndex = top;
}
if (!req.query.page) {
currentPage = calculatePageFromIndex(postIndex, settings);
}
if (settings.usePagination && req.query.page) {
const top = ((currentPage - 1) * settings.postsPerPage) + 1;
const bottom = top + settings.postsPerPage;
if (!req.params.post_index || (postIndex < top || postIndex > bottom)) {
postIndex = top;
}
}
const { start, stop } = calculateStartStop(currentPage, postIndex, settings);
@ -115,7 +115,7 @@ topicsController.get = async function getTopic(req, res, next) {
await Promise.all([
buildBreadcrumbs(topicData),
addOldCategory(topicData, userPrivileges),
addTags(topicData, req, res),
addTags(topicData, req, res, currentPage),
incrementViewCount(req, tid),
markAsRead(req, tid),
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 postAtIndex = topicData.posts.find(p => parseInt(p.index, 10) === parseInt(Math.max(0, postIndex - 1), 10));
let description = '';
@ -256,10 +256,11 @@ async function addTags(topicData, req, res) {
await addOGImageTags(res, topicData, postAtIndex);
const page = currentPage > 1 ? `?page=${currentPage}` : '';
res.locals.linkTags = [
{
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.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)) {
req.query.page = Math.max(1, Math.min(data.pageCount, page));

@ -12,7 +12,9 @@ const languages = require('../languages');
module.exports = function (User) {
User.getSettings = async function (uid) {
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`);
settings = settings || {};

Loading…
Cancel
Save