Skip to content

Commit

Permalink
Make clone URL use current page's host (#22808)
Browse files Browse the repository at this point in the history
Follow #21986

Even if the ROOT_URL is incorrect, the clone URL on the UI should be
correct.

---------

Co-authored-by: Lunny Xiao <[email protected]>
  • Loading branch information
wxiaoguang and lunny authored Feb 9, 2023
1 parent 7ae10cb commit 29aea36
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion templates/repo/clone_script.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
const btn = isSSH ? sshBtn : httpsBtn;
if (!btn) return;
const link = btn.getAttribute('data-link');
let link = btn.getAttribute('data-link');
if (link.startsWith('http://') || link.startsWith('https://')) {
// use current protocol/host as the clone link
const url = new URL(link);
url.protocol = window.location.protocol;
url.host = window.location.host;
link = url.toString();
}
for (const el of document.getElementsByClassName('js-clone-url')) {
el[el.nodeName === 'INPUT' ? 'value' : 'textContent'] = link;
}
Expand Down

0 comments on commit 29aea36

Please sign in to comment.