-
Notifications
You must be signed in to change notification settings - Fork 23
feat: rtd integration config changes #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: doc-domain-migration
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // overwrite links.js | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a copyright header. What license is this code under? |
||
|
|
||
| // Replace oldDomain with newDomain | ||
| const oldDomain = 'canonical-migration-anbox-docs.readthedocs-hosted.com'; | ||
| const newDomain = 'canonical.com/anbox-cloud/docs'; | ||
|
|
||
| // // Logging for debugging purposes | ||
| // console.stdlog = console.log.bind(console); | ||
| // console.logs = []; | ||
|
|
||
| // console.log = function() { | ||
| // // 1. Store the arguments in the logs array | ||
| // console.logs.push(Array.from(arguments)); | ||
|
|
||
| // // 2. Call the original console.log to still output to the browser console | ||
| // console.stdlog.apply(console, arguments); | ||
| // }; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is no longer need, can we drop it to avoid shipping unused code/commented code? |
||
|
|
||
| // Set up a mutation observer to monitor changes in the DOM | ||
| // RTD flyout is created dynamically, so we need to wait for it to appear | ||
| const targetNode = document.body; | ||
| const config = { childList: true, subtree: true }; | ||
|
|
||
| // Callback function to execute when mutation is observed | ||
| function waitForElement(element, callback){ | ||
| var foo = setInterval(function(){ | ||
| // console.log(`Waiting for element: ${element}...`) | ||
| if(document.querySelector(element)){ | ||
| clearInterval(foo); | ||
| // console.log(`Element found: ${element}.`) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please drop commented code |
||
| callback(); | ||
| } | ||
| }, 100); | ||
| } | ||
|
|
||
| // Start observing the target node (rtd-flyout) | ||
| // execute the overwrite when the element is loaded | ||
| waitForElement("readthedocs-flyout", function(){ | ||
| // console.log(`Triggering URL rewrite`) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
| const rtdFlyout = document.querySelector('readthedocs-flyout'); | ||
| rtdFlyout.addEventListener('click', function(e) { | ||
| // Access the shadow DOM of the 'readthedocs-flyout' element | ||
| const shadowRoot = rtdFlyout.shadowRoot; | ||
| const anchors = shadowRoot.querySelectorAll('a'); | ||
| anchors.forEach(anchor => { | ||
| // console.log(`Checking URL for replacement: ${anchor.href}`); | ||
| anchor.href = anchor.href.replace(new RegExp(oldDomain, 'g'), newDomain); | ||
| // console.log(`URL now: ${anchor.href}`); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,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/anbox-cloud/" | ||
| ogp_site_url = "https://canonical.com/anbox-cloud/docs/" | ||
|
|
||
|
|
||
| # Preview name of the documentation website | ||
|
|
@@ -170,7 +170,7 @@ | |
| # If your documentation is hosted on https://docs.ubuntu.com/, | ||
| # uncomment and update as needed. | ||
|
|
||
| slug = 'anbox-cloud' | ||
| slug = 'anbox-cloud/docs' | ||
|
|
||
| ####################### | ||
| # Sitemap configuration: https://sphinx-sitemap.readthedocs.io/ | ||
|
|
@@ -377,7 +377,8 @@ | |
| # Adds custom JavaScript files, located under 'html_static_path' | ||
|
|
||
| html_js_files = [ | ||
| "js/cookie-banner-bundle.js" | ||
| "js/cookie-banner-bundle.js", | ||
| "js/url_overwrite.js", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
| ] | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for? Not sure what magic this does but if it overwrites a
links.jsI would expect the file to be namedlinks_overwrite.jsto make things clear and explicit.