conf.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. # -*- coding: utf-8 -*-
  2. # SPDX-License-Identifier: AGPL-3.0-or-later
  3. import sys, os
  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 = '2021 SearXNG team, 2015-2021 Adam Tauber, Noémi Ványi'
  10. author = '2021 SearXNG team, 2015-2021 Adam Tauber'
  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. CONTACT_URL = get_setting('general.contact_url')
  17. WIKI_URL = get_setting('brand.wiki_url')
  18. # hint: sphinx.ext.viewcode won't highlight when 'highlight_language' [1] is set
  19. # to string 'none' [2]
  20. #
  21. # [1] https://www.sphinx-doc.org/en/master/usage/extensions/viewcode.html
  22. # [2] https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-highlight_language
  23. highlight_language = 'default'
  24. # General --------------------------------------------------------------
  25. master_doc = "index"
  26. source_suffix = '.rst'
  27. numfig = True
  28. exclude_patterns = ['build-templates/*.rst']
  29. import searx.engines
  30. import searx.plugins
  31. import searx.webutils
  32. searx.engines.load_engines(searx.settings['engines'])
  33. jinja_contexts = {
  34. 'searx': {
  35. 'engines': searx.engines.engines,
  36. 'plugins': searx.plugins.plugins,
  37. 'version': {
  38. 'node': os.getenv('NODE_MINIMUM_VERSION')
  39. },
  40. 'enabled_engine_count': sum(not x.disabled for x in searx.engines.engines.values()),
  41. 'categories': searx.engines.categories,
  42. 'categories_as_tabs': {c: searx.engines.categories[c] for c in searx.settings['categories_as_tabs']},
  43. },
  44. }
  45. jinja_filters = {
  46. 'group_engines_in_tab': searx.webutils.group_engines_in_tab,
  47. }
  48. # Let the Jinja template in configured_engines.rst access documented_modules
  49. # to automatically link documentation for modules if it exists.
  50. def setup(app):
  51. ENGINES_DOCNAME = 'admin/engines/configured_engines'
  52. def before_read_docs(app, env, docnames):
  53. assert ENGINES_DOCNAME in docnames
  54. docnames.remove(ENGINES_DOCNAME)
  55. docnames.append(ENGINES_DOCNAME)
  56. # configured_engines must come last so that sphinx already has
  57. # discovered the python module documentations
  58. def source_read(app, docname, source):
  59. if docname == ENGINES_DOCNAME:
  60. jinja_contexts['searx']['documented_modules'] = app.env.domains['py'].modules
  61. app.connect('env-before-read-docs', before_read_docs)
  62. app.connect('source-read', source_read)
  63. # usage:: lorem :patch:`f373169` ipsum
  64. extlinks = {}
  65. # upstream links
  66. extlinks['wiki'] = ('https://github.com/searxng/searxng/wiki/%s', ' ')
  67. extlinks['pull'] = ('https://github.com/searxng/searxng/pull/%s', 'PR ')
  68. extlinks['pull-searx'] = ('https://github.com/searx/searx/pull/%s', 'PR ')
  69. # links to custom brand
  70. extlinks['origin'] = (GIT_URL + '/blob/' + GIT_BRANCH + '/%s', 'git://')
  71. extlinks['patch'] = (GIT_URL + '/commit/%s', '#')
  72. extlinks['search'] = (SEARXNG_URL + '/%s', '#')
  73. extlinks['docs'] = (DOCS_URL + '/%s', 'docs: ')
  74. extlinks['pypi'] = ('https://pypi.org/project/%s', 'PyPi: ')
  75. extlinks['man'] = ('https://manpages.debian.org/jump?q=%s', '')
  76. #extlinks['role'] = (
  77. # 'https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-%s', '')
  78. extlinks['duref'] = (
  79. 'https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#%s', '')
  80. extlinks['durole'] = (
  81. 'https://docutils.sourceforge.io/docs/ref/rst/roles.html#%s', '')
  82. extlinks['dudir'] = (
  83. 'https://docutils.sourceforge.io/docs/ref/rst/directives.html#%s', '')
  84. extlinks['ctan'] = (
  85. 'https://ctan.org/pkg/%s', 'CTAN: ')
  86. extensions = [
  87. 'sphinx.ext.imgmath',
  88. 'sphinx.ext.extlinks',
  89. 'sphinx.ext.viewcode',
  90. "sphinx.ext.autodoc",
  91. "sphinx.ext.intersphinx",
  92. "pallets_sphinx_themes",
  93. "sphinx_issues", # https://github.com/sloria/sphinx-issues/blob/master/README.rst
  94. "sphinxcontrib.jinja", # https://github.com/tardyp/sphinx-jinja
  95. "sphinxcontrib.programoutput", # https://github.com/NextThought/sphinxcontrib-programoutput
  96. 'linuxdoc.kernel_include', # Implementation of the 'kernel-include' reST-directive.
  97. 'linuxdoc.rstFlatTable', # Implementation of the 'flat-table' reST-directive.
  98. 'linuxdoc.kfigure', # Sphinx extension which implements scalable image handling.
  99. "sphinx_tabs.tabs", # https://github.com/djungelorm/sphinx-tabs
  100. ]
  101. intersphinx_mapping = {
  102. "python": ("https://docs.python.org/3/", None),
  103. "flask": ("https://flask.palletsprojects.com/", None),
  104. # "werkzeug": ("https://werkzeug.palletsprojects.com/", None),
  105. "jinja": ("https://jinja.palletsprojects.com/", None),
  106. "linuxdoc" : ("https://return42.github.io/linuxdoc/", None),
  107. "sphinx" : ("https://www.sphinx-doc.org/en/master/", None),
  108. }
  109. issues_github_path = "searxng/searxng"
  110. # HTML -----------------------------------------------------------------
  111. sys.path.append(os.path.abspath('_themes'))
  112. sys.path.insert(0, os.path.abspath("../utils/"))
  113. html_theme_path = ['_themes']
  114. html_theme = "searxng"
  115. # sphinx.ext.imgmath setup
  116. html_math_renderer = 'imgmath'
  117. imgmath_image_format = 'svg'
  118. imgmath_font_size = 14
  119. # sphinx.ext.imgmath setup END
  120. html_theme_options = {"index_sidebar_logo": True}
  121. html_context = {"project_links": [] }
  122. html_context["project_links"].append(ProjectLink("Source", GIT_URL + '/tree/' + GIT_BRANCH))
  123. if WIKI_URL:
  124. html_context["project_links"].append(ProjectLink("Wiki", WIKI_URL))
  125. if PUBLIC_INSTANCES:
  126. html_context["project_links"].append(ProjectLink("Public instances", PUBLIC_INSTANCES))
  127. if ISSUE_URL:
  128. html_context["project_links"].append(ProjectLink("Issue Tracker", ISSUE_URL))
  129. if CONTACT_URL:
  130. html_context["project_links"].append(ProjectLink("Contact", CONTACT_URL))
  131. html_sidebars = {
  132. "**": [
  133. "globaltoc.html",
  134. "project.html",
  135. "relations.html",
  136. "searchbox.html",
  137. "sourcelink.html"
  138. ],
  139. }
  140. singlehtml_sidebars = {"index": ["project.html", "localtoc.html"]}
  141. html_logo = "../src/brand/searxng-wordmark.svg"
  142. html_title = "SearXNG Documentation ({})".format(VERSION_STRING)
  143. html_show_sourcelink = True
  144. # LaTeX ----------------------------------------------------------------
  145. latex_documents = [
  146. (master_doc, "searx-{}.tex".format(VERSION_STRING), html_title, author, "manual")
  147. ]