.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.infopage.InfoPageSet Class Reference

Public Member Functions

 __init__ (self, typing.Optional[typing.Type[InfoPage]] page_class=None, typing.Optional[str] info_folder=None)
 
 get_page (self, str pagename, typing.Optional[str] locale=None)
 
 iter_pages (self, typing.Optional[str] locale=None, fallback_to_default=False)
 

Public Attributes

 page_class = page_class or InfoPage
 
str folder = info_folder or _INFO_FOLDER
 
dict CACHE = {}
 
str locale_default = 'en'
 
list locales
 
list toc
 
tuple locales = (pagename, locale)
 
str CACHE = os.path.join(self.folder, locale.replace('-', '_'), pagename) + '.md'
 

Detailed Description

Cached rendering of the online documentation a SearXNG instance has.

:param page_class: render online documentation by :py:obj:`InfoPage` parser.
:type page_class: :py:obj:`InfoPage`

:param info_folder: information directory
:type info_folder: str

Definition at line 117 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

searx.infopage.InfoPageSet.__init__ ( self,
typing.Optional[typing.Type[InfoPage]] page_class = None,
typing.Optional[str] info_folder = None )

Definition at line 127 of file __init__.py.

129 ):
130 self.page_class = page_class or InfoPage
131 self.folder: str = info_folder or _INFO_FOLDER
132 """location of the Markdown files"""
133
134 self.CACHE: typing.Dict[tuple, typing.Optional[InfoPage]] = {}
135
136 self.locale_default: str = 'en'
137 """default language"""
138
139 self.locales: typing.List[str] = [
140 locale.replace('_', '-') for locale in os.listdir(_INFO_FOLDER) if locale.replace('_', '-') in LOCALE_NAMES
141 ]
142 """list of supported languages (aka locales)"""
143
144 self.toc: typing.List[str] = [
145 'search-syntax',
146 'about',
147 'donate',
148 ]
149 """list of articles in the online documentation"""
150

Member Function Documentation

◆ get_page()

searx.infopage.InfoPageSet.get_page ( self,
str pagename,
typing.Optional[str] locale = None )
Return ``pagename`` instance of :py:obj:`InfoPage`

:param pagename: name of the page, a value from :py:obj:`InfoPageSet.toc`
:type pagename: str

:param locale: language of the page, e.g. ``en``, ``zh_Hans_CN``
               (default: :py:obj:`InfoPageSet.i18n_origin`)
:type locale: str

Definition at line 151 of file __init__.py.

151 def get_page(self, pagename: str, locale: typing.Optional[str] = None):
152 """Return ``pagename`` instance of :py:obj:`InfoPage`
153
154 :param pagename: name of the page, a value from :py:obj:`InfoPageSet.toc`
155 :type pagename: str
156
157 :param locale: language of the page, e.g. ``en``, ``zh_Hans_CN``
158 (default: :py:obj:`InfoPageSet.i18n_origin`)
159 :type locale: str
160
161 """
162 locale = locale or self.locale_default
163
164 if pagename not in self.toc:
165 return None
166 if locale not in self.locales:
167 return None
168
169 cache_key = (pagename, locale)
170
171 if cache_key in self.CACHE:
172 return self.CACHE[cache_key]
173
174 # not yet instantiated
175
176 fname = os.path.join(self.folder, locale.replace('-', '_'), pagename) + '.md'
177 if not os.path.exists(fname):
178 logger.info('file %s does not exists', fname)
179 self.CACHE[cache_key] = None
180 return None
181
182 page = self.page_class(fname)
183 self.CACHE[cache_key] = page
184 return page
185

References searx.infopage.InfoPageSet.locale_default, and searx.infopage.InfoPageSet.toc.

Referenced by searx.infopage.InfoPageSet.iter_pages().

+ Here is the caller graph for this function:

◆ iter_pages()

searx.infopage.InfoPageSet.iter_pages ( self,
typing.Optional[str] locale = None,
fallback_to_default = False )
Iterate over all pages of the TOC

Definition at line 186 of file __init__.py.

186 def iter_pages(self, locale: typing.Optional[str] = None, fallback_to_default=False):
187 """Iterate over all pages of the TOC"""
188 locale = locale or self.locale_default
189 for page_name in self.toc:
190 page_locale = locale
191 page = self.get_page(page_name, locale)
192 if fallback_to_default and page is None:
193 page_locale = self.locale_default
194 page = self.get_page(page_name, self.locale_default)
195 if page is not None:
196 # page is None if the page was deleted by the administrator
197 yield page_name, page_locale, page

References searx.infopage.InfoPageSet.get_page(), searx.infopage.InfoPageSet.locale_default, and searx.infopage.InfoPageSet.toc.

+ Here is the call graph for this function:

Member Data Documentation

◆ CACHE [1/2]

dict searx.infopage.InfoPageSet.CACHE = {}

Definition at line 134 of file __init__.py.

◆ CACHE [2/2]

str searx.infopage.InfoPageSet.CACHE = os.path.join(self.folder, locale.replace('-', '_'), pagename) + '.md'

Definition at line 171 of file __init__.py.

◆ folder

str searx.infopage.InfoPageSet.folder = info_folder or _INFO_FOLDER

Definition at line 131 of file __init__.py.

◆ locale_default

str searx.infopage.InfoPageSet.locale_default = 'en'

◆ locales [1/2]

list searx.infopage.InfoPageSet.locales
Initial value:
= [
locale.replace('_', '-') for locale in os.listdir(_INFO_FOLDER) if locale.replace('_', '-') in LOCALE_NAMES
]

Definition at line 139 of file __init__.py.

◆ locales [2/2]

tuple searx.infopage.InfoPageSet.locales = (pagename, locale)

Definition at line 166 of file __init__.py.

◆ page_class

searx.infopage.InfoPageSet.page_class = page_class or InfoPage

Definition at line 130 of file __init__.py.

◆ toc

searx.infopage.InfoPageSet.toc
Initial value:
= [
'search-syntax',
'about',
'donate',
]

Definition at line 144 of file __init__.py.

Referenced by searx.infopage.InfoPageSet.get_page(), and searx.infopage.InfoPageSet.iter_pages().


The documentation for this class was generated from the following file: