From 6600d8580c54de50730539655cff5792f9cd0697 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Sat, 23 Jan 2021 17:43:53 -0500 Subject: [PATCH] Add ability to redirect reddit.com to libredd.it (#180) * Adds the ability to redirect reddit.com to libredd.it using the existing "site alts" config setting. This adds the WHOOGLE_ALT_RD environment variable for optionally redirecting reddit links to libreddit (https://github.com/spikecodes/libreddit). * Include libreddit in home page site alt note --- Dockerfile | 2 ++ README.md | 1 + app.json | 11 ++++++++--- app/templates/index.html | 4 ++-- app/utils/filter_utils.py | 9 +++++++-- docker-compose.yml | 1 + 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7a3f4b6..a62bcee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,6 +45,8 @@ ARG youtube_alt='invidious.snopyta.org' ENV WHOOGLE_ALT_YT=$youtube_alt ARG instagram_alt='bibliogram.art/u' ENV WHOOGLE_ALT_YT=$instagram_alt +ARG reddit_alt='libredd.it' +ENV WHOOGLE_ALT_RD=$reddit_alt COPY . . diff --git a/README.md b/README.md index e5c084a..b989c8e 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,7 @@ Description=Whoogle #Environment=WHOOGLE_ALT_TW=nitter.net #Environment=WHOOGLE_ALT_YT=invidious.snopyta.org #Environment=WHOOGLE_ALT_IG=bibliogram.art/u +#Environment=WHOOGLE_ALT_RD=libredd.it Type=simple User=root WorkingDirectory= diff --git a/app.json b/app.json index 2e70f01..2a54632 100644 --- a/app.json +++ b/app.json @@ -47,17 +47,22 @@ }, "WHOOGLE_ALT_TW": { "description": "The site to use as a replacement for twitter.com when site alternatives are enabled in the config.", - "value": "", + "value": "nitter.net", "required": false }, "WHOOGLE_ALT_YT": { "description": "The site to use as a replacement for youtube.com when site alternatives are enabled in the config.", - "value": "", + "value": "invidious.snopyta.org", "required": false }, "WHOOGLE_ALT_IG": { "description": "The site to use as a replacement for instagram.com when site alternatives are enabled in the config.", - "value": "", + "value": "bibliogram.art/u", + "required": false + }, + "WHOOGLE_ALT_RD": { + "description": "The site to use as a replacement for reddit.com when site alternatives are enabled in the config.", + "value": "libredd.it", "required": false } } diff --git a/app/templates/index.html b/app/templates/index.html index 766fab1..af00e75 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -116,8 +116,8 @@
-
— Replaces Twitter/YouTube/Instagram links - with Nitter/Invidious/Bibliogram links.
+
— Replaces Twitter/YouTube/Instagram/Reddit links + with Nitter/Invidious/Bibliogram/Libreddit links.
diff --git a/app/utils/filter_utils.py b/app/utils/filter_utils.py index d1a2604..c32f6d1 100644 --- a/app/utils/filter_utils.py +++ b/app/utils/filter_utils.py @@ -4,6 +4,7 @@ import urllib.parse as urlparse from urllib.parse import parse_qs SKIP_ARGS = ['ref_src', 'utm'] +SKIP_PREFIX = ['//www.', '//mobile.', '//m.'] FULL_RES_IMG = '
Full Image' GOOG_IMG = '/images/branding/searchlogo/1x/googlelogo' LOGO_URL = GOOG_IMG + '_desk' @@ -22,7 +23,8 @@ BLACKLIST = [ SITE_ALTS = { 'twitter.com': os.getenv('WHOOGLE_ALT_TW', 'nitter.net'), 'youtube.com': os.getenv('WHOOGLE_ALT_YT', 'invidious.snopyta.org'), - 'instagram.com': os.getenv('WHOOGLE_ALT_IG', 'bibliogram.art/u') + 'instagram.com': os.getenv('WHOOGLE_ALT_IG', 'bibliogram.art/u'), + 'reddit.com': os.getenv('WHOOGLE_ALT_RD', 'libredd.it') } @@ -47,7 +49,10 @@ def get_site_alt(link: str): link = link.replace(site_key, SITE_ALTS[site_key]) break - return link.replace('www.', '').replace('//m.', '//') + for prefix in SKIP_PREFIX: + link = link.replace(prefix, '//') + + return link def filter_link_args(query_link): diff --git a/docker-compose.yml b/docker-compose.yml index 75ad171..33a65b2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,6 +19,7 @@ services: #- WHOOGLE_ALT_TW=nitter.net #- WHOOGLE_ALT_YT=invidious.snopyta.org #- WHOOGLE_ALT_IG=bibliogram.art/u + #- WHOOGLE_ALT_RD=libredd.it ports: - 5000:5000 restart: unless-stopped