From 2a1554d063749b490772860e409a55d7decd4bed Mon Sep 17 00:00:00 2001 From: Thomas Miceli <27960254+thomiceli@users.noreply.github.com> Date: Tue, 3 Feb 2026 01:59:24 +0800 Subject: [PATCH] Fix renderable text files with different mimetypes (#612) --- internal/git/mime.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/internal/git/mime.go b/internal/git/mime.go index fb354e0..9f77334 100644 --- a/internal/git/mime.go +++ b/internal/git/mime.go @@ -2,43 +2,45 @@ package git import ( "fmt" + "net/http" "strings" "github.com/gabriel-vasile/mimetype" ) type MimeType struct { - ContentType string - extension string + ContentType string + extension string + golangContentType string // json, m3u, etc. still renderable as text } func (mt MimeType) IsText() bool { - return strings.Contains(mt.ContentType, "text/") + return strings.HasPrefix(mt.ContentType, "text/") || strings.HasPrefix(mt.golangContentType, "text/") } func (mt MimeType) IsCSV() bool { - return strings.Contains(mt.ContentType, "text/csv") && + return strings.HasPrefix(mt.ContentType, "text/csv") && (strings.HasSuffix(mt.extension, ".csv")) } func (mt MimeType) IsImage() bool { - return strings.Contains(mt.ContentType, "image/") + return strings.HasPrefix(mt.ContentType, "image/") } func (mt MimeType) IsSVG() bool { - return strings.Contains(mt.ContentType, "image/svg+xml") + return strings.HasPrefix(mt.ContentType, "image/svg+xml") } func (mt MimeType) IsPDF() bool { - return strings.Contains(mt.ContentType, "application/pdf") + return strings.HasPrefix(mt.ContentType, "application/pdf") } func (mt MimeType) IsAudio() bool { - return strings.Contains(mt.ContentType, "audio/") + return strings.HasPrefix(mt.ContentType, "audio/") } func (mt MimeType) IsVideo() bool { - return strings.Contains(mt.ContentType, "video/") + return strings.HasPrefix(mt.ContentType, "video/") } func (mt MimeType) CanBeHighlighted() bool { @@ -87,5 +89,5 @@ func (mt MimeType) RenderType() string { } func DetectMimeType(data []byte, extension string) MimeType { - return MimeType{mimetype.Detect(data).String(), extension} + return MimeType{mimetype.Detect(data).String(), extension, http.DetectContentType(data)} }