download patch
commit 937c4ea4d702ebe6e6588f159a4d5557dca16ce8
Author: tri <tri@thac.loan>
Date: Fri Oct 3 18:26:13 2025 +0700
show video blobs too
diff --git a/src/assets/style.css b/src/assets/style.css
index de304ba..9d50d69 100644
--- a/src/assets/style.css
+++ b/src/assets/style.css
table {
font-variant-numeric: tabular-nums;
}
-img {
+img,
+video {
max-width: 100%;
max-height: 100%;
}
diff --git a/src/main.zig b/src/main.zig
index 269bc9a..1176acb 100644
--- a/src/main.zig
+++ b/src/main.zig
pub fn writeFilePage(
args.in_repo_dir,
src_file.hash,
);
+ const blob_type = utils.blobType(src_file.path);
- if (utils.isImg(src_file.path) and file_content.len <= 1024 * 1024 * 16) {
+ if (file_content.len <= 1024 * 1024 * 16 and
+ (blob_type == .image or blob_type == .video))
+ {
const src_file_name =
if (mem.lastIndexOfScalar(u8, src_file.path, '/')) |slash_idx|
src_file.path[slash_idx + 1 ..]
pub fn writeFilePage(
// write <img> markup in blob page
const escaped_file_name = try html.escapeAlloc(arena, src_file_name);
- try writer.print(
- \\<img src="{0s}.{1s}" alt="{1s}">
- \\
- , .{
- src_file.hash,
- escaped_file_name,
- });
+
+ switch (blob_type) {
+ .image => {
+ try writer.print(
+ \\<img src="{0s}.{1s}" alt="{1s}">
+ \\
+ , .{
+ src_file.hash,
+ escaped_file_name,
+ });
+ },
+ .video => {
+ try writer.print(
+ \\<video src="{0s}.{1s}" controls></video>
+ \\
+ , .{
+ src_file.hash,
+ escaped_file_name,
+ });
+ },
+ else => return error.UnexpectedBlobType,
+ }
} else if (git.isBinary(file_content)) {
try writer.writeAll(
\\<span style="opacity: 0.5">(binary data)</span>
diff --git a/src/utils.zig b/src/utils.zig
index 9463deb..31e4245 100644
--- a/src/utils.zig
+++ b/src/utils.zig
test "humanReadableSize" {
try t.expectEqualStrings("1024 TiB", try humanReadableSize(arena, 1024 * 1024 * 1024 * 1024 * 1024));
}
-pub fn isImg(file_path: []const u8) bool {
- const img_extensions: []const []const u8 = &.{
+pub const BlobType = enum { image, video, other };
+
+pub fn blobType(path: []const u8) BlobType {
+ const img_exts: []const []const u8 = &.{
".apng",
".avif",
".gif",
pub fn isImg(file_path: []const u8) bool {
".webp",
".bmp",
};
- for (img_extensions) |ext| {
- if (std.ascii.endsWithIgnoreCase(file_path, ext)) {
- return true;
- }
+ for (img_exts) |ext| {
+ if (std.ascii.endsWithIgnoreCase(path, ext)) return .image;
+ }
+
+ const video_exts: []const []const u8 = &.{
+ ".mp4",
+ ".webm",
+ };
+ for (video_exts) |ext| {
+ if (std.ascii.endsWithIgnoreCase(path, ext)) return .video;
}
- return false;
+
+ return .other;
}