1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-26 13:29:12 -05:00

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.
This commit is contained in:
wxiaoguang 2022-09-23 12:10:26 +08:00 committed by GitHub
parent bdf3be53b0
commit be5411d6b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 14 deletions

View file

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

View file

@ -117,7 +117,6 @@
{{if eq $n 0}} {{if eq $n 0}}
<div class="ui action tiny input" id="clone-panel"> <div class="ui action tiny input" id="clone-panel">
{{template "repo/clone_buttons" .}} {{template "repo/clone_buttons" .}}
{{template "repo/clone_script" .}}
<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"> <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">
{{svg "octicon-download"}} {{svg "octicon-download"}}
<div class="menu"> <div class="menu">
@ -129,6 +128,7 @@
<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> <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>
</div> </div>
</button> </button>
{{template "repo/clone_script" .}}{{/* the script will update `.js-clone-url` and related elements */}}
</div> </div>
{{end}} {{end}}
{{if and (ne $n 0) (not .IsViewFile) (not .IsBlame) }} {{if and (ne $n 0) (not .IsViewFile) (not .IsBlame) }}