diff options
| author | Alexander Rolley <arolley35@gmail.com> | 2026-05-20 20:52:12 +0200 |
|---|---|---|
| committer | Alexander Rolley <arolley35@gmail.com> | 2026-05-20 20:52:12 +0200 |
| commit | 1cb3ae4156de430628abbc2ca19f51384857c6ba (patch) | |
| tree | 81c4ea45fae52eeeb64ce7af9dbda1ce0dab470f /src/frontend/Head.zig | |
| parent | d4b3a64ba6ad2862eb31e8c3081b7247c6b7b7b3 (diff) | |
| parent | 5e6b01b3b5357f43406be438074b94b3bcc90751 (diff) | |
Merge branch 'dev' of https://git.nathanreiner.xyz/memora into develop
Diffstat (limited to 'src/frontend/Head.zig')
| -rw-r--r-- | src/frontend/Head.zig | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/frontend/Head.zig b/src/frontend/Head.zig new file mode 100644 index 0000000..0eb090f --- /dev/null +++ b/src/frontend/Head.zig @@ -0,0 +1,58 @@ +const File = @import("File.zig"); +const Component = @import("Component.zig"); + +const z_component_code: File.Script = .minify("z-component.js"); + +pub const Meta = struct { + name: []const u8, + content: []const u8, + + pub fn to_html_string(comptime self: @This()) []const u8 { + return "<meta name=\"" ++ self.name ++ "\" content=\"" ++ self.content ++ "\">"; + } +}; + +title: []const u8, +meta: []const Meta, + +pub const empty: @This() = .{ + .title = "", + .meta = &.{}, +}; + +pub fn default(comptime title: []const u8) @This() { + return .{ + .title = title, + .meta = &.{ + .{ + .name = "viewport", + .content = "width=device-width, initial-scale=1.0", + }, + }, + }; +} + +pub fn to_html_string( + comptime self: @This(), + comptime components: []const Component, + comptime styles: []const File.Style, +) []const u8 { + var content: []const u8 = "<head>" ++ z_component_code.to_html_string(); + + content = content ++ "<title>" ++ self.title ++ "</title>"; + + inline for (components) |component| { + content = content ++ comptime component.to_html_string(); + } + + inline for (styles) |style| { + content = content ++ comptime style.to_html_string(); + } + + inline for (self.meta) |meta| { + content = content ++ comptime meta.to_html_string(); + } + + content = content ++ "</head>"; + return content; +} |