srctree

Gregory Mullen parent 215542d7 1271da08
float videos to the top

inlinesplit
src/main.zig added: 16, removed: 3, total 13
@@ -26,16 +26,29 @@ pub fn main() !void {
std.debug.print("directory iter error {}\n", .{err});
std.posix.exit(2);
}
std.sort.pdq([]u8, list.items, {}, cmpStr);
std.sort.pdq([]u8, list.items, {}, cmpStrVideo);
 
for (list.items) |str| {
const video = if (std.mem.endsWith(u8, str, ".mp4")) " class=\"vid\"" else "";
const video = if (isVideo(str)) " class=\"vid\"" else "";
try bout.print(" <li><a{s} href=\"{s}\">{s}</a></li>\n", .{ video, str, str });
}
 
try bout.writeAll(index_tail);
}
 
fn isVideo(str: []const u8) bool {
return std.mem.endsWith(u8, str, ".mp4");
}
 
fn cmpStrVideo(_: void, lhs: []const u8, rhs: []const u8) bool {
return if (isVideo(lhs) and !isVideo(rhs))
true
else if (isVideo(rhs))
false
else
cmpStr({}, lhs, rhs);
}
 
fn cmpStr(_: void, lhs: []const u8, rhs: []const u8) bool {
return std.mem.order(u8, lhs, rhs) == .lt;
}