mirror of
https://github.com/searxng/searxng.git
synced 2024-12-04 16:36:27 +00:00
[feat] search: add url formatting preference
This commit is contained in:
parent
cae07b9bf8
commit
a7537a6935
8 changed files with 51 additions and 0 deletions
|
@ -21,6 +21,7 @@
|
|||
simple_style: auto
|
||||
search_on_category_select: true
|
||||
hotkeys: default
|
||||
url_formatting: pretty
|
||||
|
||||
.. _static_use_hash:
|
||||
|
||||
|
@ -68,3 +69,6 @@
|
|||
|
||||
``hotkeys``:
|
||||
Hotkeys to use in the search interface: ``default``, ``vim`` (Vim-like).
|
||||
|
||||
``url_formatting``:
|
||||
Formatting type to use for result URLs: ``pretty``, ``full`` or ``host``.
|
||||
|
|
|
@ -472,6 +472,10 @@ class Preferences:
|
|||
settings['ui']['hotkeys'],
|
||||
choices=['default', 'vim']
|
||||
),
|
||||
'url_formatting': EnumStringSetting(
|
||||
settings['ui']['url_formatting'],
|
||||
choices=['pretty', 'full', 'host']
|
||||
),
|
||||
# fmt: on
|
||||
}
|
||||
|
||||
|
|
|
@ -145,6 +145,8 @@ ui:
|
|||
search_on_category_select: true
|
||||
# Hotkeys: default or vim
|
||||
hotkeys: default
|
||||
# URL formatting: pretty, full or host
|
||||
url_formatting: pretty
|
||||
|
||||
# Lock arbitrary settings on the preferences page. To find the ID of the user
|
||||
# setting you want to lock, check the ID of the form on the page "preferences".
|
||||
|
|
|
@ -205,6 +205,7 @@ SCHEMA = {
|
|||
'cache_url': SettingsValue(str, 'https://web.archive.org/web/'),
|
||||
'search_on_category_select': SettingsValue(bool, True),
|
||||
'hotkeys': SettingsValue(('default', 'vim'), 'default'),
|
||||
'url_formatting': SettingsValue(('pretty', 'full', 'host'), 'pretty'),
|
||||
},
|
||||
'preferences': {
|
||||
'lock': SettingsValue(list, []),
|
||||
|
|
|
@ -254,6 +254,10 @@ article[data-vim-selected].category-social {
|
|||
white-space: nowrap;
|
||||
flex-shrink: 1;
|
||||
padding-bottom: 1px;
|
||||
|
||||
.url_i1 {
|
||||
unicode-bidi: plaintext;
|
||||
}
|
||||
}
|
||||
|
||||
.url_o1::after {
|
||||
|
|
|
@ -204,6 +204,7 @@
|
|||
{%- include 'simple/preferences/search_on_category_select.html' -%}
|
||||
{%- endif -%}
|
||||
{%- include 'simple/preferences/hotkeys.html' -%}
|
||||
{%- include 'simple/preferences/urlformatting.html' -%}
|
||||
{{- plugin_preferences('ui') -}}
|
||||
{{- tab_footer() -}}
|
||||
|
||||
|
|
25
searx/templates/simple/preferences/urlformatting.html
Normal file
25
searx/templates/simple/preferences/urlformatting.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
<fieldset>{{- '' -}}
|
||||
<legend id="pref_url_formatting">{{- _('URL formatting') -}}</legend>{{- '' -}}
|
||||
<div class="value">{{- '' -}}
|
||||
<select name="url_formatting" aria-labelledby="pref_url_formatting">{{- '' -}}
|
||||
<option value="pretty"
|
||||
{%- if preferences.get_value('url_formatting') == 'pretty' %} selected="selected"
|
||||
{%- endif -%}>
|
||||
{{- _('Pretty') -}}
|
||||
</option>{{- '' -}}
|
||||
<option value="full"
|
||||
{%- if preferences.get_value('url_formatting') == 'full' %} selected="selected"
|
||||
{%- endif -%}>
|
||||
{{- _('Full') -}}
|
||||
</option>{{- '' -}}
|
||||
<option value="host"
|
||||
{%- if preferences.get_value('url_formatting') == 'host' %} selected="selected"
|
||||
{%- endif -%}>
|
||||
{{- _('Host') -}}
|
||||
</option>{{- '' -}}
|
||||
</select>{{- '' -}}
|
||||
</div>{{- '' -}}
|
||||
<div class="description">
|
||||
{{- _('Change result URL formatting') -}}
|
||||
</div>{{- '' -}}
|
||||
</fieldset>{{- '' -}}
|
|
@ -340,6 +340,14 @@ def get_enabled_categories(category_names: Iterable[str]):
|
|||
|
||||
|
||||
def get_pretty_url(parsed_url: urllib.parse.ParseResult):
|
||||
url_formatting_pref = request.preferences.get_value('url_formatting')
|
||||
|
||||
if url_formatting_pref == 'full':
|
||||
return [parsed_url.geturl()]
|
||||
|
||||
if url_formatting_pref == 'host':
|
||||
return [parsed_url.netloc]
|
||||
|
||||
path = parsed_url.path
|
||||
path = path[:-1] if len(path) > 0 and path[-1] == '/' else path
|
||||
path = unquote(path.replace("/", " › "))
|
||||
|
@ -356,6 +364,7 @@ def get_client_settings():
|
|||
'translations': get_translations(),
|
||||
'search_on_category_select': req_pref.get_value('search_on_category_select'),
|
||||
'hotkeys': req_pref.get_value('hotkeys'),
|
||||
'url_formatting': req_pref.get_value('url_formatting'),
|
||||
'theme_static_path': custom_url_for('static', filename='themes/simple'),
|
||||
}
|
||||
|
||||
|
@ -385,6 +394,7 @@ def render(template_name: str, **kwargs):
|
|||
kwargs['infinite_scroll'] = request.preferences.get_value('infinite_scroll')
|
||||
kwargs['search_on_category_select'] = request.preferences.get_value('search_on_category_select')
|
||||
kwargs['hotkeys'] = request.preferences.get_value('hotkeys')
|
||||
kwargs['url_formatting'] = request.preferences.get_value('url_formatting')
|
||||
kwargs['results_on_new_tab'] = request.preferences.get_value('results_on_new_tab')
|
||||
kwargs['advanced_search'] = request.preferences.get_value('advanced_search')
|
||||
kwargs['query_in_title'] = request.preferences.get_value('query_in_title')
|
||||
|
|
Loading…
Reference in a new issue