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-microceph.readthedocs-hosted.com/';
const newDomain = 'canonical.com/ceph/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 });
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
### Additional files
############################################################

html_static_path = ['.sphinx/_static']
html_static_path = ['.sphinx/_static', '_static']

html_css_files = [
'custom.css',
Expand Down
16 changes: 13 additions & 3 deletions docs/custom_conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import os

# Custom configuration for the Sphinx documentation builder.
# All configuration specific to your project should be done in this file.
Expand Down Expand Up @@ -41,7 +42,8 @@

## Open Graph configuration - defines what is displayed in the website preview
# The URL of the documentation output
ogp_site_url = 'https://canonical-starter-pack.readthedocs-hosted.com/'
version_slug = f"{os.environ.get('READTHEDOCS_VERSION', 'local')}"
ogp_site_url = f"https://canonical.com/ceph/docs/{version_slug}/"
# The documentation website name (usually the same as the product name)
ogp_site_name = project
# An image or logo that is used in the preview
Expand Down Expand Up @@ -89,7 +91,15 @@

# If your project is on documentation.ubuntu.com, specify the project
# slug (for example, "lxd") here.
slug = ""
slug = 'ceph/docs'

# Base URL and sitemap configuration
html_baseurl = f"https://canonical.com/ceph/docs/{version_slug}/"

if 'READTHEDOCS_VERSION' in os.environ:
sitemap_url_scheme = '{version}{link}'
else:
sitemap_url_scheme = '{link}'

############################################################
### Redirects
Expand Down Expand Up @@ -140,7 +150,7 @@
custom_html_css_files = []

# Add JavaScript files (located in .sphinx/_static/)
custom_html_js_files = []
custom_html_js_files = ['js/overwrite_links.js']

## The following settings override the default configuration.

Expand Down
Loading