Merge pull request 'Add suggested_subreddits option to config.js' (#315) from redmt/teddit:default_subreddits_as_config_option into main

Reviewed-on: https://codeberg.org/teddit/teddit/pulls/315
This commit is contained in:
teddit 2022-06-11 19:48:17 +02:00
commit 7f981f69ae
12 changed files with 97 additions and 108 deletions

View File

@ -77,7 +77,28 @@ const config = {
? JSON.parse(process.env.VALID_MEDIA_DOMAINS)
: ['preview.redd.it', 'external-preview.redd.it', 'i.redd.it', 'v.redd.it', 'a.thumbs.redditmedia.com', 'b.thumbs.redditmedia.com', 'emoji.redditmedia.com', 'styles.redditmedia.com', 'www.redditstatic.com', 'thumbs.gfycat.com', 'i.ytimg.com', 'i.imgur.com'],
valid_embed_video_domains: ['gfycat.com', 'youtube.com'],
reddit_api_error_text: `Seems like your instance is either blocked (e.g. due to API rate limiting), reddit is currently down, or your API key is expired and not renewd properly. This can also happen for other reasons.`
reddit_api_error_text: `Seems like your instance is either blocked (e.g. due to API rate limiting), reddit is currently down, or your API key is expired and not renewd properly. This can also happen for other reasons.`,
/**
* Here you can configure the suggested subreddits which are visible in the
* cleaned homepage, and in the top bar.
* You should keep at least 'All', and 'Saved'.
*/
suggested_subreddits: process.env.SUGGESTED_SUBREDDITS
? JSON.parse(process.env.SUGGESTED_SUBREDDITS)
:
['Popular', 'All', 'Saved', 'AskReddit', 'pics', 'news',
'worldnews', 'funny', 'tifu', 'videos', 'gaming', 'aww',
'todayilearned', 'gifs', 'Art', 'explainlikeimfive',
'movies', 'Jokes', 'TwoXChromosomes',
'mildlyinteresting', 'LifeProTips', 'askscience',
'IAmA', 'dataisbeautiful', 'books', 'science',
'Showerthoughts', 'gadgets', 'Futurology',
'nottheonion', 'history', 'sports', 'OldSchoolCool',
'GetMotivated', 'DIY', 'photoshopbattles', 'nosleep',
'Music', 'space', 'food', 'UpliftingNews', 'EarthPorn',
'Documentaries', 'InternetIsBeautiful',
'WritingPrompts', 'creepy', 'philosophy',
'announcements', 'listentothis', 'blog'],
};
module.exports = config;

View File

@ -30,7 +30,7 @@ module.exports = function(fetch) {
} else {
console.error(`Something went wrong while trying to get an access token from reddit API. ${result.status} ${result.statusText}`)
console.error(reddit_api_error_text)
return res.render('frontpage', { json: null, http_status_code: result.status })
return res.render('frontpage', { json: null, http_status_code: result.status, instance_config: config })
}
}).catch(error => {
console.log(`Error while obtaining a reddit API key.`, error)
@ -66,7 +66,7 @@ module.exports = function(fetch) {
} else {
console.error(`Something went wrong while fetching data from reddit API. ${result.status} ${result.statusText}`)
console.error(reddit_api_error_text)
return res.render('frontpage', { json: null, http_status_code: result.status })
return res.render('frontpage', { json: null, http_status_code: result.status, instance_config: config })
}
}).catch(error => {
console.log(`Error while refreshing the reddit API key.`, error)

View File

@ -13,7 +13,7 @@ homeRoute.get('/', (req, res, next) => {
) {
return res.render('homepage', {
user_preferences: req.cookies,
internal_config: config,
instance_config: config,
});
}
@ -139,6 +139,7 @@ homeRoute.get([`/:sort?`, '/frontpage'], async (req, res, next) => {
return res.render('frontpage', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
}
if (json) {
@ -168,6 +169,7 @@ homeRoute.get([`/:sort?`, '/frontpage'], async (req, res, next) => {
past: past,
user_preferences: req.cookies,
redis_key: key,
instance_config: config,
});
}
})();
@ -201,6 +203,7 @@ homeRoute.get([`/:sort?`, '/frontpage'], async (req, res, next) => {
return res.render('frontpage', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
} else {
console.log('Fetched the frontpage from Reddit.');
@ -229,6 +232,7 @@ homeRoute.get([`/:sort?`, '/frontpage'], async (req, res, next) => {
past: past,
user_preferences: req.cookies,
redis_key: key,
instance_config: config,
});
}
})();
@ -245,6 +249,7 @@ homeRoute.get([`/:sort?`, '/frontpage'], async (req, res, next) => {
json: null,
http_status_code: result.status,
user_preferences: req.cookies,
instance_config: config,
});
}
})

