Skip to content

Commit 29aea36

Browse files
wxiaoguanglunny
andauthored
Make clone URL use current page's host (#22808)
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]>
1 parent 7ae10cb commit 29aea36

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

templates/repo/clone_script.tmpl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@
1717
const btn = isSSH ? sshBtn : httpsBtn;
1818
if (!btn) return;
1919

20-
const link = btn.getAttribute('data-link');
20+
let link = btn.getAttribute('data-link');
21+
if (link.startsWith('http://') || link.startsWith('https://')) {
22+
// use current protocol/host as the clone link
23+
const url = new URL(link);
24+
url.protocol = window.location.protocol;
25+
url.host = window.location.host;
26+
link = url.toString();
27+
}
2128
for (const el of document.getElementsByClassName('js-clone-url')) {
2229
el[el.nodeName === 'INPUT' ? 'value' : 'textContent'] = link;
2330
}

0 commit comments

Comments
 (0)