Skip to content

Commit c19f795

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>
1 parent e599f5a commit c19f795

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

doc/.sphinx/_integration/add_config.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
if project == "LXD":
1313
html_baseurl = "https://canonical.com/lxd/docs/latest/"
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/canonical-microceph/latest/"
@@ -20,9 +21,13 @@
2021
# Override default header styles
2122
html_static_path = globals().get('html_static_path', []) + ["_static"]
2223
html_css_files = globals().get('html_css_files', []) + ['override-header.css']
24+
# Add js to overwrite MicroCloud links
25+
html_js_files = globals().get('html_js_files', []) + ['overwrite_microcloud_links.js']
2326
# Add "integrated" to the list of custom tags
2427
tags.add('integrated')
2528
elif project == "MicroOVN":
2629
html_baseurl = "https://ubuntu.com/docs/microovn/latest/"
27-
custom_tags.append('integrated')
28-
30+
tags.add('integrated')
31+
html_static_path = globals().get('html_static_path', []) + ["_static"]
32+
# Add js to overwrite MicroCloud links
33+
html_js_files = globals().get('html_js_files', []) + ['overwrite_microcloud_links.js']

doc/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,18 @@ integrate:
109109
# Add information about where to find the tags/docs to the doc sets
110110
cat .sphinx/_integration/add_config.py >> integration/lxd/doc/conf.py
111111
cat .sphinx/_integration/add_config.py >> integration/microceph/docs/conf.py
112-
cat .sphinx/_integration/add_config.py >> integration/microovn/docs/custom_conf.py
112+
cat .sphinx/_integration/add_config.py >> integration/microovn/docs/conf.py
113113

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

117+
# Copy MicroCloud `overwrite_links.js` to all repos
118+
cp _static/js/overwrite_links.js integration/lxd/doc/_static/js/overwrite_microcloud_links.js
119+
mkdir -p integration/microceph/docs/_static
120+
cp _static/js/overwrite_links.js integration/microceph/docs/_static/overwrite_microcloud_links.js
121+
mkdir -p integration/microovn/docs/_static
122+
cp _static/js/overwrite_links.js integration/microovn/docs/_static/overwrite_microcloud_links.js
123+
117124
# `html` builds the integrated docs.
118125
html: integrate install
119126
mkdir -p $(current_dir)/_build
@@ -230,4 +237,4 @@ spellcheck: spelling
230237
# "make mode" option. $(O) is meant as a shortcut for $(SPHINX_OPTS).
231238
%:
232239
$(MAKE) --no-print-directory install
233-
. $(DOCS_VENV); $(SPHINX_BUILD) -M $@ "$(DOCS_SOURCEDIR)" "$(DOCS_BUILDDIR)" $(SPHINX_OPTS) $(O)
240+
. $(DOCS_VENV); $(SPHINX_BUILD) -M $@ "$(DOCS_SOURCEDIR)" "$(DOCS_BUILDDIR)" $(SPHINX_OPTS) $(O)

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)