Changeset View
Changeset View
Standalone View
Standalone View
swh/docs/sphinx/view_in_phabricator.py
Show All 10 Lines | |||||
def html_page_context(app, pagename, templatename, context, doctree): | def html_page_context(app, pagename, templatename, context, doctree): | ||||
if pagename.startswith("apidoc/"): | if pagename.startswith("apidoc/"): | ||||
# Auto-generated documentation. | # Auto-generated documentation. | ||||
# TODO: link to the .py | # TODO: link to the .py | ||||
context["show_source"] = False | context["show_source"] = False | ||||
return | return | ||||
elif pagename.startswith("swh-"): | elif pagename.startswith("swh-"): | ||||
# .rst from a package's docs/ directory | # .rst from a package's docs/ directory | ||||
repository = pagename.split("/", 1)[0] | (repository, _, path) = pagename.partition("/") | ||||
ardumont: clearer, thx | |||||
path = "docs/" | |||||
else: | else: | ||||
# .rst from swh-docs/docs/ | # .rst from swh-docs/docs/ | ||||
repository = "swh-docs" | repository = "swh-docs" | ||||
path = "docs/" | path = pagename | ||||
context[ | source_url = ( | ||||
"source_url_prefix" | f"https://forge.softwareheritage.org/source/{repository}" | ||||
] = f"https://forge.softwareheritage.org/source/{repository}/browse/master/{path}" | 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 | |||||
def setup(app): | def setup(app): | ||||
app.connect("html-page-context", html_page_context) | app.connect("html-page-context", html_page_context) |
clearer, thx