[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
categories_as_tabs:
- general
- images
- videos
- news
- map
- music
- it
- science
- files
- social media
general:
images:
videos:
news:
map:
music:
it:
science:
files:
social media:
.. _settings engine:

View file

@ -272,7 +272,7 @@ class EnginesSetting(SwitchableSetting):
transformed_choices = []
for engine_name, engine in self.choices.items(): # pylint: disable=no-member,access-member-before-definition
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
transformed_choice = {}
transformed_choice['default_on'] = not engine.disabled

View file

@ -228,16 +228,16 @@ checker:
- has_infobox
categories_as_tabs:
- general
- images
- videos
- news
- map
- music
- it
- science
- files
- social media
general:
images:
videos:
news:
map:
music:
it:
science:
files:
social media:
engines:
- 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)
OSCAR_STYLE = ('logicodev', 'logicodev-dark', 'pointhi')
SIMPLE_STYLE = ('auto', 'light', 'dark')
CATEGORIES_AS_TABS = [
'general',
'images',
'videos',
'news',
'map',
'music',
'it',
'science',
'files',
'social media',
]
CATEGORIES_AS_TABS = {
'general': {},
'images': {},
'videos': {},
'news': {},
'map': {},
'music': {},
'it': {},
'science': {},
'files': {},
'social media': {},
}
STR_TO_BOOL = {
'0': False,
'false': False,
@ -211,7 +211,7 @@ SCHEMA = {
'checker': {
'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, []),
'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['safesearch'] = str(request.preferences.get_value('safesearch'))
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['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"""
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
groups = itertools.groupby(sorted(engines, key=get_group), get_group)

View file

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