"""The Sphinx awesome theme as a Python package.:copyright: Copyright Kai Welke.:license: MIT, see LICENSE for details"""from__future__importannotationsfromdataclassesimportdataclass,fieldfromimportlib.metadataimportPackageNotFoundError,versionfrompathlibimportPathfromtypingimportAny,TypedDictfromdocutils.parsers.rstimportdirectivesfromsphinx.applicationimportSphinxfromsphinx.builders.htmlimportStandaloneHTMLBuilderfromsphinx.utilimportloggingfromsphinxcontrib.serializinghtmlimportJSONHTMLBuilderfrom.importjsonimplfrom.builderimportAwesomeHTMLBuilderfrom.codeimportAwesomeCodeBlockfrom.jinja_functionsimportsetup_jinjafrom.logosimportcopy_logos,setup_logo_path,update_configfrom.postprocessimportchanged_docs,post_process_htmlfrom.tocimportchange_toclogger=logging.getLogger(__name__)try:# obtain version from `pyproject.toml` via `importlib.metadata.version()`__version__=version(__name__)exceptPackageNotFoundError:# pragma: no cover__version__="unknown"
[docs]classLinkIcon(TypedDict):"""A link to an external resource, represented by an icon."""link:str"""The absolute URL to an external resource."""icon:str"""An SVG icon as a string."""
[docs]@dataclassclassThemeOptions:"""Helper class for configuring the Awesome Theme. Each attribute becomes a key in the :confval:`sphinx:html_theme_options` dictionary. """show_prev_next:bool=True"""If true, the theme includes links to the previous and next pages in the hierarchy."""show_breadcrumbs:bool=True"""If true, the theme includes `breadcrumbs <https://en.wikipedia.org/wiki/Breadcrumb_navigation>`_ links on every page except the root page."""breadcrumbs_separator:str="/""""The separator for the breadcrumbs links."""awesome_headerlinks:bool=True"""If true, clicking a headerlink copies its URL to the clipboard."""show_scrolltop:bool=False"""If true, the theme shows a button that scrolls to the top of the page when clicked."""awesome_external_links:bool=False"""If true, the theme includes an icon after external links and adds ``rel="nofollow noopener"`` to the links' attributes."""main_nav_links:dict[str,str]=field(default_factory=dict)"""A dictionary with links to include in the site header. The keys of this dictionary are the labels for the links. The values are absolute or relative URLs. """extra_header_link_icons:dict[str,LinkIcon]=field(default_factory=dict)"""A dictionary with extra icons to include on the right of the search bar. The keys are labels for the link's ``title`` attribute. The values are themselves :class:`LinkIcon`. """logo_light:str|None=None"""A path to a logo for the light mode. If you're using separate logos for light and dark mode, you **must** provide both logos."""logo_dark:str|None=None"""A path to a logo for the dark mode. If you're using separate logos for light and dark mode, you **must** provide both logos."""globaltoc_includehidden:bool=True"""If true, the theme includes entries from *hidden* :sphinxdocs:`toctree <usage/restructuredtext/directives.html#directive-toctree>` directives in the sidebar. The ``toctree`` directive generates a list of links on the page where you include it, unless you set the ``:hidden:`` option. This option is inherited from the ``basic`` theme. """
defsetup(app:Sphinx)->dict[str,Any]:"""Register the theme and its extensions wih Sphinx."""here=Path(__file__).parent.resolve()directives.register_directive("code-block",AwesomeCodeBlock)app.add_config_value("pygments_style_dark",None,"html",[str])# Monkey-patch galoreStandaloneHTMLBuilder.init_highlighter=AwesomeHTMLBuilder.init_highlighter# type: ignoreStandaloneHTMLBuilder.create_pygments_style_file=(# type: ignoreAwesomeHTMLBuilder.create_pygments_style_file)app.add_html_theme(name="sphinxawesome_theme",theme_path=str(here))app.add_js_file("theme.js",loading_method="defer")# Add the CSS overrides if we're using the `sphinx-design` extensionif"sphinx_design"inapp.config.extensions:app.add_css_file("awesome-sphinx-design.css",priority=900)# Add the CSS overrides if we're using the `myst-nb` extensionif"myst_nb"inapp.config.extensions:app.add_css_file("awesome-myst-nb.css",priority=900)if"sphinx_docsearch"inapp.config.extensions:app.add_css_file("awesome-docsearch.css",priority=900)app.config.html_context.update({"docsearch":True})# The theme is set up _after_ extensions are set up,# so I can't use internal extensions.# For the same reason, I also can't call the `config-inited` eventapp.connect("builder-inited",update_config)app.connect("html-page-context",setup_logo_path)app.connect("html-page-context",setup_jinja)app.connect("html-page-context",change_toc)app.connect("build-finished",copy_logos)app.connect("env-before-read-docs",changed_docs)app.connect("build-finished",post_process_html)JSONHTMLBuilder.out_suffix=".json"JSONHTMLBuilder.implementation=jsonimplJSONHTMLBuilder.indexer_format=jsonimplreturn{"version":__version__,"parallel_read_safe":True,"parallel_write_safe":True,}