View File

@ -46,6 +46,7 @@ preferenceRoutes.get('/import_prefs/:key', (req, res, next) => {
return res.render('frontpage', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
}
if (json) {

View File

@ -13,6 +13,7 @@ saveRoutes.get('/saved', (req, res, next) => {
return res.render('saved', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
}
@ -38,6 +39,7 @@ saveRoutes.get('/saved', (req, res, next) => {
return res.render('saved', {
json: processed_json,
user_preferences: req.cookies,
instance_config: config,
});
} else {
return res.render('subreddit', {
@ -45,6 +47,7 @@ saveRoutes.get('/saved', (req, res, next) => {
error: true,
data: processed_json,
user_preferences: req.cookies,
instance_config: config,
});
}
})();
@ -217,6 +220,7 @@ saveRoutes.get(
return res.render('frontpage', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
}
if (json) {
@ -260,6 +264,7 @@ saveRoutes.get(
return res.render('frontpage', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
} else {
console.log(
@ -291,6 +296,7 @@ saveRoutes.get(
json: null,
http_status_code: result.status,
user_preferences: req.cookies,
instance_config: config,
});
}
})

View File

@ -14,6 +14,7 @@ searchRoute.get('/search', (req, res, next) => {
sortby: undefined,
past: undefined,
user_preferences: req.cookies,
instance_config: config,
});
}

View File

@ -1,11 +1,11 @@
const staticRoutes = require('express').Router();
staticRoutes.get('/privacy', (req, res, next) => {
return res.render('privacypolicy', { user_preferences: req.cookies });
return res.render('privacypolicy', { user_preferences: req.cookies, instance_config: config });
});
staticRoutes.get('/about', (req, res, next) => {
return res.render('about', { user_preferences: req.cookies });
return res.render('about', { user_preferences: req.cookies, instance_config: config });
});
module.exports = staticRoutes;

View File

@ -28,6 +28,7 @@ subredditRoutes.get('/r/:subreddit/search', (req, res, next) => {
sortby: undefined,
past: undefined,
user_preferences: req.cookies,
instance_config: config,
});
}
@ -68,6 +69,7 @@ subredditRoutes.get('/r/:subreddit/search', (req, res, next) => {
return res.render('frontpage', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
}
if (json) {
@ -90,6 +92,7 @@ subredditRoutes.get('/r/:subreddit/search', (req, res, next) => {
sortby: sortby,
past: past,
user_preferences: req.cookies,
instance_config: config,
});
})();
} else {
@ -129,6 +132,7 @@ subredditRoutes.get('/r/:subreddit/search', (req, res, next) => {
return res.render('frontpage', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
} else {
console.log('Fetched search results from Reddit.');
@ -150,6 +154,7 @@ subredditRoutes.get('/r/:subreddit/search', (req, res, next) => {
sortby: sortby,
past: past,
user_preferences: req.cookies,
instance_config: config,
});
})();
}
@ -166,6 +171,7 @@ subredditRoutes.get('/r/:subreddit/search', (req, res, next) => {
json: null,
http_status_code: result.status,
user_preferences: req.cookies,
instance_config: config,
});
}
})
@ -209,6 +215,7 @@ subredditRoutes.get(
return res.render('frontpage', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
}
if (json) {
@ -221,6 +228,7 @@ subredditRoutes.get(
: formatWikipagelisting(json, subreddit),
subreddit: subreddit,
user_preferences: req.cookies,
instance_config: config,
});
} else {
let url = '';
@ -245,6 +253,7 @@ subredditRoutes.get(
return res.render('subreddit', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
} else {
console.log(
@ -257,6 +266,7 @@ subredditRoutes.get(
: formatWikipagelisting(json, subreddit),
subreddit: subreddit,
user_preferences: req.cookies,
instance_config: config,
});
}
}
@ -275,6 +285,7 @@ subredditRoutes.get(
json: null,
http_status_code: result.status,
user_preferences: req.cookies,
instance_config: config,
});
}
})
@ -328,6 +339,7 @@ subredditRoutes.get('/r/random', (req, res, next) => {
return res.render('subreddit', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
} else {
console.log(
@ -342,6 +354,7 @@ subredditRoutes.get('/r/random', (req, res, next) => {
return res.render('frontpage', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
}
});
@ -358,6 +371,7 @@ subredditRoutes.get('/r/random', (req, res, next) => {
json: null,
http_status_code: result.status,
user_preferences: req.cookies,
instance_config: config,
});
}
})
@ -423,6 +437,7 @@ subredditRoutes.get('/r/:subreddit/:sort?', (req, res, next) => {
return res.render('frontpage', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
}
if (json) {
@ -465,6 +480,7 @@ subredditRoutes.get('/r/:subreddit/:sort?', (req, res, next) => {
redis_key: key,
after: req.query.after,
before: req.query.before,
instance_config: config,
});
} else {
return res.render('subreddit', {
@ -472,6 +488,7 @@ subredditRoutes.get('/r/:subreddit/:sort?', (req, res, next) => {
error: true,
data: processed_json,
user_preferences: req.cookies,
instance_config: config,
});
}
}
@ -499,6 +516,7 @@ subredditRoutes.get('/r/:subreddit/:sort?', (req, res, next) => {
return res.render('subreddit', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
} else {
console.log(
@ -541,6 +559,7 @@ subredditRoutes.get('/r/:subreddit/:sort?', (req, res, next) => {
redis_key: key,
after: req.query.after,
before: req.query.before,
instance_config: config,
});
}
})();
@ -561,6 +580,7 @@ subredditRoutes.get('/r/:subreddit/:sort?', (req, res, next) => {
json: null,
http_status_code: result.status,
user_preferences: req.cookies,
instance_config: config,
});
}
})
@ -623,6 +643,7 @@ subredditRoutes.get(
return res.render('frontpage', {
post: null,
user_preferences: req.cookies,
instance_config: config,
});
}
if (json) {
@ -670,6 +691,7 @@ subredditRoutes.get(
instance_videos_muted: config.videos_muted,
post_media_max_heights: config.post_media_max_heights,
redis_key: comments_key,
instance_config: config,
});
})();
} else {
@ -696,6 +718,7 @@ subredditRoutes.get(
return res.render('post', {
post: null,
user_preferences: req.cookies,
instance_config: config,
});
} else {
console.log(
@ -744,6 +767,7 @@ subredditRoutes.get(
instance_videos_muted: config.videos_muted,
post_media_max_heights: config.post_media_max_heights,
redis_key: comments_key,
instance_config: config,
});
})();
}
@ -764,6 +788,7 @@ subredditRoutes.get(
http_status_code: result.status,
http_statustext: result.statusText,
user_preferences: req.cookies,
instance_config: config,
});
}
})
@ -844,6 +869,7 @@ subredditRoutes.get('/subreddits/:sort?', (req, res, next) => {
return res.render('frontpage', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
}
if (json) {
@ -867,6 +893,7 @@ subredditRoutes.get('/subreddits/:sort?', (req, res, next) => {
subreddits_front: !before && !after ? true : false,
user_preferences: req.cookies,
instance_nsfw_enabled: config.nsfw_enabled,
instance_config: config,
});
} else {
return res.render('subreddits_explore', {
@ -874,6 +901,7 @@ subredditRoutes.get('/subreddits/:sort?', (req, res, next) => {
error: true,
data: processed_json,
user_preferences: req.cookies,
instance_config: config,
});
}
})();
@ -907,6 +935,7 @@ subredditRoutes.get('/subreddits/:sort?', (req, res, next) => {
return res.render('subreddits_explore', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
} else {
console.log(`Fetched the JSON from reddit.com/subreddits.`);
@ -928,6 +957,7 @@ subredditRoutes.get('/subreddits/:sort?', (req, res, next) => {
subreddits_front: !before && !after ? true : false,
user_preferences: req.cookies,
instance_nsfw_enabled: config.nsfw_enabled,
instance_config: config,
});
})();
}
@ -946,6 +976,7 @@ subredditRoutes.get('/subreddits/:sort?', (req, res, next) => {
json: null,
http_status_code: result.status,
user_preferences: req.cookies,
instance_config: config,
});
}
})

