Skip to content
Open
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
File renamed without changes.
File renamed without changes.
52 changes: 52 additions & 0 deletions docs/_static/js/overwrite_links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Replaces rtd-address with new-address in links

const rtd_address = 'https://canonical-ta-kernel-docs-ha-proxy.readthedocs-hosted.com/';
const new_address = 'https://ubuntu.com/kernel/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);
}
12 changes: 7 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
# NOTE: The Open Graph Protocol (OGP) enhances page display in a social graph
# and is used by social media platforms; see https://ogp.me/

ogp_site_url = "https://canonical-kernel-docs.readthedocs-hosted.com/"
ogp_site_url = "https://ubuntu.com/kernel/docs"


# Preview name of the documentation website
Expand Down Expand Up @@ -160,7 +160,7 @@
# TODO: If your documentation is hosted on https://docs.ubuntu.com/,
# uncomment and update as needed.

# slug = ''
slug = 'kernel/docs'


#######################
Expand All @@ -169,11 +169,12 @@

# 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/kernel/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:

Expand All @@ -189,7 +190,7 @@

# Template and asset locations

html_static_path = ["_dev/_static"]
html_static_path = ["_static"]
templates_path = ["_dev/_templates"]


Expand Down Expand Up @@ -325,7 +326,8 @@
# Adds custom JavaScript files, located under 'html_static_path'

html_js_files = [
"bundle.js",
"js/bundle.js",
"js/overwrite_links.js",
]


Expand Down