Skip to content

Commit de05e19

Browse files
doc: consistently overwrite MicroCloud links
- Copies the MicroCloud `overwrite_links.js` file into the cloned LXD, MicroCeph, and MicroOVN repos as `overwrite_microcloud_links.js`, so that the JavaScript loads across the integrated docs - Prefixes functions and variables in the MicroCloud `overwrite_links.js` file with `microcloud_` in order to prevent conflicts with the equivalents in the LXD, MicroCeph, and MicroOVN `overwrite_links.js` files. - Reconfigures the Makefile to append `add_config.py` to the end of the MicroOVN `conf.py` so that the addition of `overwrite_microcloud_links.js` to `html_js_files` applies to MicroOVN. Signed-off-by: Elijah Greenstein <elijah.greenstein@canonical.com> (cherry picked from commit fde8f1a)
1 parent 4316efe commit de05e19

3 files changed

Lines changed: 31 additions & 15 deletions

File tree

doc/.sphinx/_integration/add_config.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,25 @@
1212
if project == "LXD":
1313
html_baseurl = "https://canonical.com/lxd/docs/v5.21/"
1414
html_css_files = globals().get('html_css_files', []) + ['override-header.css']
15+
html_js_files = globals().get('html_js_files', []) + ['js/overwrite_microcloud_links.js']
1516
tags.add('integrated')
1617
elif project == "MicroCeph":
1718
html_baseurl = "https://documentation.ubuntu.com/microceph/v19.2.0-squid/"
1819
# Override default header styles
1920
html_static_path = globals().get('html_static_path', []) + ["_static"]
20-
html_css_files = globals().get('html_css_files', []) + ['override-header.css', 'https://assets.ubuntu.com/v1/d86746ef-cookie_banner.css']
21-
html_js_files = globals().get('html_js_files', []) + ['https://assets.ubuntu.com/v1/287a5e8f-bundle.js']
21+
html_css_files = globals().get('html_css_files', []) + [
22+
'override-header.css',
23+
'https://assets.ubuntu.com/v1/d86746ef-cookie_banner.css',
24+
]
25+
html_js_files = globals().get('html_js_files', []) + [
26+
'https://assets.ubuntu.com/v1/287a5e8f-bundle.js',
27+
'overwrite_microcloud_links.js', # Add js to overwrite MicroCloud links
28+
]
2229
# Add "integrated" to the list of custom tags
2330
tags.add('integrated')
2431
elif project == "MicroOVN":
2532
html_baseurl = "https://ubuntu.com/docs/microovn/24.03/"
26-
custom_tags.append('integrated')
27-
33+
tags.add('integrated')
34+
html_static_path = globals().get('html_static_path', []) + ["_static"]
35+
# Add js to overwrite MicroCloud links
36+
html_js_files = globals().get('html_js_files', []) + ['overwrite_microcloud_links.js']

doc/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,18 @@ integrate:
117117
# Add information about where to find the tags/docs to the doc sets
118118
cat .sphinx/_integration/add_config.py >> integration/lxd/doc/conf.py
119119
cat .sphinx/_integration/add_config.py >> integration/microceph/docs/conf.py
120-
cat .sphinx/_integration/add_config.py >> integration/microovn/docs/custom_conf.py
120+
cat .sphinx/_integration/add_config.py >> integration/microovn/docs/conf.py
121121

122122
# Override the MicroOVN tag with the circle of friends one (for consistency)
123123
cp .sphinx/_integration/tag.png integration/microovn/docs/.sphinx/_static/microovn.png
124124

125+
# Copy MicroCloud `overwrite_links.js` to all repos
126+
cp _static/js/overwrite_links.js integration/lxd/doc/_static/js/overwrite_microcloud_links.js
127+
mkdir -p integration/microceph/docs/_static
128+
cp _static/js/overwrite_links.js integration/microceph/docs/_static/overwrite_microcloud_links.js
129+
mkdir -p integration/microovn/docs/_static
130+
cp _static/js/overwrite_links.js integration/microovn/docs/_static/overwrite_microcloud_links.js
131+
125132
# `html` builds the integrated docs.
126133
html: integrate install
127134
mkdir -p $(current_dir)/_build

doc/_static/js/overwrite_links.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
// Replace oldDomain with newDomain
2-
const oldDomain = 'canonical-microcloud-documentation.readthedocs-hosted.com';
3-
const newDomain = 'canonical.com/microcloud/docs';
2+
const microcloud_oldDomain = 'canonical-microcloud-documentation.readthedocs-hosted.com';
3+
const microcloud_newDomain = 'canonical.com/microcloud/docs';
44

5-
function escapeRegExp(value) {
5+
function microcloud_escapeRegExp(value) {
66
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
77
}
88

9-
function overwriteMatchingAnchorUrls(container) {
9+
function microcloud_overwriteMatchingAnchorUrls(container) {
1010
if (!container) return;
1111

1212
const anchors = container.querySelectorAll('a[href], link[href]');
13-
const oldDomainRegex = new RegExp(escapeRegExp(oldDomain), 'g');
13+
const oldDomainRegex = new RegExp(microcloud_escapeRegExp(microcloud_oldDomain), 'g');
1414

1515
anchors.forEach(anchor => {
16-
anchor.href = anchor.href.replace(oldDomainRegex, newDomain);
16+
anchor.href = anchor.href.replace(oldDomainRegex, microcloud_newDomain);
1717
});
1818
}
1919

20-
overwriteMatchingAnchorUrls(document.querySelector('header'));
20+
microcloud_overwriteMatchingAnchorUrls(document.querySelector('header'));
2121

2222
// Use a MutationObserver to wait for the RTD flyout element to appear in the DOM
23-
const observer = new MutationObserver(function(mutations, obs) {
23+
const microcloud_observer = new MutationObserver(function(mutations, obs) {
2424

2525
const rtdFlyout = document.querySelector('readthedocs-flyout');
2626
if (!rtdFlyout) return;
@@ -31,8 +31,8 @@
3131
const shadowRoot = rtdFlyout.shadowRoot;
3232
if (!shadowRoot) return;
3333

34-
overwriteMatchingAnchorUrls(shadowRoot);
34+
microcloud_overwriteMatchingAnchorUrls(shadowRoot);
3535
});
3636
});
3737

38-
observer.observe(document.body, { childList: true, subtree: true });
38+
microcloud_observer.observe(document.body, { childList: true, subtree: true });

0 commit comments

Comments
 (0)