View File

@ -94,6 +94,7 @@ userRoutes.get('/u/:user/:kind?', (req, res, next) => {
return res.render('frontpage', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
}
if (json) {
@ -126,6 +127,7 @@ userRoutes.get('/u/:user/:kind?', (req, res, next) => {
sortby: sortby,
past: past,
user_preferences: req.cookies,
instance_config: config,
});
}
})();
@ -166,6 +168,7 @@ userRoutes.get('/u/:user/:kind?', (req, res, next) => {
return res.render('frontpage', {
post: null,
user_preferences: req.cookies,
instance_config: config,
});
} else {
(async () => {
@ -196,6 +199,7 @@ userRoutes.get('/u/:user/:kind?', (req, res, next) => {
sortby: sortby,
past: past,
user_preferences: req.cookies,
instance_config: config,
});
}
})();
@ -212,6 +216,7 @@ userRoutes.get('/u/:user/:kind?', (req, res, next) => {
json: null,
http_status_code: result.status,
user_preferences: req.cookies,
instance_config: config,
});
}
})
@ -224,6 +229,7 @@ userRoutes.get('/u/:user/:kind?', (req, res, next) => {
json: null,
http_status_code: result.status,
user_preferences: req.cookies,
instance_config: config,
});
});
});
@ -241,6 +247,7 @@ userRoutes.get('/u/:user/:kind?', (req, res, next) => {
http_status_code: result.status,
http_statustext: result.statusText,
user_preferences: req.cookies,
instance_config: config,
});
}
})
@ -314,6 +321,7 @@ userRoutes.get('/u/:user/m/:custom_feed/:sort?', (req, res, next) => {
return res.render('frontpage', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
}
if (json) {
@ -350,6 +358,7 @@ userRoutes.get('/u/:user/m/:custom_feed/:sort?', (req, res, next) => {
redis_key: key,
after: req.query.after,
before: req.query.before,
instance_config: config,
});
} else {
return res.render('subreddit', {
@ -357,6 +366,7 @@ userRoutes.get('/u/:user/m/:custom_feed/:sort?', (req, res, next) => {
error: true,
data: processed_json,
user_preferences: req.cookies,
instance_config: config,
});
}
}
@ -384,6 +394,7 @@ userRoutes.get('/u/:user/m/:custom_feed/:sort?', (req, res, next) => {
return res.render('subreddit', {
json: null,
user_preferences: req.cookies,
instance_config: config,
});
} else {
console.log(
@ -420,6 +431,7 @@ userRoutes.get('/u/:user/m/:custom_feed/:sort?', (req, res, next) => {
redis_key: key,
after: req.query.after,
before: req.query.before,
instance_config: config,
});
}
})();
@ -440,6 +452,7 @@ userRoutes.get('/u/:user/m/:custom_feed/:sort?', (req, res, next) => {
json: null,
http_status_code: result.status,
user_preferences: req.cookies,
instance_config: config,
});
}
})

