Skip to content
Draft
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
38 changes: 38 additions & 0 deletions docs/_static/js/overwrite_links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Replace oldDomain with newDomain
const oldDomain = 'canonical-chisel-migration.readthedocs-hosted.com';
const newDomain = 'ubuntu.com/chisel/docs/';

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

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

const anchors = container.querySelectorAll('a[href], link[href]');
const oldDomainRegex = new RegExp(escapeRegExp(oldDomain), 'g');

anchors.forEach(anchor => {
anchor.href = anchor.href.replace(oldDomainRegex, newDomain);
});
}

overwriteMatchingAnchorUrls(document.querySelector('header'));

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

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

obs.disconnect();

rtdFlyout.addEventListener('click', function() {
const shadowRoot = rtdFlyout.shadowRoot;
if (!shadowRoot) return;

overwriteMatchingAnchorUrls(shadowRoot);
});
});

observer.observe(document.body, { childList: true, subtree: true });
12 changes: 7 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
# Sidebar documentation title; best kept reasonably short
#
# TODO: To include a version number, add it here (hardcoded or automated).
#

version = f"{os.environ.get('READTHEDOCS_VERSION', 'local')}"

# TODO: To disable the title, set to an empty string.

html_title = project + " documentation"
Expand Down Expand Up @@ -70,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://documentation.ubuntu.com/chisel/"
ogp_site_url = f"https://ubuntu.com/chisel/docs//{version}/"


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

slug = "chisel"
slug = 'chisel/docs' # Or '<ecosystem>/<product>/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 = f"https://ubuntu.com/chisel/docs//{version}/"

# URL scheme. Add language and version scheme elements.
# When configured with RTD variables, check for RTD environment so manual runs succeed:
Expand Down Expand Up @@ -313,6 +315,7 @@

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


Expand Down Expand Up @@ -377,4 +380,3 @@
def setup(app):
app.add_css_file("tasklist.css")
app.add_js_file("tasklist.js") #checkbox-enabling JS

Loading