╭ changed ──╮ │src/web.zig│ ╰───────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭─────────────────────────────────────╮ │ 4 const ui = @import("./ui.zig"); │ │ 5 const pg = @import("./page.zig");│ │ 6 │ │ 7 -const Asset = struct { │ │ 7 +const Embed = struct { │ │ 8 path: []const u8, │ │ 9 content_type: []const u8, │ │10 body: []const u8, │ ╰─────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │11 }; │ │12 │ │13 -const assets = [_]Asset{ │ │14 - .{ .path = "index.html", .content_type = "text/html; charset=utf-8", .body = @embedFile("assets/index.html") }, │ │15 - .{ .path = "script.js", .content_type = "text/javascript; charset=utf-8", .body = @embedFile("assets/script.js") },│ │16 - .{ .path = "term.ttf", .content_type = "font/ttf", .body = @embedFile("assets/term.ttf") }, │ │17 - .{ .path = "haxy.wasm", .content_type = "application/wasm", .body = @embedFile("assets/haxy.wasm") }, │ │13 +const embeds = [_]Embed{ │ │14 + .{ .path = "index.html", .content_type = "text/html; charset=utf-8", .body = @embedFile("embed/index.html") }, │ │15 + .{ .path = "script.js", .content_type = "text/javascript; charset=utf-8", .body = @embedFile("embed/script.js") }, │ │16 + .{ .path = "term.ttf", .content_type = "font/ttf", .body = @embedFile("embed/term.ttf") }, │ │17 + .{ .path = "haxy.wasm", .content_type = "application/wasm", .body = @embedFile("embed/haxy.wasm") }, │ │18 }; │ │19 │ │20 pub fn run( │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │78 } │ │79 │ │80 fn renderIndexHtml(io: std.Io, allocator: std.mem.Allocator, admin_repo_path: []const u8) ![]const u8 {│ │81 - const template = (findAsset("/index.html") orelse return error.MissingIndexAsset).body; │ │81 + const template = (findEmbed("/index.html") orelse return error.MissingIndexAsset).body; │ │82 │ │83 // open the admin repo to read live user/repo data; if it doesn't exist │ │84 // yet (e.g. a fresh `haxy serve` with no admin repo) fall back to empty. │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────╮ │187 return; │ │188 } │ │189 │ │190 - const asset = findAsset(path) orelse { │ │190 + const embed = findEmbed(path) orelse { │ │191 if (http_server.reader.state == .received_head) {│ │192 http_server.reader.state = .ready; │ │193 } │ ╰──────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │199 http_server.reader.state = .ready; │ │200 } │ │201 │ │202 - if (std.mem.eql(u8, asset.path, "index.html")) { │ │202 + if (std.mem.eql(u8, embed.path, "index.html")) { │ │203 const index_html = try renderIndexHtml(io, allocator, admin_repo_path); │ │204 defer allocator.free(index_html); │ │205 - try writeStaticResponse(http_server, 200, "OK", asset.content_type, index_html, request.head.method == .HEAD);│ │205 + try writeStaticResponse(http_server, 200, "OK", embed.content_type, index_html, request.head.method == .HEAD);│ │206 } else { │ │207 - try writeStaticResponse(http_server, 200, "OK", asset.content_type, asset.body, request.head.method == .HEAD);│ │207 + try writeStaticResponse(http_server, 200, "OK", embed.content_type, embed.body, request.head.method == .HEAD);│ │208 } │ │209 } │ │210 │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────╮ │211 -fn findAsset(request_path: []const u8) ?Asset { │ │211 +fn findEmbed(request_path: []const u8) ?Embed { │ │212 const path = if (std.mem.eql(u8, request_path, "/")) │ │213 "index.html" │ │214 else if (request_path.len > 1 and request_path[0] == '/')│ ╰──────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────╮ │216 else │ │217 return null; │ │218 │ │219 - for (assets) |asset| { │ │220 - if (std.mem.eql(u8, path, asset.path)) return asset;│ │219 + for (embeds) |embed| { │ │220 + if (std.mem.eql(u8, path, embed.path)) return embed;│ │221 } │ │222 return null; │ │223 } │ ╰─────────────────────────────────────────────────────────────────╯