Skip to content

Commit 8f10b46

Browse files
committed
simplify
1 parent a25a598 commit 8f10b46

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

modules/context/repo.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"code.gitea.io/gitea/modules/cache"
1717
"code.gitea.io/gitea/modules/git"
1818
"code.gitea.io/gitea/modules/log"
19+
"code.gitea.io/gitea/modules/markup"
1920
"code.gitea.io/gitea/modules/markup/markdown"
2021
"code.gitea.io/gitea/modules/setting"
2122
api "code.gitea.io/gitea/modules/structs"
@@ -378,9 +379,16 @@ func repoAssignment(ctx *Context, repo *models.Repository) {
378379
}
379380

380381
for index, btn := range repo.CustomRepoButtons {
381-
if !btn.IsLink() {
382-
repo.CustomRepoButtons[index].RenderedContent = string(markdown.Render([]byte(btn.Content), ctx.Repo.RepoLink,
383-
ctx.Repo.Repository.ComposeMetas()))
382+
if btn.IsLink() {
383+
continue
384+
}
385+
386+
if repo.CustomRepoButtons[index].RenderedContent, err = markdown.RenderString(&markup.RenderContext{
387+
URLPrefix: ctx.Repo.Repository.Link(),
388+
Metas: ctx.Repo.Repository.ComposeMetas(),
389+
}, btn.Content); err != nil {
390+
ctx.ServerError("LoadCustomRepoButton", err)
391+
return
384392
}
385393
}
386394
}

templates/repo/header.tmpl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
</div>
4343
{{if not .IsBeingCreated}}
4444
<div class="repo-buttons">
45+
{{ $index := 0}}
4546
{{range .CustomRepoButtons}}
4647
<div class="ui labeled button">
4748
{{if .IsLink}}
@@ -50,12 +51,20 @@
5051
</a>
5152
{{else}}
5253
<a class="ui basic label show-repo-button-content"
53-
data-title="{{.Title}}"
54-
data-content="{{.RenderedContent}}">
54+
data-index="{{$index}}">
5555
{{.Title}}
5656
</a>
57+
<div class="ui modal custom-repo-buttons" id="detail-modal-{{$index}}">
58+
{{svg "octicon-x" 16 "close inside"}}
59+
<div class="content">
60+
<div class="sub header">{{.Title}}</div>
61+
<div class="ui divider"></div>
62+
<div class="render-content markdown">{{.RenderedContent|Str2html}}</div>
63+
</div>
64+
</div>
5765
{{end}}
5866
</div>
67+
{{ $index = Add $index 1}}
5968
{{end}}
6069
{{if $.RepoTransfer}}
6170
<form method="post" action="{{$.RepoLink}}/action/accept_transfer?redirect_to={{$.RepoLink}}">
@@ -114,15 +123,6 @@
114123
</div><!-- end grid -->
115124
</div><!-- end container -->
116125

117-
<div class="ui modal custom-repo-buttons" id="detail-modal">
118-
{{svg "octicon-x" 16 "close inside"}}
119-
<div class="content">
120-
<div class="sub header"></div>
121-
<div class="ui divider"></div>
122-
<div class="render-content markdown"></div>
123-
</div>
124-
</div>
125-
126126
{{end}}
127127
<div class="ui tabs container">
128128
{{if not .Repository.IsBeingCreated}}

web_src/js/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,12 +1286,8 @@ async function initRepository() {
12861286
return;
12871287
}
12881288

1289-
const $detailModal = $('#detail-modal');
1290-
12911289
$('.show-repo-button-content').on('click', function () {
1292-
$detailModal.find('.content .render-content').html($(this).data('content'));
1293-
$detailModal.find('.sub.header').text($(this).data('title'));
1294-
$detailModal.modal('show');
1290+
$(`#detail-modal-${$(this).data('index')}`).modal('show');
12951291
return false;
12961292
});
12971293
})();

0 commit comments

Comments
 (0)