View File

@ -1595,6 +1595,7 @@ body.homepage.clean {
body.homepage.clean main {
flex-grow: 1;
display: flex;
width: 100%;
flex-direction: column;
justify-content: center;
align-items: center;

View File

@ -23,56 +23,11 @@ html
a(href="/saved") Saved
each subreddit in user_preferences.subbed_subreddits
a(href="/r/" + subreddit) #{subreddit}
else
a(href="/r/popular") Popular
a(href="/r/all") All
a(href="/saved") Saved
a(href="/r/AskReddit") AskReddit
a(href="/r/pics") pics
a(href="/r/news") news
a(href="/r/worldnews") worldnews
a(href="/r/funny") funny
a(href="/r/tifu") tifu
a(href="/r/videos") videos
a(href="/r/gaming") gaming
a(href="/r/aww") aww
a(href="/r/todayilearned") todayilearned
a(href="/r/gifs") gifs
a(href="/r/Art") Art
a(href="/r/explainlikeimfive") explainlikeimfive
a(href="/r/movies") movies
a(href="/r/Jokes") Jokes
a(href="/r/TwoXChromosomes") TwoXChromosomes
a(href="/r/mildlyinteresting") mildlyinteresting
a(href="/r/LifeProTips") LifeProTips
a(href="/r/askscience") askscience
a(href="/r/IAmA") IAmA
a(href="/r/dataisbeautiful") dataisbeautiful
a(href="/r/books") books
a(href="/r/science") science
a(href="/r/Showerthoughts") Showerthoughts
a(href="/r/gadgets") gadgets
a(href="/r/Futurology") Futurology
a(href="/r/nottheonion") nottheonion
a(href="/r/history") history
a(href="/r/sports") sports
a(href="/r/OldSchoolCool") OldSchoolCool
a(href="/r/GetMotivated") GetMotivated
a(href="/r/DIY") DIY
a(href="/r/photoshopbattles") photoshopbattles
a(href="/r/nosleep") nosleep
a(href="/r/Music") Music
a(href="/r/space") space
a(href="/r/food") food
a(href="/r/UpliftingNews") UpliftingNews
a(href="/r/EarthPorn") EarthPorn
a(href="/r/Documentaries") Documentaries
a(href="/r/InternetIsBeautiful") InternetIsBeautiful
a(href="/r/WritingPrompts") WritingPrompts
a(href="/r/creepy") creepy
a(href="/r/philosophy") philosophy
a(href="/r/announcements") announcements
a(href="/r/listentothis") listentothis
a(href="/r/blog") blog
else if instance_config.suggested_subreddits && Array.isArray(instance_config.suggested_subreddits)
each subreddit in instance_config.suggested_subreddits
if subreddit.toLowerCase() === 'saved'
a(href="/saved") Saved
else
a(href="/r/" + subreddit) #{subreddit}
include includes/footer.pug

View File

@ -16,55 +16,10 @@ div#topbar
a(href="/saved") Saved
each subreddit in user_preferences.subbed_subreddits
a(href="/r/" + subreddit) #{subreddit}
else
a(href="/r/popular") Popular
a(href="/r/all") All
a(href="/saved") Saved
a(href="/r/AskReddit") AskReddit
a(href="/r/pics") pics
a(href="/r/news") news
a(href="/r/worldnews") worldnews
a(href="/r/funny") funny
a(href="/r/tifu") tifu
a(href="/r/videos") videos
a(href="/r/gaming") gaming
a(href="/r/aww") aww
a(href="/r/todayilearned") todayilearned
a(href="/r/gifs") gifs
a(href="/r/Art") Art
a(href="/r/explainlikeimfive") explainlikeimfive
a(href="/r/movies") movies
a(href="/r/Jokes") Jokes
a(href="/r/TwoXChromosomes") TwoXChromosomes
a(href="/r/mildlyinteresting") mildlyinteresting
a(href="/r/LifeProTips") LifeProTips
a(href="/r/askscience") askscience
a(href="/r/IAmA") IAmA
a(href="/r/dataisbeautiful") dataisbeautiful
a(href="/r/books") books
a(href="/r/science") science
a(href="/r/Showerthoughts") Showerthoughts
a(href="/r/gadgets") gadgets
a(href="/r/Futurology") Futurology
a(href="/r/nottheonion") nottheonion
a(href="/r/history") history
a(href="/r/sports") sports
a(href="/r/OldSchoolCool") OldSchoolCool
a(href="/r/GetMotivated") GetMotivated
a(href="/r/DIY") DIY
a(href="/r/photoshopbattles") photoshopbattles
a(href="/r/nosleep") nosleep
a(href="/r/Music") Music
a(href="/r/space") space
a(href="/r/food") food
a(href="/r/UpliftingNews") UpliftingNews
a(href="/r/EarthPorn") EarthPorn
a(href="/r/Documentaries") Documentaries
a(href="/r/InternetIsBeautiful") InternetIsBeautiful
a(href="/r/WritingPrompts") WritingPrompts
a(href="/r/creepy") creepy
a(href="/r/philosophy") philosophy
a(href="/r/announcements") announcements
a(href="/r/listentothis") listentothis
a(href="/r/blog") blog
else if instance_config.suggested_subreddits && Array.isArray(instance_config.suggested_subreddits)
each subreddit in instance_config.suggested_subreddits
if subreddit.toLowerCase() === 'saved'
a(href="/saved") Saved
else
a(href="/r/" + subreddit) #{subreddit}
a(href="/subreddits", id="sr-more-link") more »