From 797372ecaaf74bc65fb466f710610ff6ba2cb38f Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Wed, 30 Mar 2022 14:46:33 -0600 Subject: [PATCH] Ignore blank alts if site alt config is enabled If the alt for a particular service is blank, the original source is used instead. Example: 1. Site alts enabled in config 2. User wants wikipedia links, not wikiless 3. WHOOGLE_ALT_WIKI set to "" 4. All available alt links redirected to farside, except wikipedia Fixes #704 --- app/filter.py | 2 +- app/utils/results.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/filter.py b/app/filter.py index 731b6aa..6b4e284 100644 --- a/app/filter.py +++ b/app/filter.py @@ -410,7 +410,7 @@ class Filter: # Replace link description link_desc = link_desc[0] for site, alt in SITE_ALTS.items(): - if site not in link_desc: + if site not in link_desc or not alt: continue new_desc = BeautifulSoup(features='html.parser').new_tag('div') new_desc.string = str(link_desc).replace(site, alt) diff --git a/app/utils/results.py b/app/utils/results.py index a7ce6f1..55e0079 100644 --- a/app/utils/results.py +++ b/app/utils/results.py @@ -128,7 +128,7 @@ def get_site_alt(link: str) -> str: hostname = urlparse.urlparse(link).hostname for site_key in SITE_ALTS.keys(): - if not hostname or site_key not in hostname: + if not hostname or site_key not in hostname or not SITE_ALTS[site_key]: continue link = link.replace(hostname, SITE_ALTS[site_key])