1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-22 20:17:45 +01:00

[enh] change categories_as_tabs from a list to a dict

The tab icon names are currently hard coded in the templates.
This commit lets us introduce an icon property in the future, e.g:

categories_as_tabs:
  general:
    icon: search-outline
This commit is contained in:
Martin Fischer 2022-01-04 18:00:45 +01:00
parent b38036d519
commit a4c2cfb837
7 changed files with 40 additions and 38 deletions

View File

@ -228,16 +228,16 @@ Categories not listed here can still be searched with the :ref:`search-syntax`.
.. code-block:: yaml .. code-block:: yaml
categories_as_tabs: categories_as_tabs:
- general general:
- images images:
- videos videos:
- news news:
- map map:
- music music:
- it it:
- science science:
- files files:
- social media social media:
.. _settings engine: .. _settings engine:

View File

@ -272,7 +272,7 @@ class EnginesSetting(SwitchableSetting):
transformed_choices = [] transformed_choices = []
for engine_name, engine in self.choices.items(): # pylint: disable=no-member,access-member-before-definition for engine_name, engine in self.choices.items(): # pylint: disable=no-member,access-member-before-definition
for category in engine.categories: for category in engine.categories:
if not category in settings['categories_as_tabs'] + [OTHER_CATEGORY]: if not category in list(settings['categories_as_tabs'].keys()) + [OTHER_CATEGORY]:
continue continue
transformed_choice = {} transformed_choice = {}
transformed_choice['default_on'] = not engine.disabled transformed_choice['default_on'] = not engine.disabled

View File

@ -228,16 +228,16 @@ checker:
- has_infobox - has_infobox
categories_as_tabs: categories_as_tabs:
- general general:
- images images:
- videos videos:
- news news:
- map map:
- music music:
- it it:
- science science:
- files files:
- social media social media:
engines: engines:
- name: apk mirror - name: apk mirror

View File

@ -20,18 +20,18 @@ OUTPUT_FORMATS = ['html', 'csv', 'json', 'rss']
LANGUAGE_CODES = ['all'] + list(l[0] for l in languages) LANGUAGE_CODES = ['all'] + list(l[0] for l in languages)
OSCAR_STYLE = ('logicodev', 'logicodev-dark', 'pointhi') OSCAR_STYLE = ('logicodev', 'logicodev-dark', 'pointhi')
SIMPLE_STYLE = ('auto', 'light', 'dark') SIMPLE_STYLE = ('auto', 'light', 'dark')
CATEGORIES_AS_TABS = [ CATEGORIES_AS_TABS = {
'general', 'general': {},
'images', 'images': {},
'videos', 'videos': {},
'news', 'news': {},
'map', 'map': {},
'music', 'music': {},
'it', 'it': {},
'science', 'science': {},
'files', 'files': {},
'social media', 'social media': {},
] }
STR_TO_BOOL = { STR_TO_BOOL = {
'0': False, '0': False,
'false': False, 'false': False,
@ -211,7 +211,7 @@ SCHEMA = {
'checker': { 'checker': {
'off_when_debug': SettingsValue(bool, True), 'off_when_debug': SettingsValue(bool, True),
}, },
'categories_as_tabs': SettingsValue(list, CATEGORIES_AS_TABS), 'categories_as_tabs': SettingsValue(dict, CATEGORIES_AS_TABS),
'engines': SettingsValue(list, []), 'engines': SettingsValue(list, []),
'doi_resolvers': {}, 'doi_resolvers': {},
} }

View File

@ -439,7 +439,7 @@ def render(template_name, override_theme=None, **kwargs):
kwargs['query_in_title'] = request.preferences.get_value('query_in_title') kwargs['query_in_title'] = request.preferences.get_value('query_in_title')
kwargs['safesearch'] = str(request.preferences.get_value('safesearch')) kwargs['safesearch'] = str(request.preferences.get_value('safesearch'))
kwargs['theme'] = get_current_theme_name(override=override_theme) kwargs['theme'] = get_current_theme_name(override=override_theme)
kwargs['categories_as_tabs'] = settings['categories_as_tabs'] kwargs['categories_as_tabs'] = list(settings['categories_as_tabs'].keys())
kwargs['categories'] = _get_enable_categories(categories.keys()) kwargs['categories'] = _get_enable_categories(categories.keys())
kwargs['OTHER_CATEGORY'] = OTHER_CATEGORY kwargs['OTHER_CATEGORY'] = OTHER_CATEGORY

View File

@ -146,7 +146,9 @@ def group_engines_in_tab(engines: Iterable[Engine]) -> List[Tuple[str, Iterable[
"""Groups an Iterable of engines by their first non tab category""" """Groups an Iterable of engines by their first non tab category"""
def get_group(eng): def get_group(eng):
non_tab_categories = [c for c in eng.categories if c not in settings['categories_as_tabs'] + [OTHER_CATEGORY]] non_tab_categories = [
c for c in eng.categories if c not in list(settings['categories_as_tabs'].keys()) + [OTHER_CATEGORY]
]
return non_tab_categories[0] if len(non_tab_categories) > 0 else DEFAULT_GROUP_NAME return non_tab_categories[0] if len(non_tab_categories) > 0 else DEFAULT_GROUP_NAME
groups = itertools.groupby(sorted(engines, key=get_group), get_group) groups = itertools.groupby(sorted(engines, key=get_group), get_group)

View File

@ -34,8 +34,8 @@ outgoing:
useragent_suffix: "" useragent_suffix: ""
categories_as_tabs: categories_as_tabs:
- general general:
- dummy dummy:
engines: engines:
- name: general dummy - name: general dummy