diff --git a/docs/_dev/_static/cookie-banner.css b/docs/_static/cookie-banner.css similarity index 100% rename from docs/_dev/_static/cookie-banner.css rename to docs/_static/cookie-banner.css diff --git a/docs/_dev/_static/bundle.js b/docs/_static/js/bundle.js similarity index 100% rename from docs/_dev/_static/bundle.js rename to docs/_static/js/bundle.js diff --git a/docs/_static/js/overwrite_links.js b/docs/_static/js/overwrite_links.js new file mode 100644 index 0000000..5ca5234 --- /dev/null +++ b/docs/_static/js/overwrite_links.js @@ -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); +} \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index bc20aa8..2303e60 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 @@ -160,7 +160,7 @@ # TODO: If your documentation is hosted on https://docs.ubuntu.com/, # uncomment and update as needed. -# slug = '' +slug = 'kernel/docs' ####################### @@ -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: @@ -189,7 +190,7 @@ # Template and asset locations -html_static_path = ["_dev/_static"] +html_static_path = ["_static"] templates_path = ["_dev/_templates"] @@ -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", ]