Skip to content

Commit 5b5e900

Browse files
committed
[docs] Configure for canonical.com publication
1 parent 16198f7 commit 5b5e900

2 files changed

Lines changed: 46 additions & 4 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Replace oldDomain with newDomain
2+
const oldDomain = 'canonical-multipass1.readthedocs-hosted.com';
3+
const newDomain = 'canonical.com/multipass/docs';
4+
5+
function escapeRegExp(value) {
6+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
7+
}
8+
9+
function overwriteMatchingAnchorUrls(container) {
10+
if (!container) return;
11+
12+
const anchors = container.querySelectorAll('a[href], link[href]');
13+
const oldDomainRegex = new RegExp(escapeRegExp(oldDomain), 'g');
14+
15+
anchors.forEach(anchor => {
16+
anchor.href = anchor.href.replace(oldDomainRegex, newDomain);
17+
});
18+
}
19+
20+
overwriteMatchingAnchorUrls(document.querySelector('header'));
21+
22+
// Use a MutationObserver to wait for the RTD flyout element to appear in the DOM
23+
const observer = new MutationObserver(function(mutations, obs) {
24+
25+
const rtdFlyout = document.querySelector('readthedocs-flyout');
26+
if (!rtdFlyout) return;
27+
28+
obs.disconnect();
29+
30+
rtdFlyout.addEventListener('click', function() {
31+
const shadowRoot = rtdFlyout.shadowRoot;
32+
if (!shadowRoot) return;
33+
34+
overwriteMatchingAnchorUrls(shadowRoot);
35+
});
36+
});
37+
38+
observer.observe(document.body, { childList: true, subtree: true });

‎docs/conf.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
import ast
3+
import os
34

45
# Configuration for the Sphinx documentation builder.
56
# All configuration specific to your project should be done in this file.
@@ -70,10 +71,12 @@
7071
# NOTE: The Open Graph Protocol (OGP) enhances page display in a social graph
7172
# and is used by social media platforms; see https://ogp.me/
7273

73-
ogp_site_url = "https://documentation.ubuntu.com/multipass/en/latest/"
74+
version_slug = f"{os.environ.get('READTHEDOCS_VERSION', 'local')}"
75+
html_baseurl = f"https://canonical.com/multipass/docs/{version_slug}/"
76+
ogp_site_url = html_baseurl
7477

75-
html_baseurl = "https://documentation.ubuntu.com/multipass/" # for sitemap.xml, the trailing slash is important
76-
sitemap_url_scheme = "en/latest/{link}"
78+
sitemap_url_scheme = "{link}"
79+
sitemap_filename = "doc-sitemap.xml" # Required to avoid sitemap conflicts
7780

7881
# Preview name of the documentation website
7982
#
@@ -164,7 +167,7 @@
164167
# TODO: If your documentation is hosted on https://docs.ubuntu.com/,
165168
# uncomment and update as needed.
166169

167-
slug = "multipass"
170+
slug = "multipass/docs"
168171

169172

170173
# Template and asset locations
@@ -273,6 +276,7 @@
273276

274277
html_js_files = [
275278
"js/bundle.js",
279+
"js/overwrite_links.js",
276280
]
277281

278282

0 commit comments

Comments
 (0)