diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-09-23 12:10:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-23 12:10:26 +0800 |
commit | be5411d6b576a3dd281e3e0ab016c02edfad77bb (patch) | |
tree | 47937df590ca4318fb4be9e06b2f9c807992466c | |
parent | bdf3be53b0b8005effb3bca8d9cc8dba7d35261c (diff) | |
download | gitea-be5411d6b576a3dd281e3e0ab016c02edfad77bb.tar.gz gitea-be5411d6b576a3dd281e3e0ab016c02edfad77bb.zip |
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.
-rw-r--r-- | templates/repo/clone_script.tmpl | 6 | ||||
-rw-r--r-- | templates/repo/home.tmpl | 26 |
2 files changed, 18 insertions, 14 deletions
diff --git a/templates/repo/clone_script.tmpl b/templates/repo/clone_script.tmpl index 5c9a545cad..97fd61d83d 100644 --- a/templates/repo/clone_script.tmpl +++ b/templates/repo/clone_script.tmpl @@ -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> // synchronously set clone button states and urls here to avoid flickering // on page load. initRepoCloneLink calls this when proto changes. @@ -21,8 +24,9 @@ for (const el of document.getElementsByClassName('js-clone-url')) { el[el.nodeName === 'INPUT' ? 'value' : 'textContent'] = link; } + const sep = '//'; 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> diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 2f9b1f25b7..18c02aa9ec 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -116,19 +116,19 @@ <!-- Only show clone panel in repository home page --> {{if eq $n 0}} <div class="ui action tiny input" id="clone-panel"> - {{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"> - {{svg "octicon-download"}} - <div class="menu"> - {{if not $.DisableDownloadSourceArchives}} - <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> - <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> - <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> - {{end}} - <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> - </button> + {{template "repo/clone_buttons" .}} + <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"}} + <div class="menu"> + {{if not $.DisableDownloadSourceArchives}} + <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> + <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> + <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> + {{end}} + <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> + </button> + {{template "repo/clone_script" .}}{{/* the script will update `.js-clone-url` and related elements */}} </div> {{end}} {{if and (ne $n 0) (not .IsViewFile) (not .IsBlame) }} |