conf.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. import sys, os
  3. from pathlib import Path
  4. from pallets_sphinx_themes import ProjectLink
  5. from searx import get_setting
  6. from searx.version import VERSION_STRING, GIT_URL, GIT_BRANCH
  7. # Project --------------------------------------------------------------
  8. project = 'SearXNG'
  9. copyright = 'SearXNG team'
  10. author = 'SearXNG team'
  11. release, version = VERSION_STRING, VERSION_STRING
  12. SEARXNG_URL = get_setting('server.base_url') or 'https://example.org/searxng'
  13. ISSUE_URL = get_setting('brand.issue_url')
  14. DOCS_URL = get_setting('brand.docs_url')
  15. PUBLIC_INSTANCES = get_setting('brand.public_instances')
  16. PRIVACYPOLICY_URL = get_setting('general.privacypolicy_url')
  17. CONTACT_URL = get_setting('general.contact_url')
  18. WIKI_URL = get_setting('brand.wiki_url')
  19. SOURCEDIR = Path(__file__).parent.parent / "searx"
  20. os.environ['SOURCEDIR'] = str(SOURCEDIR)
  21. # hint: sphinx.ext.viewcode won't highlight when 'highlight_language' [1] is set
  22. # to string 'none' [2]
  23. #
  24. # [1] https://www.sphinx-doc.org/en/master/usage/extensions/viewcode.html
  25. # [2] https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-highlight_language
  26. highlight_language = 'default'
  27. # General --------------------------------------------------------------
  28. master_doc = "index"
  29. source_suffix = '.rst'
  30. numfig = True
  31. exclude_patterns = ['build-templates/*.rst', 'user/*.md']
  32. import searx.engines
  33. import searx.plugins
  34. import searx.webutils
  35. # import searx.webapp is needed to init the engines & plugins, to init a
  36. # (empty) secret_key is needed.
  37. searx.settings['server']['secret_key'] = ''
  38. import searx.webapp
  39. searx.engines.load_engines(searx.settings['engines'])
  40. jinja_contexts = {
  41. 'searx': {
  42. 'engines': searx.engines.engines,
  43. 'plugins': searx.plugins.plugins,
  44. 'version': {
  45. 'node': os.getenv('NODE_MINIMUM_VERSION')
  46. },
  47. 'enabled_engine_count': sum(not x.disabled for x in searx.engines.engines.values()),
  48. 'categories': searx.engines.categories,
  49. 'categories_as_tabs': {c: searx.engines.categories[c] for c in searx.settings['categories_as_tabs']},
  50. },
  51. }
  52. jinja_filters = {
  53. 'group_engines_in_tab': searx.webutils.group_engines_in_tab,
  54. }
  55. # Let the Jinja template in configured_engines.rst access documented_modules
  56. # to automatically link documentation for modules if it exists.
  57. def setup(app):
  58. ENGINES_DOCNAME = 'user/configured_engines'
  59. def before_read_docs(app, env, docnames):
  60. assert ENGINES_DOCNAME in docnames
  61. docnames.remove(ENGINES_DOCNAME)
  62. docnames.append(ENGINES_DOCNAME)
  63. # configured_engines must come last so that sphinx already has
  64. # discovered the python module documentations
  65. def source_read(app, docname, source):
  66. if docname == ENGINES_DOCNAME:
  67. jinja_contexts['searx']['documented_modules'] = app.env.domains['py'].modules
  68. app.connect('env-before-read-docs', before_read_docs)
  69. app.connect('source-read', source_read)
  70. # usage:: lorem :patch:`f373169` ipsum
  71. extlinks = {}
  72. # upstream links
  73. extlinks['wiki'] = ('https://github.com/searxng/searxng/wiki/%s', ' %s')
  74. extlinks['pull'] = ('https://github.com/searxng/searxng/pull/%s', 'PR %s')
  75. extlinks['pull-searx'] = ('https://github.com/searx/searx/pull/%s', 'PR %s')
  76. # links to custom brand
  77. extlinks['origin'] = (GIT_URL + '/blob/' + GIT_BRANCH + '/%s', 'git://%s')
  78. extlinks['patch'] = (GIT_URL + '/commit/%s', '#%s')
  79. extlinks['docs'] = (DOCS_URL + '/%s', 'docs: %s')
  80. extlinks['pypi'] = ('https://pypi.org/project/%s', 'PyPi: %s')
  81. extlinks['man'] = ('https://manpages.debian.org/jump?q=%s', '%s')
  82. #extlinks['role'] = (
  83. # 'https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-%s', '')
  84. extlinks['duref'] = (
  85. 'https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#%s', '%s')
  86. extlinks['durole'] = (
  87. 'https://docutils.sourceforge.io/docs/ref/rst/roles.html#%s', '%s')
  88. extlinks['dudir'] = (
  89. 'https://docutils.sourceforge.io/docs/ref/rst/directives.html#%s', '%s')
  90. extlinks['ctan'] = (
  91. 'https://ctan.org/pkg/%s', 'CTAN: %s')
  92. extensions = [
  93. 'sphinx.ext.imgmath',
  94. 'sphinx.ext.extlinks',
  95. 'sphinx.ext.viewcode',
  96. "sphinx.ext.autodoc",
  97. "sphinx.ext.intersphinx",
  98. "pallets_sphinx_themes",
  99. "sphinx_issues", # https://github.com/sloria/sphinx-issues/blob/master/README.rst
  100. "sphinx_jinja", # https://github.com/tardyp/sphinx-jinja
  101. "sphinxcontrib.programoutput", # https://github.com/NextThought/sphinxcontrib-programoutput
  102. 'linuxdoc.kernel_include', # Implementation of the 'kernel-include' reST-directive.
  103. 'linuxdoc.rstFlatTable', # Implementation of the 'flat-table' reST-directive.
  104. 'linuxdoc.kfigure', # Sphinx extension which implements scalable image handling.
  105. "sphinx_tabs.tabs", # https://github.com/djungelorm/sphinx-tabs
  106. 'myst_parser', # https://www.sphinx-doc.org/en/master/usage/markdown.html
  107. 'notfound.extension', # https://github.com/readthedocs/sphinx-notfound-page
  108. 'sphinxcontrib.autodoc_pydantic', # https://github.com/mansenfranzen/autodoc_pydantic
  109. ]
  110. autodoc_default_options = {
  111. 'member-order': 'groupwise',
  112. }
  113. myst_enable_extensions = [
  114. "replacements", "smartquotes"
  115. ]
  116. suppress_warnings = ['myst.domains']
  117. intersphinx_mapping = {
  118. "python": ("https://docs.python.org/3/", None),
  119. "babel" : ("https://babel.readthedocs.io/en/latest/", None),
  120. "flask": ("https://flask.palletsprojects.com/", None),
  121. "flask_babel": ("https://python-babel.github.io/flask-babel/", None),
  122. # "werkzeug": ("https://werkzeug.palletsprojects.com/", None),
  123. "jinja": ("https://jinja.palletsprojects.com/", None),
  124. "linuxdoc" : ("https://return42.github.io/linuxdoc/", None),
  125. "sphinx" : ("https://www.sphinx-doc.org/en/master/", None),
  126. "redis": ('https://redis.readthedocs.io/en/stable/', None),
  127. }
  128. issues_github_path = "searxng/searxng"
  129. # HTML -----------------------------------------------------------------
  130. # https://searxng.github.io/searxng --> '/searxng/'
  131. # https://docs.searxng.org --> '/'
  132. notfound_urls_prefix = '/'
  133. sys.path.append(os.path.abspath('_themes'))
  134. sys.path.insert(0, os.path.abspath("../utils/"))
  135. html_theme_path = ['_themes']
  136. html_theme = "searxng"
  137. # sphinx.ext.imgmath setup
  138. html_math_renderer = 'imgmath'
  139. imgmath_image_format = 'svg'
  140. imgmath_font_size = 14
  141. # sphinx.ext.imgmath setup END
  142. html_show_sphinx = False
  143. html_theme_options = {"index_sidebar_logo": True}
  144. html_context = {"project_links": [] }
  145. html_context["project_links"].append(ProjectLink("Source", GIT_URL + '/tree/' + GIT_BRANCH))
  146. if WIKI_URL:
  147. html_context["project_links"].append(ProjectLink("Wiki", WIKI_URL))
  148. if PUBLIC_INSTANCES:
  149. html_context["project_links"].append(ProjectLink("Public instances", PUBLIC_INSTANCES))
  150. if ISSUE_URL:
  151. html_context["project_links"].append(ProjectLink("Issue Tracker", ISSUE_URL))
  152. if PRIVACYPOLICY_URL:
  153. html_context["project_links"].append(ProjectLink("Privacy Policy", PRIVACYPOLICY_URL))
  154. if CONTACT_URL:
  155. html_context["project_links"].append(ProjectLink("Contact", CONTACT_URL))
  156. html_sidebars = {
  157. "**": [
  158. "globaltoc.html",
  159. "project.html",
  160. "relations.html",
  161. "searchbox.html",
  162. "sourcelink.html"
  163. ],
  164. }
  165. singlehtml_sidebars = {"index": ["project.html", "localtoc.html"]}
  166. html_logo = "../src/brand/searxng-wordmark.svg"
  167. html_title = "SearXNG Documentation ({})".format(VERSION_STRING)
  168. html_show_sourcelink = True
  169. # LaTeX ----------------------------------------------------------------
  170. latex_documents = [
  171. (master_doc, "searxng-{}.tex".format(VERSION_STRING), html_title, author, "manual")
  172. ]