From 465bbd44026ecafe8035a9ff74b67e3d5d09d268 Mon Sep 17 00:00:00 2001 From: Ben Collerson Date: Mon, 1 Aug 2022 00:37:00 +1000 Subject: [PATCH] [enh] archive.today option for results page (#3308) Adds an option to the oscar theme that puts an archive.today link next to the web.archive.org cache link. In preferences change 'Show archive.today links' to 'On' --- searx/preferences.py | 10 ++++++++++ searx/settings.yml | 1 + searx/templates/oscar/macros.html | 6 ++++++ searx/templates/oscar/preferences.html | 11 +++++++++++ searx/webapp.py | 2 ++ 5 files changed, 30 insertions(+) diff --git a/searx/preferences.py b/searx/preferences.py index 64451dee..5c9c293e 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -354,6 +354,16 @@ class Preferences: 'True': True } ), + 'archive_today': MapSetting( + settings['ui'].get('archive_today', True), + is_locked('archive_today'), + map={ + '0': False, + '1': True, + 'False': False, + 'True': True + } + ), 'image_proxy': MapSetting( settings['server'].get('image_proxy', False), is_locked('image_proxy'), diff --git a/searx/settings.yml b/searx/settings.yml index a321ea22..bc5cc041 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -38,6 +38,7 @@ server: ui: autofocus : True # Autofocus search input + archive_today : False # show archive.today links static_path : "" # Custom static path - leave it blank if you didn't change templates_path : "" # Custom templates path - leave it blank if you didn't change default_theme : oscar # ui theme diff --git a/searx/templates/oscar/macros.html b/searx/templates/oscar/macros.html index 1cf46074..06e7d402 100644 --- a/searx/templates/oscar/macros.html +++ b/searx/templates/oscar/macros.html @@ -36,6 +36,9 @@ {{ result_link(result.cached_url, icon('link') + _('cached'), "text-info", id) }} {%- elif not result.is_onion -%} {{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info", id) }} + {% if archive_today %} + {{ result_link("https://archive.today/" + result.url, icon('link') + _('archive'), "text-info", id) }} + {% endif %} {%- endif -%} {%- endif -%} {%- if proxify -%} @@ -72,6 +75,9 @@ {{ result_link(result.cached_url, icon('link') + _('cached'), "text-info", id) }} {%- elif not result.is_onion -%} {{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info", id) }} + {% if archive_today %} + {{ result_link("https://archive.today/" + result.url, icon('link') + _('archive'), "text-info", id) }} + {% endif %} {%- endif -%} {%- endif -%} {%- if proxify -%} diff --git a/searx/templates/oscar/preferences.html b/searx/templates/oscar/preferences.html index a6019193..45cd12aa 100644 --- a/searx/templates/oscar/preferences.html +++ b/searx/templates/oscar/preferences.html @@ -161,6 +161,17 @@ {{ preferences_item_footer(info, label, rtl) }} {% endif %} + {% if 'archive_today' not in locked_preferences %} + {% set label = _('Show archive.today links') %} + {% set info = _('Alternative link cache service') %} + {{ preferences_item_header(info, label, rtl, 'archive_today') }} + + {{ preferences_item_footer(info, label, rtl) }} + {% endif %} + {% set label = _('Show advanced settings') %} {% set info = _('Show advanced settings panel in the home page by default') %} {{ preferences_item_header(info, label, rtl, 'advanced_search') }} diff --git a/searx/webapp.py b/searx/webapp.py index e7f2494d..e37eaf73 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -389,6 +389,8 @@ def render(template_name, override_theme=None, **kwargs): kwargs['autofocus'] = request.preferences.get_value('autofocus') + kwargs['archive_today'] = request.preferences.get_value('archive_today') + kwargs['safesearch'] = str(request.preferences.get_value('safesearch')) kwargs['language_codes'] = languages