aboutsummaryrefslogtreecommitdiff
path: root/comments
diff options
context:
space:
mode:
authorMartin Ashby <martin@ashbysoft.com>2024-05-26 22:10:03 +0100
committerMartin Ashby <martin@ashbysoft.com>2024-05-26 22:10:03 +0100
commit12e32e5559be7427483f8520a58dce34046f020c (patch)
tree9d2ae0a9cad76bb071ff8b05150a17cd7050b2e1 /comments
parent8666c8822d396f0c42c73f7c33e445f6608c4e51 (diff)
downloadmfashby.net-12e32e5559be7427483f8520a58dce34046f020c.tar.gz
mfashby.net-12e32e5559be7427483f8520a58dce34046f020c.tar.bz2
mfashby.net-12e32e5559be7427483f8520a58dce34046f020c.tar.xz
mfashby.net-12e32e5559be7427483f8520a58dce34046f020c.zip
Add post on zigvm
Fixup for zig master
Diffstat (limited to 'comments')
-rw-r--r--comments/build.zig6
-rw-r--r--comments/build.zig.zon15
-rw-r--r--comments/src/main.zig16
3 files changed, 20 insertions, 17 deletions
diff --git a/comments/build.zig b/comments/build.zig
index 3293e4c..c978095 100644
--- a/comments/build.zig
+++ b/comments/build.zig
@@ -21,7 +21,7 @@ pub fn build(b: *std.Build) void {
.name = "comments",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
- .root_source_file = .{ .path = "src/main.zig" },
+ .root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
@@ -40,8 +40,6 @@ pub fn build(b: *std.Build) void {
const smtp = b.dependency("smtp", opts);
exe.root_module.addImport("smtp", smtp.module("smtp"));
-
-
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
// step when running `zig build`).
@@ -73,7 +71,7 @@ pub fn build(b: *std.Build) void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
- .root_source_file = .{ .path = "src/main.zig" },
+ .root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
diff --git a/comments/build.zig.zon b/comments/build.zig.zon
index edc18d7..54d1e35 100644
--- a/comments/build.zig.zon
+++ b/comments/build.zig.zon
@@ -3,16 +3,21 @@
.version = "0.0.1",
.dependencies = .{ .pq = .{
.url = "https://code.mfashby.net/pq-zig/snapshot/pq-zig-main.tar.xz",
- .hash = "12201517d080461a76f4b26ff78a810d80b1d58e2d3f382da30de1055ebdcea3feaf",
+ .hash = "1220895045b9a9333a385a0329d9c11604036f28a2150d10c3ed711d4bab21d4a218",
+ //.path = "../../pq-zig"
}, .smtp = .{
.url = "https://code.mfashby.net/smtp-zig/snapshot/smtp-zig-main.tar.xz",
- .hash = "1220b85b46b525e725f8fdb6e23189aa365976acf388e3b2a5a4da364851c3ec4252",
+ .hash = "1220b42673da5f313d4ce816e41de2f17e4b7ebbae1669904b9c17a385d9997e72ed",
+ //.path = "../../smtp-zig"
}, .mustache = .{
- .url = "https://github.com/batiati/mustache-zig/archive/refs/heads/master.tar.gz",
- .hash = "12205538be57d7c0b92806e87c500c50bfcecb9b083adea8b2fdbec99f46598c922d",
+ // TODO revert to balati when https://github.com/batiati/mustache-zig/pull/21 is merged
+ .url = "https://github.com/MFAshby/mustache-zig/archive/refs/heads/master.tar.gz",
+ .hash = "1220910fce41f46c0f652c3bfe19ca83940b1b26e046d8bdb901e3a9fd0f2b480b1b",
+ //.path = "../../mustache-zig"
}, .zigwebserver = .{
.url = "https://code.mfashby.net/zigwebserver/snapshot/zigwebserver-main.tar.xz",
- .hash = "122084fc67129e92544a86f10ca9a64f2667682aa7dfd6a12a80c374015a33555df6",
+ .hash = "122065d7f71c3788d59e952a283f714e5df90d50b170a3dc5066dd9cd1d104319831",
+ //.path = "../../zigwebserver"
} },
.paths = .{""},
}
diff --git a/comments/src/main.zig b/comments/src/main.zig
index a5008b8..165dff0 100644
--- a/comments/src/main.zig
+++ b/comments/src/main.zig
@@ -84,7 +84,7 @@ const Response = struct {
fn do(self: @This()) !void {
const wtr = std.io.getStdOut().writer();
if (self.status.phrase()) |phrase| {
- try std.fmt.format(wtr, "status: {} {s}\r\n", .{@intFromEnum(self.status), phrase});
+ try std.fmt.format(wtr, "status: {} {s}\r\n", .{ @intFromEnum(self.status), phrase });
} else {
try std.fmt.format(wtr, "status: {}\r\n", .{@intFromEnum(self.status)});
}
@@ -196,7 +196,7 @@ fn get_comment(res: *Response, ctx: Ctx, _: Params) Err!void {
}
const rr = @embedFile("templates/comments.html");
- const tt = comptime mustache.parseComptime(rr, .{}, .{});
+ const tt = mustache.parseText(res.allocator, rr, .{}, .{ .copy_strings = false }) catch unreachable;
res.transfer_encoding = .chunked;
try res.headers.append("content-type", "text/html");
try res.do();
@@ -204,7 +204,7 @@ fn get_comment(res: *Response, ctx: Ctx, _: Params) Err!void {
const data = struct {
comments: []const Comment,
};
- try mustache.render(tt, data{
+ try mustache.render(tt.success, data{
.comments = comments.items,
}, res.writer());
try res.finish();
@@ -243,7 +243,7 @@ fn post_comment(res: *Response, ctx: Ctx, _: Params) Err!void {
}
const ans = try stmt.read_column(0, []const u8);
if (!std.mem.eql(u8, ans, form_val.capcha_answer)) {
- std.log.err("bad capcha answer {s} expected {s}", .{form_val.capcha_answer, ans});
+ std.log.err("bad capcha answer {s} expected {s}", .{ form_val.capcha_answer, ans });
try constresponse(res, @embedFile("templates/capchainvalid.html"), std.http.Status.unauthorized);
return;
}
@@ -261,9 +261,9 @@ fn post_comment(res: *Response, ctx: Ctx, _: Params) Err!void {
// Send me an email
const rr = @embedFile("templates/notification.txt");
- const tt = comptime mustache.parseComptime(rr, .{}, .{});
+ const tt = mustache.parseText(res.allocator, rr, .{}, .{ .copy_strings = false }) catch unreachable;
const Data = struct { url: []const u8, author: []const u8, comment: []const u8 };
- const notification = try mustache.allocRender(res.allocator, tt, Data{
+ const notification = try mustache.allocRender(res.allocator, tt.success, Data{
.url = form_val.url,
.author = form_val.author,
.comment = form_val.comment,
@@ -306,7 +306,7 @@ fn get_form(res: *Response, ctx: Ctx, _: Params) Err!void {
const capcha = try stmt.read_struct(Capcha);
const rr = @embedFile("templates/form.html");
- const tt = comptime mustache.parseComptime(rr, .{}, .{});
+ const tt = mustache.parseText(res.allocator, rr, .{}, .{ .copy_strings = false }) catch unreachable;
res.transfer_encoding = .chunked;
try res.headers.append("content-type", "text/html");
@@ -317,7 +317,7 @@ fn get_form(res: *Response, ctx: Ctx, _: Params) Err!void {
capcha_question: []const u8,
url: []const u8,
};
- try mustache.render(tt, data{
+ try mustache.render(tt.success, data{
.capcha_id = capcha.id,
.capcha_question = capcha.question,
.url = url,