feat(content): routing to provided .blog paths
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m7s

This is a starting point to dynamically loading `markdown` files as blog
entries. With this change the *doc/about.md* and *doc/blog.md* files
are no longer builded into the executable and instead read from the
filesystem during runtime (along with the new test file *doc/test.md*).
This commit is contained in:
2025-11-01 22:36:48 +01:00
parent e4c3f69821
commit a877ac3e7d
7 changed files with 138 additions and 59 deletions

View File

@@ -7,8 +7,11 @@ pub fn main() !void {
const allocator = gpa.allocator();
var app: App = .init(.{
.document = .init(@embedFile("blog")),
.page = .about,
.document = .init(try std.fs.cwd().readFileAlloc("./doc/about.md", allocator, .unlimited)),
});
defer app.model.deinit(allocator);
var renderer = zterm.Renderer.Buffered.init(allocator);
defer renderer.deinit();
@@ -36,7 +39,7 @@ pub fn main() !void {
}, .{});
// title
{
var title: Title = .init();
var title: Title = .{};
try header.append(try .init(allocator, .{}, title.element()));
}
// about navigation button
@@ -76,7 +79,7 @@ pub fn main() !void {
}
// footer
{
var info_banner: InfoBanner = .init();
var info_banner: InfoBanner = .{};
const footer: App.Container = try .init(allocator, .{
.size = .{
.dim = .{ .y = 1 },
@@ -98,6 +101,8 @@ pub fn main() !void {
switch (event) {
.key => |key| {
if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) app.quit();
// test if the event handling is working correctly
if (key.eql(.{ .cp = zterm.input.Space })) app.postEvent(.{ .blog = allocator.dupe(u8, "./doc/test.md") catch unreachable });
},
.err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }),
else => {},
@@ -134,10 +139,7 @@ const zlog = @import("zlog");
const zterm = @import("zterm");
const App = zterm.App(
Model,
union(enum) {
about,
blog,
},
Model.Pages,
);
const contents = @import("content.zig");