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

make category order configurable using ui.categories_order

This commit is contained in:
Noémi Ványi 2020-03-30 23:24:30 +02:00
parent 08fdfc73fb
commit 640da73a9e
2 changed files with 21 additions and 9 deletions

View File

@ -24,6 +24,12 @@ ui:
default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section
theme_args : theme_args :
oscar_style : logicodev # default style of oscar oscar_style : logicodev # default style of oscar
# categories_order :
# - general
# - files
# - map
# - it
# - science
# searx supports result proxification using an external service: https://github.com/asciimoo/morty # searx supports result proxification using an external service: https://github.com/asciimoo/morty
# uncomment below section if you have running morty proxy # uncomment below section if you have running morty proxy

View File

@ -355,17 +355,12 @@ def render(template_name, override_theme=None, **kwargs):
if (engine_name, category) not in disabled_engines) if (engine_name, category) not in disabled_engines)
if 'categories' not in kwargs: if 'categories' not in kwargs:
kwargs['categories'] = ['general'] kwargs['categories'] = [x for x in
kwargs['categories'].extend(x for x in _get_ordered_categories()
sorted(categories.keys()) if x in enabled_categories]
if x != 'general'
and x in enabled_categories)
if 'all_categories' not in kwargs: if 'all_categories' not in kwargs:
kwargs['all_categories'] = ['general'] kwargs['all_categories'] = _get_ordered_categories()
kwargs['all_categories'].extend(x for x in
sorted(categories.keys())
if x != 'general')
if 'selected_categories' not in kwargs: if 'selected_categories' not in kwargs:
kwargs['selected_categories'] = [] kwargs['selected_categories'] = []
@ -443,6 +438,17 @@ def render(template_name, override_theme=None, **kwargs):
'{}/{}'.format(kwargs['theme'], template_name), **kwargs) '{}/{}'.format(kwargs['theme'], template_name), **kwargs)
def _get_ordered_categories():
ordered_categories = []
if 'categories_order' not in settings['ui']:
ordered_categories = ['general']
ordered_categories.extend(x for x in sorted(categories.keys()) if x != 'general')
return ordered_categories
ordered_categories = settings['ui']['categories_order']
ordered_categories.extend(x for x in sorted(categories.keys()) if x not in ordered_categories)
return ordered_categories
@app.before_request @app.before_request
def pre_request(): def pre_request():
request.start_time = time() request.start_time = time()