fix: urls used when recent/unread/popular/top is used as the homepage

if recent is used as the homepage then changing the selected category or filters was redirecting the user to forum.com/recent?cid=1 instead of staying at forum.com/?cid=1

also fix unread page mark read button showing the selected category
isekai-main
Barış Soner Uşaklı 3 years ago
parent 1c80adf1ef
commit 2835966518

@ -12,6 +12,7 @@ const pagination = require('../pagination');
const privileges = require('../privileges'); const privileges = require('../privileges');
const recentController = module.exports; const recentController = module.exports;
const relative_path = nconf.get('relative_path');
recentController.get = async function (req, res, next) { recentController.get = async function (req, res, next) {
const data = await recentController.getData(req, 'recent', 'recent'); const data = await recentController.getData(req, 'recent', 'recent');
@ -56,33 +57,36 @@ recentController.getData = async function (req, url, sort) {
query: req.query, query: req.query,
}); });
const isDisplayedAsHome = !(req.originalUrl.startsWith(`${relative_path}/api/${url}`) || req.originalUrl.startsWith(`${relative_path}/${url}`));
const baseUrl = isDisplayedAsHome ? '' : url;
if (isDisplayedAsHome) {
data.title = meta.config.homePageTitle || '[[pages:home]]';
} else {
data.title = `[[pages:${url}]]`;
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: `[[${url}:title]]` }]);
}
data.canPost = canPost; data.canPost = canPost;
data.showSelect = isPrivileged; data.showSelect = isPrivileged;
data.showTopicTools = isPrivileged; data.showTopicTools = isPrivileged;
data.allCategoriesUrl = url + helpers.buildQueryString(req.query, 'cid', ''); data.allCategoriesUrl = baseUrl + helpers.buildQueryString(req.query, 'cid', '');
data.selectedCategory = categoryData.selectedCategory; data.selectedCategory = categoryData.selectedCategory;
data.selectedCids = categoryData.selectedCids; data.selectedCids = categoryData.selectedCids;
data['feeds:disableRSS'] = meta.config['feeds:disableRSS'] || 0; data['feeds:disableRSS'] = meta.config['feeds:disableRSS'] || 0;
data.rssFeedUrl = `${nconf.get('relative_path')}/${url}.rss`; data.rssFeedUrl = `${relative_path}/${url}.rss`;
if (req.loggedIn) { if (req.loggedIn) {
data.rssFeedUrl += `?uid=${req.uid}&token=${rssToken}`; data.rssFeedUrl += `?uid=${req.uid}&token=${rssToken}`;
} }
data.title = meta.config.homePageTitle || '[[pages:home]]';
data.filters = helpers.buildFilters(url, filter, req.query); data.filters = helpers.buildFilters(baseUrl, filter, req.query);
data.selectedFilter = data.filters.find(filter => filter && filter.selected); data.selectedFilter = data.filters.find(filter => filter && filter.selected);
data.terms = helpers.buildTerms(url, term, req.query); data.terms = helpers.buildTerms(baseUrl, term, req.query);
data.selectedTerm = data.terms.find(term => term && term.selected); data.selectedTerm = data.terms.find(term => term && term.selected);
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 });
if (req.originalUrl.startsWith(`${nconf.get('relative_path')}/api/${url}`) || req.originalUrl.startsWith(`${nconf.get('relative_path')}/${url}`)) {
data.title = `[[pages:${url}]]`;
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: `[[${url}:title]]` }]);
}
return data; return data;
}; };

@ -11,6 +11,7 @@ const topics = require('../topics');
const helpers = require('./helpers'); const helpers = require('./helpers');
const unreadController = module.exports; const unreadController = module.exports;
const relative_path = nconf.get('relative_path');
unreadController.get = async function (req, res) { unreadController.get = async function (req, res) {
const { cid } = req.query; const { cid } = req.query;
@ -34,7 +35,16 @@ unreadController.get = async function (req, res) {
query: req.query, query: req.query,
}); });
const isDisplayedAsHome = !(req.originalUrl.startsWith(`${relative_path}/api/unread`) || req.originalUrl.startsWith(`${relative_path}/unread`));
const baseUrl = isDisplayedAsHome ? '' : 'unread';
if (isDisplayedAsHome) {
data.title = meta.config.homePageTitle || '[[pages:home]]'; data.title = meta.config.homePageTitle || '[[pages:home]]';
} else {
data.title = '[[pages:unread]]';
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[unread:title]]' }]);
}
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 });
@ -45,18 +55,13 @@ unreadController.get = async function (req, res) {
} }
data.showSelect = true; data.showSelect = true;
data.showTopicTools = isPrivileged; data.showTopicTools = isPrivileged;
data.allCategoriesUrl = `unread${helpers.buildQueryString(req.query, 'cid', '')}`; data.allCategoriesUrl = `${baseUrl}${helpers.buildQueryString(req.query, 'cid', '')}`;
data.selectedCategory = categoryData.selectedCategory; data.selectedCategory = categoryData.selectedCategory;
data.selectedCids = categoryData.selectedCids; data.selectedCids = categoryData.selectedCids;
data.selectCategoryLabel = '[[unread:mark_as_read]]'; data.selectCategoryLabel = '[[unread:mark_as_read]]';
data.selectCategoryIcon = 'fa-inbox'; data.selectCategoryIcon = 'fa-inbox';
if (req.originalUrl.startsWith(`${nconf.get('relative_path')}/api/unread`) || req.originalUrl.startsWith(`${nconf.get('relative_path')}/unread`)) { data.showCategorySelectLabel = true;
data.title = '[[pages:unread]]'; data.filters = helpers.buildFilters(baseUrl, filter, req.query);
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[unread:title]]' }]);
}
data.filters = helpers.buildFilters('unread', filter, req.query);
data.selectedFilter = data.filters.find(filter => filter && filter.selected); data.selectedFilter = data.filters.find(filter => filter && filter.selected);
res.render('unread', data); res.render('unread', data);

Loading…
Cancel
Save