diff --git a/docs/_templates/breadcrumbs.html b/docs/_templates/breadcrumbs.html
new file mode 100644
index 0000000..9db4a54
--- /dev/null
+++ b/docs/_templates/breadcrumbs.html
@@ -0,0 +1,16 @@
+{% extends "!breadcrumbs.html" %}
+
+{# Overrides RTD's default "View page source" link formatting, which
+ forces the full page name in the link; but we don't want it because
+ page names include the repo, eg. "swh-model/index".
+ The view_in_phabricator.py extension sets swh_source_url to
+ ".../source/swh-model/browse/master/docs/index"
+#}
+{%- block breadcrumbs_aside %}
+foo
+
+ {%- if hasdoc(pagename) and display_vcs_links %}
+ {{ _('View page source') }}
+ {% endif %}
+
+{%- endblock %}
diff --git a/swh/docs/sphinx/view_in_phabricator.py b/swh/docs/sphinx/view_in_phabricator.py
index 64929a6..cd7b40d 100644
--- a/swh/docs/sphinx/view_in_phabricator.py
+++ b/swh/docs/sphinx/view_in_phabricator.py
@@ -1,31 +1,34 @@
# 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.
"""
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 = pagename.split("/", 1)[0]
- path = "docs/"
+ (repository, _, path) = pagename.partition("/")
else:
# .rst from swh-docs/docs/
repository = "swh-docs"
- path = "docs/"
- context[
- "source_url_prefix"
- ] = f"https://forge.softwareheritage.org/source/{repository}/browse/master/{path}"
+ 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
def setup(app):
app.connect("html-page-context", html_page_context)