From bb19c7eccf9b24927930fb364c1dc84df6a1475f Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Wed, 16 Mar 2022 22:23:33 +0100 Subject: [PATCH 1/2] Sphinx doc: rename "User documentation" to "User Information" --- docs/user/index.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/user/index.rst b/docs/user/index.rst index dc9fb0da2..af2051f01 100644 --- a/docs/user/index.rst +++ b/docs/user/index.rst @@ -1,6 +1,6 @@ -================== -User documentation -================== +================ +User information +================ .. contents:: Contents :depth: 3 From dbe3eaabc929fb1a9d2da8e69ab6e70ba5bcf172 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Wed, 16 Mar 2022 22:24:35 +0100 Subject: [PATCH 2/2] Info: code refactoring & bug fixes --- searx/infopage/__init__.py | 26 +++++++++++++++----------- searx/templates/oscar/info.html | 2 +- searx/templates/simple/info.html | 2 +- searx/webapp.py | 30 +++++++++--------------------- searxng_extra/docs_prebuild | 2 +- 5 files changed, 27 insertions(+), 35 deletions(-) diff --git a/searx/infopage/__init__.py b/searx/infopage/__init__.py index 9b181ad60..44f3bdbd7 100644 --- a/searx/infopage/__init__.py +++ b/searx/infopage/__init__.py @@ -116,20 +116,20 @@ class InfoPageSet: # pylint: disable=too-few-public-methods self, page_class: typing.Optional[typing.Type[InfoPage]] = None, info_folder: typing.Optional[str] = None ): self.page_class = page_class or InfoPage - self.CACHE: typing.Dict[tuple, typing.Optional[InfoPage]] = {} - - # future: could be set from settings.xml - self.folder: str = info_folder or _INFO_FOLDER """location of the Markdwon files""" + self.CACHE: typing.Dict[tuple, typing.Optional[InfoPage]] = {} + self.locale_default: str = 'en' """default language""" - self.locales: typing.List = [locale for locale in os.listdir(_INFO_FOLDER) if locale in LOCALE_NAMES] + self.locales: typing.List[str] = [ + locale.replace('_', '-') for locale in os.listdir(_INFO_FOLDER) if locale.replace('_', '-') in LOCALE_NAMES + ] """list of supported languages (aka locales)""" - self.toc: typing.List = [ + self.toc: typing.List[str] = [ 'search-syntax', 'about', ] @@ -161,7 +161,7 @@ class InfoPageSet: # pylint: disable=too-few-public-methods # not yet instantiated - fname = os.path.join(self.folder, locale, pagename) + '.md' + fname = os.path.join(self.folder, locale.replace('-', '_'), pagename) + '.md' if not os.path.exists(fname): logger.info('file %s does not exists', fname) self.CACHE[cache_key] = None @@ -171,9 +171,13 @@ class InfoPageSet: # pylint: disable=too-few-public-methods self.CACHE[cache_key] = page return page - def all_pages(self, locale: typing.Optional[str] = None): + def iter_pages(self, locale: typing.Optional[str] = None, fallback_to_default=False): """Iterate over all pages of the TOC""" locale = locale or self.locale_default - for pagename in self.toc: - page = self.get_page(pagename, locale) - yield pagename, page + for page_name in self.toc: + page_locale = locale + page = self.get_page(page_name, locale) + if fallback_to_default and page is None: + page_locale = self.locale_default + page = self.get_page(page_name, self.locale_default) + yield page_name, page_locale, page diff --git a/searx/templates/oscar/info.html b/searx/templates/oscar/info.html index 0c2044adb..c12446a08 100644 --- a/searx/templates/oscar/info.html +++ b/searx/templates/oscar/info.html @@ -2,7 +2,7 @@ {% block title %}{{ active_page.title }} - {% endblock %} {% block content %}