From c6fb7b4962778c12f786d7d4de96787459a3b4dc Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 20 May 2026 17:29:28 +0200 Subject: frontend: add comptime bundler --- src/frontend/Document.zig | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/frontend/Document.zig (limited to 'src/frontend/Document.zig') 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 = ""; + content = content ++ comptime self.head.to_html_string(self.components, self.styles); + content = content ++ ""; + + inline for (self.contents) |c| { + content = content ++ comptime c.to_html_string(); + } + + content = content ++ ""; + + 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()}); +} -- cgit v1.2.3-70-g09d2