From 913b67f4ecf6c892dfc1280222e8a55987b64e4b Mon Sep 17 00:00:00 2001 From: Norwin Date: Sat, 30 Jul 2022 16:54:21 +0200 Subject: [PATCH 1/8] change vscode clone link to ssh --- templates/repo/home.tmpl | 2 +- web_src/js/features/repo-common.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 5e1af447a49a3..929a4161ed958 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -130,7 +130,7 @@ {{svg "octicon-file-zip" 16 "mr-3"}}{{.locale.Tr "repo.download_zip"}} {{svg "octicon-file-zip" 16 "mr-3"}}{{.locale.Tr "repo.download_tar"}} {{svg "octicon-package" 16 "mr-3"}}{{.locale.Tr "repo.download_bundle"}} - {{svg "gitea-vscode" 16 "mr-3"}}{{.locale.Tr "repo.clone_in_vsc"}} + {{svg "gitea-vscode" 16 "mr-3"}}{{.locale.Tr "repo.clone_in_vsc"}} diff --git a/web_src/js/features/repo-common.js b/web_src/js/features/repo-common.js index b0ecc5a651275..5c1eeed4873d8 100644 --- a/web_src/js/features/repo-common.js +++ b/web_src/js/features/repo-common.js @@ -73,6 +73,7 @@ export function initRepoCloneLink() { } // the empty repo guide $('.quickstart .empty-repo-guide .clone-url').text(cloneLink); + $('#repo-clone-vscode').attr('href', `vscode://vscode.git/clone?url=${encodeURIComponent(cloneLink)}`); }; updateUi(); From 836a7772a0a80431dedc7d16c666716467213d89 Mon Sep 17 00:00:00 2001 From: Norwin Date: Mon, 1 Aug 2022 13:53:07 +0200 Subject: [PATCH 2/8] adjust to new clone button script --- templates/repo/clone_script.tmpl | 6 +++++- templates/repo/home.tmpl | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/templates/repo/clone_script.tmpl b/templates/repo/clone_script.tmpl index 48b7ad3299ca2..237254f2ef111 100644 --- a/templates/repo/clone_script.tmpl +++ b/templates/repo/clone_script.tmpl @@ -1,6 +1,8 @@ diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index e4ec38b1a0645..486d6be4a15ac 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -124,7 +124,6 @@ {{if eq $n 0}} {{end}} + {{template "repo/clone_script" .}} {{end}} From 57472de63a2b4bd1f6f06e2f7655677af4807c5a Mon Sep 17 00:00:00 2001 From: Norwin Date: Mon, 1 Aug 2022 14:08:44 +0200 Subject: [PATCH 3/8] refactor: less inlining --- templates/repo/clone_script.tmpl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/templates/repo/clone_script.tmpl b/templates/repo/clone_script.tmpl index 237254f2ef111..30a7139ea4a6b 100644 --- a/templates/repo/clone_script.tmpl +++ b/templates/repo/clone_script.tmpl @@ -19,9 +19,11 @@ const link = btn.getAttribute('data-link'); for (const el of document.getElementsByClassName('js-clone-url')) { - let attr = el.nodeName === 'INPUT' ? 'value' : 'textContent'; - attr = el.getAttribute('data-attr') || attr; - el[attr] = `${el.getAttribute('data-prefix') || ''}${link}`; + const prefix = el.getAttribute('data-prefix') || ''; + let attr = el.getAttribute('data-attr'); + if (!attr) + attr = el.nodeName === 'INPUT' ? 'value' : 'textContent'; + el[attr] = prefix + link; } })(); From 7ab76a42190ba27d2e76b202457a8d9eac29992e Mon Sep 17 00:00:00 2001 From: Norwin Date: Mon, 1 Aug 2022 14:12:49 +0200 Subject: [PATCH 4/8] refactor: use separate class --- templates/repo/clone_script.tmpl | 14 +++++++------- templates/repo/home.tmpl | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/repo/clone_script.tmpl b/templates/repo/clone_script.tmpl index 30a7139ea4a6b..e56f04eea2df6 100644 --- a/templates/repo/clone_script.tmpl +++ b/templates/repo/clone_script.tmpl @@ -1,8 +1,8 @@ diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 486d6be4a15ac..3644da34df7a1 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -131,7 +131,7 @@ {{svg "octicon-file-zip" 16 "mr-3"}}{{.locale.Tr "repo.download_zip"}} {{svg "octicon-file-zip" 16 "mr-3"}}{{.locale.Tr "repo.download_tar"}} {{svg "octicon-package" 16 "mr-3"}}{{.locale.Tr "repo.download_bundle"}} - {{svg "gitea-vscode" 16 "mr-3"}}{{.locale.Tr "repo.clone_in_vsc"}} + {{svg "gitea-vscode" 16 "mr-3"}}{{.locale.Tr "repo.clone_in_vsc"}} {{end}} From cbbc83078a88ce27edef47ed16e82828382f8524 Mon Sep 17 00:00:00 2001 From: Norwin Date: Mon, 1 Aug 2022 14:15:01 +0200 Subject: [PATCH 5/8] fix syntax typo --- templates/repo/clone_script.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/clone_script.tmpl b/templates/repo/clone_script.tmpl index e56f04eea2df6..2f4e7f70ed18d 100644 --- a/templates/repo/clone_script.tmpl +++ b/templates/repo/clone_script.tmpl @@ -23,7 +23,7 @@ el[attr] = link; } for (const el of document.getElementsByClassName('js-clone-url-vs')) { - el['href'] = `vscode://vscode.git/clone?url=${encodeURIComponent(link)`; + el['href'] = `vscode://vscode.git/clone?url=${encodeURIComponent(link)}`; } })(); From fae64bf57e6795203fa2bd8b0e2621b04efcde2f Mon Sep 17 00:00:00 2001 From: Norwin Date: Mon, 1 Aug 2022 14:20:21 +0200 Subject: [PATCH 6/8] firefox doesnt like this `` literal?? --- templates/repo/clone_script.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/clone_script.tmpl b/templates/repo/clone_script.tmpl index 2f4e7f70ed18d..18a8dd5d30c27 100644 --- a/templates/repo/clone_script.tmpl +++ b/templates/repo/clone_script.tmpl @@ -23,7 +23,7 @@ el[attr] = link; } for (const el of document.getElementsByClassName('js-clone-url-vs')) { - el['href'] = `vscode://vscode.git/clone?url=${encodeURIComponent(link)}`; + el['href'] = 'vscode://vscode.git/clone?url=' + encodeURIComponent(link); } })(); From 09fb67fe4471d05c2122b4578bba9fe6a964925c Mon Sep 17 00:00:00 2001 From: Norwin Date: Mon, 1 Aug 2022 19:06:39 +0200 Subject: [PATCH 7/8] re-add default value for use without JS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit though nobody that disables js will use vscode 🙃 --- templates/repo/home.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 3644da34df7a1..e229e07d6faf6 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -131,7 +131,7 @@ {{svg "octicon-file-zip" 16 "mr-3"}}{{.locale.Tr "repo.download_zip"}} {{svg "octicon-file-zip" 16 "mr-3"}}{{.locale.Tr "repo.download_tar"}} {{svg "octicon-package" 16 "mr-3"}}{{.locale.Tr "repo.download_bundle"}} - {{svg "gitea-vscode" 16 "mr-3"}}{{.locale.Tr "repo.clone_in_vsc"}} + {{svg "gitea-vscode" 16 "mr-3"}}{{.locale.Tr "repo.clone_in_vsc"}} {{end}} From c6141111a261b70594f96b3a1fba27172e28609b Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 9 Sep 2022 10:53:04 +0800 Subject: [PATCH 8/8] Apply suggestions from code review --- templates/repo/clone_script.tmpl | 7 +++---- templates/repo/home.tmpl | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/templates/repo/clone_script.tmpl b/templates/repo/clone_script.tmpl index 18a8dd5d30c27..afd90040fb4e7 100644 --- a/templates/repo/clone_script.tmpl +++ b/templates/repo/clone_script.tmpl @@ -2,7 +2,7 @@ // synchronously set clone button states and urls here to avoid flickering // on page load. initRepoCloneLink calls this when proto changes. // this applies the protocol-dependant clone url to all elements with the - // `js-clone-url` and `js-clone-url-vs` classes. + // `js-clone-url` and `js-clone-url-vsc` classes. // TODO: This localStorage setting should be moved to backend user config // so it's available during rendering, then this inline script can be removed. (window.updateCloneStates = function() { @@ -19,10 +19,9 @@ const link = btn.getAttribute('data-link'); for (const el of document.getElementsByClassName('js-clone-url')) { - const attr = (el.nodeName === 'INPUT') ? 'value' : 'textContent'; - el[attr] = link; + el[el.nodeName === 'INPUT' ? 'value' : 'textContent'] = link; } - for (const el of document.getElementsByClassName('js-clone-url-vs')) { + for (const el of document.getElementsByClassName('js-clone-url-vsc')) { el['href'] = 'vscode://vscode.git/clone?url=' + encodeURIComponent(link); } })(); diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index a436af3754e1c..fe5af82d1a2f3 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -126,7 +126,7 @@ {{svg "octicon-file-zip" 16 "mr-3"}}{{.locale.Tr "repo.download_tar"}} {{svg "octicon-package" 16 "mr-3"}}{{.locale.Tr "repo.download_bundle"}} {{end}} - {{svg "gitea-vscode" 16 "mr-3"}}{{.locale.Tr "repo.clone_in_vsc"}} + {{svg "gitea-vscode" 16 "mr-3"}}{{.locale.Tr "repo.clone_in_vsc"}}