Update to latest Jetzig

This commit is contained in:
mitteneer 2024-09-14 11:04:27 -04:00
parent 0c59f29509
commit 348545949a
5 changed files with 11 additions and 95 deletions

View file

@ -7,24 +7,12 @@ pub fn build(b: *std.Build) !void {
const exe = b.addExecutable(.{
.name = "zuletzt",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
// Example dependency:
const iguanas_dep = b.dependency("iguanas", .{ .optimize = optimize, .target = target });
exe.root_module.addImport("iguanas", iguanas_dep.module("iguanas"));
const sqlite = b.dependency("sqlite", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("sqlite", sqlite.module("sqlite"));
// links the bundled sqlite3, so leave this out if you link the system one
exe.linkLibrary(sqlite.artifact("sqlite"));
// All dependencies **must** be added to imports above this line.
@ -41,7 +29,7 @@ pub fn build(b: *std.Build) !void {
run_step.dependOn(&run_cmd.step);
const lib_unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
@ -49,7 +37,7 @@ pub fn build(b: *std.Build) !void {
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const exe_unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});

View file

@ -16,12 +16,8 @@
// internet connectivity.
.dependencies = .{
.jetzig = .{
.url = "https://github.com/jetzig-framework/jetzig/archive/3c47435fd6ec7ea705a778dab1f533ae74e9bd6a.tar.gz",
.hash = "12209edf5716323a2475a4fe0eb02f5281d8b1d5e6708bc03a104892f7cf72a6cab5",
},
.sqlite = .{
.url = "https://github.com/vrischmann/zig-sqlite/archive/706ec59.tar.gz",
.hash = "1220faeb7e1b89ce805a41be1395931fbec69530aac45fce9cb17b817532e4cb6899",
.url = "https://github.com/jetzig-framework/jetzig/archive/dda433bb73000614482af10a277d47dc9d89600c.tar.gz",
.hash = "12202ce84b803a8b300c91d98afbc7c326298b55a23bf05cf603182e934b621008ec",
},
},
.paths = .{

View file

@ -1,52 +0,0 @@
const std = @import("std");
const jetzig = @import("jetzig");
const queries = @import("../lib/db.zig");
const sqlite = @import("sqlite");
pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View {
var root = try data.array();
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
var arena = std.heap.ArenaAllocator.init(allocator);
defer arena.deinit();
var db = try sqlite.Db.init(.{
.mode = sqlite.Db.Mode{ .File = "/home/swebb/Source/zuletzt/src/app/database/data.db" },
.open_flags = .{
.write = true,
.create = true,
},
.threading_mode = .MultiThread,
});
const params = try request.params();
const queryOrNull: ?[]const u8 = if (params.get("q")) |param| param.string.value else null;
if (queryOrNull) |query| {
// sql.search(query, db);
var artistSearch = try db.prepare(queries.total_search);
defer artistSearch.deinit();
const artistResults = try artistSearch.all(
struct {
artist: []u8,
url: []u8,
form: []u8,
},
arena.allocator(),
.{},
.{ .artist = query, .album = query, .track = query },
);
for (artistResults) |r| {
std.log.debug("artist: {s}, url: {s}", .{ r.artist, r.url });
try root.append(data.string(r.artist));
try root.append(data.string(r.url));
try root.append(data.string(r.form));
//std.log.debug("{s}", .{r});
}
} else {
return request.render(.bad_request);
}
//const query = params.get("q");
//try root.put("q",query);
//try root.put("q", data.string("Welcome"));
return request.render(.ok);
}

View file

@ -1,16 +0,0 @@
<table>
<tr>
<th>Artist</th>
<th>Album</th>
<th>Track</th>
</tr>
@zig {
for (zmpl.items(.array), 0..) |u,i| {
if(@mod(i,3)==0){
<tr>
<td id={{zmpl.items(.array)[i+2].string.value}}><a href={{zmpl.items(.array)[i+1].string.value}}>{{u}}</a></td>
</tr>
}
}
}
</table>

View file

@ -1,10 +1,10 @@
const std = @import("std");
pub const jetzig = @import("jetzig");
const jetzig = @import("jetzig");
pub const routes = @import("routes");
const zmd = @import("zmd");
const builtin = @import("builtin");
pub const static = @import("static");
pub const sqlite = @import("sqlite");
// Override default settings in `jetzig.config` here:
pub const jetzig_options = struct {
@ -72,13 +72,13 @@ pub const jetzig_options = struct {
"</ul>",
};
pub fn block(allocator: std.mem.Allocator, node: jetzig.zmd.Node) ![]const u8 {
pub fn block(allocator: std.mem.Allocator, node: zmd.Node) ![]const u8 {
return try std.fmt.allocPrint(allocator,
\\<pre class="w-1/2 font-mono mt-4 ms-3 bg-gray-900 p-2 text-white"><code class="language-{?s}">{s}</code></pre>
, .{ node.meta, node.content });
}
pub fn link(allocator: std.mem.Allocator, node: jetzig.zmd.Node) ![]const u8 {
pub fn link(allocator: std.mem.Allocator, node: zmd.Node) ![]const u8 {
return try std.fmt.allocPrint(allocator,
\\<a class="underline decoration-sky-500" href="{0s}" title={1s}>{1s}</a>
, .{ node.href.?, node.title.? });