Skip to content

Commit be5411d

Browse files
authored
Make Clone in VSCode link get updated correctly (#21225) (#21226)
Backport #21225, fix for #21128 (also in 1.17.3), close #21224 The indent was incorrect before, so this PR did some formatting work. Bypass Golang's template bug for JS string interpolation. And since there are JS lint rules for templates, so the string interpolation is also a must.
1 parent bdf3be5 commit be5411d

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

templates/repo/clone_script.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{{/*Golang's template has a bug with string interpolation containing slashes,
2+
the double slash will be treated as a comment there.
3+
But there are also JS lint rules for template that require to use string interpolation in 1.17*/}}
14
<script>
25
// synchronously set clone button states and urls here to avoid flickering
36
// on page load. initRepoCloneLink calls this when proto changes.
@@ -21,8 +24,9 @@
2124
for (const el of document.getElementsByClassName('js-clone-url')) {
2225
el[el.nodeName === 'INPUT' ? 'value' : 'textContent'] = link;
2326
}
27+
const sep = '//';
2428
for (const el of document.getElementsByClassName('js-clone-url-vsc')) {
25-
el['href'] = `vscode://vscode.git/clone?url=${encodeURIComponent(link)}`;
29+
el.href = `vscode:${sep}vscode.git/clone?url=${encodeURIComponent(link)}`;
2630
}
2731
})();
2832
</script>

templates/repo/home.tmpl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,19 @@
116116
<!-- Only show clone panel in repository home page -->
117117
{{if eq $n 0}}
118118
<div class="ui action tiny input" id="clone-panel">
119-
{{template "repo/clone_buttons" .}}
120-
{{template "repo/clone_script" .}}
121-
<button id="download-btn" class="ui basic small compact jump dropdown icon button tooltip" data-content="{{.i18n.Tr "repo.download_archive"}}" data-position="top right">
122-
{{svg "octicon-download"}}
123-
<div class="menu">
124-
{{if not $.DisableDownloadSourceArchives}}
125-
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.zip" rel="nofollow">{{svg "octicon-file-zip" 16 "mr-3"}}{{.i18n.Tr "repo.download_zip"}}</a>
126-
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip" 16 "mr-3"}}{{.i18n.Tr "repo.download_tar"}}</a>
127-
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.bundle" rel="nofollow">{{svg "octicon-package" 16 "mr-3"}}{{.i18n.Tr "repo.download_bundle"}}</a>
128-
{{end}}
129-
<a class="item js-clone-url-vsc" href="vscode://vscode.git/clone?url={{.CloneButtonOriginLink.HTTPS}}">{{svg "gitea-vscode" 16 "mr-3"}}{{.i18n.Tr "repo.clone_in_vsc"}}</a>
130-
</div>
131-
</button>
119+
{{template "repo/clone_buttons" .}}
120+
<button id="download-btn" class="ui basic small compact jump dropdown icon button tooltip" data-content="{{.i18n.Tr "repo.download_archive"}}" data-position="top right">
121+
{{svg "octicon-download"}}
122+
<div class="menu">
123+
{{if not $.DisableDownloadSourceArchives}}
124+
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.zip" rel="nofollow">{{svg "octicon-file-zip" 16 "mr-3"}}{{.i18n.Tr "repo.download_zip"}}</a>
125+
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip" 16 "mr-3"}}{{.i18n.Tr "repo.download_tar"}}</a>
126+
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.bundle" rel="nofollow">{{svg "octicon-package" 16 "mr-3"}}{{.i18n.Tr "repo.download_bundle"}}</a>
127+
{{end}}
128+
<a class="item js-clone-url-vsc" href="vscode://vscode.git/clone?url={{.CloneButtonOriginLink.HTTPS}}">{{svg "gitea-vscode" 16 "mr-3"}}{{.i18n.Tr "repo.clone_in_vsc"}}</a>
129+
</div>
130+
</button>
131+
{{template "repo/clone_script" .}}{{/* the script will update `.js-clone-url` and related elements */}}
132132
</div>
133133
{{end}}
134134
{{if and (ne $n 0) (not .IsViewFile) (not .IsBlame) }}

0 commit comments

Comments
 (0)