fix: Preview/Source buttons only for .html/.htm, not other file types

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-20 15:04:45 +01:00
parent 33703222f8
commit 20f521cf16
2 changed files with 4 additions and 6 deletions
-2
View File
@@ -173,7 +173,6 @@ func handleFileViewRenderHTML(ctx *context.Context, fInfo *fileInfo) bool {
return false
}
ctx.Data["IsHTMLFile"] = true
ctx.Data["HasSourceRenderedToggle"] = true
return true
}
@@ -193,7 +192,6 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) {
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
if isHTMLTreePath(ctx.Repo.TreePath) {
ctx.Data["IsHTMLFile"] = true
ctx.Data["HasSourceRenderedToggle"] = true
}
if ctx.Repo.TreePath == ".editorconfig" {
+4 -4
View File
@@ -41,15 +41,15 @@
<a href="?display=source" class="ui mini basic button {{if .IsDisplayingSource}}active{{end}}">{{ctx.Locale.Tr "repo.file_view_source"}}</a>
</div>
{{end}}
{{/* this componment is also controlled by frontend plugin renders */}}
<div class="ui compact icon buttons file-view-toggle-buttons {{Iif .HasSourceRenderedToggle "" "tw-hidden"}}">
{{/* Gitea icon toggles for markup etc.; HTML uses Preview/Source buttons above only */}}
{{if and .HasSourceRenderedToggle (not .IsHTMLFile)}}
<div class="ui compact icon buttons file-view-toggle-buttons">
{{if .IsRepresentableAsText}}
<a href="?display=source" class="ui mini basic button file-view-toggle-source {{if .IsDisplayingSource}}active{{end}}" data-tooltip-content="{{ctx.Locale.Tr "repo.file_view_source"}}">{{svg "octicon-code" 15}}</a>
{{end}}
{{if .HasSourceRenderedToggle}}
<a href="?display=rendered" class="ui mini basic button file-view-toggle-rendered {{if not .IsDisplayingSource}}active{{end}}" data-tooltip-content="{{ctx.Locale.Tr "repo.file_view_rendered"}}">{{svg "octicon-file" 15}}</a>
{{end}}
</div>
{{end}}
{{if not .ReadmeInList}}
<div class="ui buttons tw-mr-1">
<a class="ui mini basic button" href="{{$.RawFileLink}}">{{ctx.Locale.Tr "repo.file_raw"}}</a>