diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-05-20 17:29:28 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-05-20 17:30:28 +0200 |
| commit | c6fb7b4962778c12f786d7d4de96787459a3b4dc (patch) | |
| tree | 4e21b9a1afd06d7edf5dd87dfffe822c073c6521 /src/frontend/Document.zig | |
| parent | 755c794883467609e425207f6a543d2e8c6d6b46 (diff) | |
frontend: add comptime bundler
Diffstat (limited to 'src/frontend/Document.zig')
| -rw-r--r-- | src/frontend/Document.zig | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/frontend/Document.zig b/src/frontend/Document.zig new file mode 100644 index 0000000..0ba46b1 --- /dev/null +++ b/src/frontend/Document.zig @@ -0,0 +1,46 @@ +const std = @import("std"); + +const Component = @import("Component.zig"); +const Head = @import("Head.zig"); +const File = @import("File.zig"); + +const Self = @This(); + +components: []const Component, +head: Head, +styles: []const File.Style, +contents: []const File.Html, + +pub const empty: Self = .{ + .head = .empty, + .components = &.{}, + .styles = &.{}, + .contents = &.{}, +}; + +pub fn to_string(comptime self: Self) []const u8 { + comptime var content: []const u8 = "<!DOCTYPE html><html>"; + content = content ++ comptime self.head.to_html_string(self.components, self.styles); + content = content ++ "<body>"; + + inline for (self.contents) |c| { + content = content ++ comptime c.to_html_string(); + } + + content = content ++ "</body></html>"; + + return content; +} + +test { + const document: Self = comptime .{ + .head = .default("test"), + .components = &.{ + .path("./web/hello-world"), + }, + .styles = &.{}, + .contents = &.{.minify("./web/index.html")}, + }; + + std.debug.print("{s}", .{document.to_string()}); +} |