diff options
Diffstat (limited to 'src/gen.zig')
| -rw-r--r-- | src/gen.zig | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/gen.zig b/src/gen.zig index ec26295..dbfb1ba 100644 --- a/src/gen.zig +++ b/src/gen.zig @@ -96,23 +96,24 @@ fn genSite(ctx: *Context) !void { try std.fs.cwd().makePath(dstdir); } - const f = try std.fs.cwd().createFile(dstpath, .{}); + const f = try fs.FileSwapper.createAt(ctx.allocator(), dstpath); + defer f.close(); const page_name = try std.mem.replaceOwned(u8, ctx.allocator(), dstname, "_", " "); defer ctx.allocator().free(page_name); - try build(ctx.allocator(), f, page_name, srcpath); + try build(ctx.allocator(), f.writer().any(), page_name, srcpath); ctx.generated += 1; } } // build a single html file -fn build(allocator: std.mem.Allocator, f: std.fs.File, page_name: []const u8, srcpath: []const u8) !void { +fn build(allocator: std.mem.Allocator, w: std.io.AnyWriter, page_name: []const u8, srcpath: []const u8) !void { const mtime = try fs.get_mtime(allocator, srcpath); defer allocator.free(mtime); // HEAD - try f.writer().print( + try w.print( \\<!-- Generated file, do not edit, you may edit and discard {[SOURCE]s} :) --> \\<!DOCTYPE html> \\<html lang="en"> @@ -138,30 +139,30 @@ fn build(allocator: std.mem.Allocator, f: std.fs.File, page_name: []const u8, sr }); // NAV - try f.writer().writeAll( + try w.writeAll( \\<nav> \\ ); - portal(allocator, f.writer().any(), "meta.nav", false) catch {}; // ignore error - try f.writer().writeAll( + portal(allocator, w, "meta.nav", false) catch {}; // ignore error + try w.writeAll( \\</nav> \\</header> \\ ); // MAIN - try f.writer().print( + try w.print( \\<main> \\ , .{}); - try inject(allocator, f.writer().any(), srcpath); - try f.writer().writeAll( + try inject(allocator, w, srcpath); + try w.writeAll( \\</main> \\ ); // FOOTER - try f.writer().print( + try w.print( \\<footer> \\Edited on {[MTIME]s} <a href="{[SOURCE_URL]s}/{[PATH]s}" target="_blank">[src]</a> \\<a href="mailto:{[PUBLIC_INBOX]s}">[comments]</a> @@ -183,12 +184,12 @@ fn build(allocator: std.mem.Allocator, f: std.fs.File, page_name: []const u8, sr .SOURCE_URL = Context.params.SOURCE_URL, }); - try f.writer().writeAll( + try w.writeAll( \\<a href="#top">[⏶]</a> \\ ); - try f.writer().writeAll( + try w.writeAll( \\</body> \\</html> \\ @@ -221,7 +222,7 @@ fn meta(ctx: *Context, p: []const u8) !void { }; defer ctx.allocator().free(link); - const f = try std.fs.cwd().createFile(dstpath, .{}); + const f = try fs.FileSwapper.createAt(ctx.allocator(), dstpath); defer f.close(); try f.writer().print( |