1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-16 07:04:25 +00:00
gitea/templates/repo/empty.tmpl
wxiaoguang d4c789dfc1
Refactor repo clone button and repo clone links, fix JS error on empty repo page (#19208)
The last PR about clone buttons introduced an JS error when visiting an empty repo page:
* https://github.com/go-gitea/gitea/pull/19028
* `Uncaught ReferenceError: isSSH is not defined`, because the variables are scoped and doesn't share between sub templates.

This:
1. Simplify `templates/repo/clone_buttons.tmpl` and make code clear
2. Move most JS code into `initRepoCloneLink`
3. Remove unused `CloneLink.Git`
4. Remove `ctx.Data["DisableSSH"] / ctx.Data["ExposeAnonSSH"] / ctx.Data["DisableHTTP"]`, and only set them when is is needed (eg: deploy keys / ssh keys)
5. Introduce `Data["CloneButton*"]` to provide data for clone buttons and links
6. Introduce `Data["RepoCloneLink"]` for the repo clone link (not the wiki)
7. Remove most `ctx.Data["PageIsWiki"]` because it has been set in the `/wiki` middleware
8. Remove incorrect `quickstart` class in `migrating.tmpl`
2022-03-29 05:21:30 +02:00

79 lines
2.7 KiB
Handlebars

{{template "base/head" .}}
<div class="page-content repository quickstart">
{{template "repo/header" .}}
<div class="ui container">
<div class="ui grid">
<div class="sixteen wide column content">
{{template "base/alert" .}}
{{if .Repository.IsArchived}}
<div class="ui warning message">
{{.i18n.Tr "repo.archive.title"}}
</div>
{{end}}
{{if .Repository.IsBroken}}
<div class="ui segment center">
{{.i18n.Tr "repo.broken_message"}}
</div>
{{else if .CanWriteCode}}
<h4 class="ui top attached header">
{{.i18n.Tr "repo.quick_guide"}}
</h4>
<div class="ui attached guide table segment empty-repo-guide">
<div class="item">
<h3>{{.i18n.Tr "repo.clone_this_repo"}} <small>{{.i18n.Tr "repo.clone_helper" "http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository" | Str2html}}</small></h3>
<div class="ui action small input">
{{template "repo/clone_buttons" .}}
</div>
</div>
{{if not .Repository.IsArchived}}
<div class="ui divider"></div>
<div class="item">
<h3>{{.i18n.Tr "repo.create_new_repo_command"}}</h3>
<div class="markup">
<pre><code>touch README.md
git init
{{if ne .Repository.DefaultBranch "master"}}git checkout -b {{.Repository.DefaultBranch}}{{end}}
git add README.md
git commit -m "first commit"
git remote add origin <span class="clone-url"></span>
git push -u origin {{.Repository.DefaultBranch}}</code></pre>
</div>
</div>
<div class="ui divider"></div>
<div class="item">
<h3>{{.i18n.Tr "repo.push_exist_repo"}}</h3>
<div class="markup">
<pre><code>git remote add origin <span class="clone-url"></span>
git push -u origin {{.Repository.DefaultBranch}}</code></pre>
</div>
</div>
<!-- the clone-url content will be updated by initRepoCloneLink, the code below is used to avoid UI flicking -->
<script>
(() => {
const proto = localStorage.getItem('repo-clone-protocol') || 'https';
const btn = document.getElementById(`repo-clone-${proto}`);
const cloneUrls = document.getElementsByClassName('clone-url');
// it's ok if we didn't find the btn here, initRepoCloneLink will take all the work
if (btn) {
for (let i = 0; i < cloneUrls.length; i++) {
cloneUrls[i].textContent = btn.getAttribute('data-link');
}
}
})();
</script>
{{end}}
{{else}}
<div class="ui segment center">
{{.i18n.Tr "repo.empty_message"}}
</div>
{{end}}
</div>
</div>
</div>
</div>
</div>
{{template "base/footer" .}}