Commit 4106bdf

Anton Medvedev <anton@medv.io>
2025-11-30 16:43:38
Handle binary files in commit diff view
1 parent f00e66f
Changed files (3)
pkg/templates/commit.gohtml
@@ -183,6 +183,16 @@
         font-size: var(--code-font-size);
       }
 
+      .binary-file {
+        padding: 8px 16px;
+        font-style: italic;
+
+        border: 1px solid var(--c-border);
+        border-top: none;
+        border-bottom-left-radius: 6px;
+        border-bottom-right-radius: 6px;
+      }
+
       {{ .DiffCSS }}
     </style>
 {{ end }}
@@ -249,9 +259,13 @@
                             </button>
                         </header>
                     </div>
-                    <div class="file-diff">
-                        {{ .HTML }}
-                    </div>
+                    {{ if .IsBinary }}
+                        <div class="binary-file">Binary file</div>
+                    {{ else }}
+                        <div class="file-diff">
+                            {{ .HTML }}
+                        </div>
+                    {{ end }}
                 </section>
             {{ end }}
         </div>
pkg/templates/templates.go
@@ -196,6 +196,7 @@ type FileView struct {
 	IsNew    bool
 	IsDelete bool
 	IsRename bool
+	IsBinary bool
 	HTML     HTML // pre-rendered HTML for diff of this file
 }
 
commits.go
@@ -208,6 +208,7 @@ func generateCommitPage(commit git.Commit, params Params) error {
 			IsNew:    f.IsNew,
 			IsDelete: f.IsDelete,
 			IsRename: f.IsRename,
+			IsBinary: f.IsBinary,
 			HTML:     template.HTML(buf.String()),
 		})
 	}