Source code for swh.docs.sphinx.view_in_phabricator

# Copyright (C) 2021  The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information

"""
Shows a link 'View this page in Phabricator' on top of each page.
"""


[docs]def html_page_context(app, pagename, templatename, context, doctree): if pagename.startswith("apidoc/"): # Auto-generated documentation. # TODO: link to the .py context["show_source"] = False return elif pagename.startswith("swh-"): # .rst from a package's docs/ directory (repository, _, path) = pagename.partition("/") else: # .rst from swh-docs/docs/ repository = "swh-docs" path = pagename source_url = ( f"https://forge.softwareheritage.org/source/{repository}" f"/browse/master/docs/{path}" ) # Set a variable that can be used by swh-docs/docs/_templates/breadcrumbs.html: context["swh_source_url"] = source_url
[docs]def setup(app): app.connect("html-page-context", html_page_context)