diff --git a/docs/_static/js/overwrite_links.js b/docs/_static/js/overwrite_links.js new file mode 100644 index 000000000..21c5e7834 --- /dev/null +++ b/docs/_static/js/overwrite_links.js @@ -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 }); \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index 3292d8121..2cd6299b2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -123,7 +123,7 @@ ### Additional files ############################################################ -html_static_path = ['.sphinx/_static'] +html_static_path = ['.sphinx/_static', '_static'] html_css_files = [ 'custom.css', diff --git a/docs/custom_conf.py b/docs/custom_conf.py index 4d6aebcb9..beec5d13f 100644 --- a/docs/custom_conf.py +++ b/docs/custom_conf.py @@ -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. @@ -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 @@ -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 @@ -139,7 +149,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. diff --git a/microceph/ceph/services.go b/microceph/ceph/services.go index d2393e340..07f2d35c8 100644 --- a/microceph/ceph/services.go +++ b/microceph/ceph/services.go @@ -217,6 +217,15 @@ func removeServiceDatabase(s interfaces.StateInterface, service string) error { return fmt.Errorf("failed to remove service from db %q: %w", service, err) } + // Clear mon host entry from config table. + if service == "mon" { + key := fmt.Sprintf("mon.host.%s", s.ClusterState().Name()) + err = database.DeleteConfigItem(ctx, tx, key) + if err != nil { + return err + } + } + return nil }) return err