Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions docs/_static/js/overwrite_links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Replaces rtd-address with new-address in links

const rtd_address = 'http://canonical-real-time-ubuntu-documentation.readthedocs-hosted.com'

const new_address = 'ubuntu.com/real-time/docs';

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

function overwriteMatchingAnchorUrls(container) {
if (!container) return;

const rtd_addressRegex = new RegExp(escapeRegExp(rtd_address), 'g');
container.querySelectorAll('a[href], link[href]').forEach((anchor) => {
anchor.href = anchor.href.replace(rtd_addressRegex, new_address);
});
}

function patchFlyout() {
const rtdFlyout = document.querySelector('readthedocs-flyout');
if (!rtdFlyout) return false;

overwriteMatchingAnchorUrls(rtdFlyout);
overwriteMatchingAnchorUrls(rtdFlyout.shadowRoot);

rtdFlyout.addEventListener('click', () => {
overwriteMatchingAnchorUrls(rtdFlyout);
overwriteMatchingAnchorUrls(rtdFlyout.shadowRoot);
});

return true;
}

function init() {
overwriteMatchingAnchorUrls(document.querySelector('header'));

if (patchFlyout()) return;

const observer = new MutationObserver(() => {
if (patchFlyout()) {
observer.disconnect();
}
});

observer.observe(document.body, { childList: true, subtree: true });
}

if (document.body) {
init();
} else {
document.addEventListener('DOMContentLoaded', init);
}
8 changes: 5 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
html_title = project + " documentation"

# Documentation website URL
ogp_site_url = os.environ.get("READTHEDOCS_CANONICAL_URL", "/")
ogp_site_url = "https://ubuntu.com/real-time/docs/"

# Preview name of the documentation website
# TODO: To use a different name for the project in previews, update the next line.
Expand Down Expand Up @@ -112,17 +112,18 @@
# Project slug
# TODO: If your documentation is hosted on https://documentation.ubuntu.com/,
# uncomment and set to the RTD slug.
slug = 'real-time'
slug = 'real-time/docs'

#######################
# Sitemap configuration: https://sphinx-sitemap.readthedocs.io/
#######################

# Use RTD canonical URL to ensure duplicate pages have a specific canonical URL
html_baseurl = os.environ.get("READTHEDOCS_CANONICAL_URL", "/")
html_baseurl = "https://ubuntu.com/real-time/docs/"

# sphinx-sitemap uses html_baseurl to generate the full URL for each page:
sitemap_url_scheme = "{link}"
sitemap_filename = "doc-sitemap.xml"

# Include `lastmod` dates in the sitemap:
sitemap_show_lastmod = True
Expand Down Expand Up @@ -267,6 +268,7 @@
# Adds custom JavaScript files, located remotely or in 'html_static_path'.
html_js_files = [
"js/bundle.js",
"js/overwrite_links.js",
]

# Appends extra markup to the end of every document written in reST
Expand Down
Loading