From cdbe5507371e11f16771fc5cc8abf6080f6ffac7 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Wed, 20 Dec 2023 11:27:20 -0700 Subject: [PATCH] Add env vars for hiding favicons and removing daily update check - WHOOGLE_SHOW_FAVICONS: Default on, can be set to 0 to hide favicons and skip the request for fetching them - WHOOGLE_UPDATE_CHECK: Default on, can be set to 0 to disable the daily check for new versions released on github Closes #1098 Closes #1059 --- README.md | 2 ++ app/filter.py | 4 +++- app/routes.py | 3 ++- app/static/css/search.css | 2 +- app/utils/misc.py | 4 ++-- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 63fadf0..2900e69 100644 --- a/README.md +++ b/README.md @@ -422,6 +422,8 @@ There are a few optional environment variables available for customizing a Whoog | WHOOGLE_TOR_SERVICE | Enable/disable the Tor service on startup. Default on -- use '0' to disable. | | WHOOGLE_TOR_USE_PASS | Use password authentication for tor control port. | | WHOOGLE_TOR_CONF | The absolute path to the config file containing the password for the tor control port. Default: ./misc/tor/control.conf WHOOGLE_TOR_PASS must be 1 for this to work.| +| WHOOGLE_SHOW_FAVICONS | Show/hide favicons next to search result URLs. Default on. | +| WHOOGLE_UPDATE_CHECK | Enable/disable the automatic daily check for new versions of Whoogle. Default on. | ### Config Environment Variables These environment variables allow setting default config values, but can be overwritten manually by using the home page config menu. These allow a shortcut for destroying/rebuilding an instance to the same config state every time. diff --git a/app/filter.py b/app/filter.py index 3a80535..42d175f 100644 --- a/app/filter.py +++ b/app/filter.py @@ -244,7 +244,9 @@ class Filter: None (The soup object is modified directly) """ # Skip empty, parentless, or internal links - if not link or not link.parent or not link['href'].startswith('http'): + show_favicons = read_config_bool('WHOOGLE_SHOW_FAVICONS', True) + is_valid_link = link and link.parent and link['href'].startswith('http') + if not show_favicons or not is_valid_link: return parent = link.parent diff --git a/app/routes.py b/app/routes.py index 23edd13..90eeab6 100644 --- a/app/routes.py +++ b/app/routes.py @@ -135,7 +135,8 @@ def before_request_func(): # Check for latest version if needed now = datetime.now() - if now - timedelta(hours=24) > app.config['LAST_UPDATE_CHECK']: + needs_update_check = now - timedelta(hours=24) > app.config['LAST_UPDATE_CHECK'] + if read_config_bool('WHOOGLE_UPDATE_CHECK', True) and needs_update_check: app.config['LAST_UPDATE_CHECK'] = now app.config['HAS_UPDATE'] = check_for_update( app.config['RELEASES_URL'], diff --git a/app/static/css/search.css b/app/static/css/search.css index 6c5df2f..3661efb 100644 --- a/app/static/css/search.css +++ b/app/static/css/search.css @@ -64,7 +64,7 @@ details summary span { padding-right: 5px; } -.sCuL3 { +.has-favicon .sCuL3 { padding-left: 30px; } diff --git a/app/utils/misc.py b/app/utils/misc.py index d5fa5e6..20705bc 100644 --- a/app/utils/misc.py +++ b/app/utils/misc.py @@ -56,8 +56,8 @@ def gen_file_hash(path: str, static_file: str) -> str: return filename_split[0] + '.' + file_hash + filename_split[-1] -def read_config_bool(var: str) -> bool: - val = os.getenv(var, '0') +def read_config_bool(var: str, default: bool=False) -> bool: + val = os.getenv(var, '1' if default else '0') # user can specify one of the following values as 'true' inputs (all # variants with upper case letters will also work): # ('true', 't', '1', 'yes', 'y')