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
51 changes: 51 additions & 0 deletions _static/js/url_overwrite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// overwrite links.js
Copy link
Collaborator

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.js I would expect the file to be named links_overwrite.js to make things clear and explicit.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
// };
Copy link
Collaborator

Choose a reason for hiding this comment

The 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}.`)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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`)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

});
});
});
7 changes: 4 additions & 3 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/
Expand Down Expand Up @@ -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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

]


Expand Down