summaryrefslogtreecommitdiffstats
path: root/templates
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-02-09 17:29:13 +0800
committerGitHub <noreply@github.com>2023-02-09 17:29:13 +0800
commit29aea3642f5de5f1a8d4264f8360ddb5d072a861 (patch)
treed552181ba22e42f61e95183456f9771680aa487d /templates
parent7ae10cb7f1a520d46c2c92d60cf5181c3d7b6850 (diff)
downloadgitea-29aea3642f5de5f1a8d4264f8360ddb5d072a861.tar.gz
gitea-29aea3642f5de5f1a8d4264f8360ddb5d072a861.zip
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 <xiaolunwen@gmail.com>
Diffstat (limited to 'templates')
-rw-r--r--templates/repo/clone_script.tmpl9
1 files changed, 8 insertions, 1 deletions
diff --git a/templates/repo/clone_script.tmpl b/templates/repo/clone_script.tmpl
index afd90040fb..88a67d8235 100644
--- a/templates/repo/clone_script.tmpl
+++ b/templates/repo/clone_script.tmpl
@@ -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;
}