loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ui: fix go to citation button url (#4597)

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4597
Reviewed-by: Ghost <twenty-panda@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Bram Hagens <bram@bramh.me>
Co-committed-by: Bram Hagens <bram@bramh.me>

authored by

Bram Hagens
Bram Hagens
and committed by
0ko
7f62acb4 b670f111

+85 -3
+2 -1
routers/web/repo/view.go
··· 781 781 if content, err := entry.Blob().GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil { 782 782 log.Error("checkCitationFile: GetBlobContent: %v", err) 783 783 } else { 784 - ctx.Data["CitiationExist"] = true 784 + ctx.Data["CitationExist"] = true 785 + ctx.Data["CitationFile"] = entry.Name() 785 786 ctx.PageData["citationFileContent"] = content 786 787 break 787 788 }
+1 -1
templates/repo/cite/cite_modal.tmpl
··· 6 6 <div class="ui stackable secondary menu"> 7 7 <div class="ui action input" id="citation-panel"> 8 8 {{template "repo/cite/cite_buttons" .}} 9 - <a id="goto-citation-btn" class="ui basic jump icon button" href="{{$.RepoLink}}/src/{{$.BranchName}}/CITATION.cff" data-tooltip-content="{{ctx.Locale.Tr "repo.find_file.go_to_file"}}"> 9 + <a id="goto-citation-btn" class="ui basic jump icon button" href="{{$.RepoLink}}/src/{{$.BranchName}}/{{$.CitationFile}}" data-tooltip-content="{{ctx.Locale.Tr "repo.find_file.go_to_file"}}"> 10 10 {{svg "octicon-file-moved"}} 11 11 </a> 12 12 </div>
+1 -1
templates/repo/home.tmpl
··· 133 133 <a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.download_tar"}}</a> 134 134 <a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.bundle" rel="nofollow">{{svg "octicon-package" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.download_bundle"}}</a> 135 135 {{end}} 136 - {{if .CitiationExist}} 136 + {{if .CitationExist}} 137 137 <a class="item" id="cite-repo-button">{{svg "octicon-cross-reference" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.cite_this_repo"}}</a> 138 138 {{end}} 139 139 {{range .OpenWithEditorApps}}
+81
tests/integration/repo_citation_test.go
··· 1 + // Copyright 2024 The Forgejo Authors. All rights reserved. 2 + // SPDX-License-Identifier: GPL-3.0-or-later 3 + 4 + package integration 5 + 6 + import ( 7 + "net/http" 8 + "net/url" 9 + "strings" 10 + "testing" 11 + 12 + repo_model "code.gitea.io/gitea/models/repo" 13 + unit_model "code.gitea.io/gitea/models/unit" 14 + "code.gitea.io/gitea/models/unittest" 15 + user_model "code.gitea.io/gitea/models/user" 16 + files_service "code.gitea.io/gitea/services/repository/files" 17 + "code.gitea.io/gitea/tests" 18 + 19 + "github.com/stretchr/testify/assert" 20 + ) 21 + 22 + func TestCitation(t *testing.T) { 23 + onGiteaRun(t, func(t *testing.T, u *url.URL) { 24 + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) 25 + 26 + session := loginUser(t, user.LoginName) 27 + 28 + t.Run("No citation", func(t *testing.T) { 29 + defer tests.PrintCurrentTest(t)() 30 + 31 + repo, _, f := CreateDeclarativeRepo(t, user, "citation-no-citation", []unit_model.Type{unit_model.TypeCode}, nil, nil) 32 + defer f() 33 + 34 + testCitationButtonExists(t, session, repo, "", false) 35 + }) 36 + 37 + t.Run("cff citation", func(t *testing.T) { 38 + defer tests.PrintCurrentTest(t)() 39 + 40 + repo, f := createRepoWithEmptyFile(t, user, "citation-cff", "CITATION.cff") 41 + defer f() 42 + 43 + testCitationButtonExists(t, session, repo, "CITATION.cff", true) 44 + }) 45 + 46 + t.Run("bib citation", func(t *testing.T) { 47 + defer tests.PrintCurrentTest(t)() 48 + 49 + repo, f := createRepoWithEmptyFile(t, user, "citation-bib", "CITATION.bib") 50 + defer f() 51 + 52 + testCitationButtonExists(t, session, repo, "CITATION.bib", true) 53 + }) 54 + }) 55 + } 56 + 57 + func testCitationButtonExists(t *testing.T, session *TestSession, repo *repo_model.Repository, file string, exists bool) { 58 + req := NewRequest(t, "GET", repo.HTMLURL()) 59 + resp := session.MakeRequest(t, req, http.StatusOK) 60 + doc := NewHTMLParser(t, resp.Body) 61 + 62 + doc.AssertElement(t, "#cite-repo-button", exists) 63 + 64 + if exists { 65 + href, exists := doc.doc.Find("#goto-citation-btn").Attr("href") 66 + assert.True(t, exists) 67 + 68 + assert.True(t, strings.HasSuffix(href, file)) 69 + } 70 + } 71 + 72 + func createRepoWithEmptyFile(t *testing.T, user *user_model.User, repoName, fileName string) (*repo_model.Repository, func()) { 73 + repo, _, f := CreateDeclarativeRepo(t, user, repoName, []unit_model.Type{unit_model.TypeCode}, nil, []*files_service.ChangeRepoFile{ 74 + { 75 + Operation: "create", 76 + TreePath: fileName, 77 + }, 78 + }) 79 + 80 + return repo, f 81 + }