fix clean_homepage feature so that the user can enable or disable it despite of the instance config

This commit is contained in:
teddit
2022-06-11 13:42:19 +02:00
parent 096c7218d4
commit b797cef167
2 changed files with 15 additions and 16 deletions

View File

@@ -5,22 +5,22 @@ const homeRoute = require('express').Router();
const processJsonSubreddit = require('../inc/processJsonSubreddit.js');
const tedditApiSubreddit = require('../inc/teddit_api/handleSubreddit.js')();
const processMoreComments = require('../inc/processMoreComments.js')();
const frontpagePath = config.clean_homepage ? '/frontpage' : '';
if (config.clean_homepage) {
homeRoute.get('/', (req, res, next) => {
if (req.cookies.clean_homepage && req.cookies.clean_homepage == 'true') {
return res.redirect('/frontpage');
}
res.render('homepage', {
homeRoute.get('/', (req, res, next) => {
if (
(config.clean_homepage && req.cookies.prefer_frontpage !== 'true') ||
(!config.clean_homepage && req.cookies.prefer_frontpage == 'undefined')
) {
return res.render('homepage', {
user_preferences: req.cookies,
internal_config: config,
});
});
}
}
homeRoute.get(`${frontpagePath}/:sort?`, async (req, res, next) => {
next();
});
homeRoute.get([`/:sort?`, '/frontpage'], async (req, res, next) => {
let past = req.query.t;
let before = req.query.before;
let after = req.query.after;
@@ -81,7 +81,7 @@ homeRoute.get(`${frontpagePath}/:sort?`, async (req, res, next) => {
d = `&before=${before}`;
}
if (sortby == '') {
if (sortby == '' || sortby == 'frontpage') {
sortby = 'hot';
}

View File

@@ -105,11 +105,10 @@ html
input(type="checkbox", name="show_upvotes", id="show_upvotes", checked="checked")
else
input(type="checkbox", name="show_upvotes", id="show_upvotes")
if instance_config.clean_homepage
.setting
label(for="prefer_frontpage") Prefer reddit-style frontpage as homepage:
if(user_preferences.prefer_frontpage == 'true')
input(type="checkbox", name="prefer_frontpage", id="prefer_frontpage", checked="true")
if ((!instance_config.clean_homepage && !user_preferences.prefer_frontpage) || user_preferences.prefer_frontpage == 'true')
input(type="checkbox", name="prefer_frontpage", id="prefer_frontpage", checked="checked")
else
input(type="checkbox", name="prefer_frontpage", id="prefer_frontpage")
legend Media