aboutsummaryrefslogtreecommitdiff
path: root/converter
diff options
context:
space:
mode:
authorMartin Ashby <martin@ashbysoft.com>2024-07-14 21:10:09 +0100
committerMartin Ashby <martin@ashbysoft.com>2024-07-14 21:10:09 +0100
commit54b7021b063a81bc1655a6b4519b9a41cd6ed30b (patch)
tree760762f8df8d9fb5dfb4022ad42ecb9127440623 /converter
parent7d296d575b49f5de94f7354094344573b8701199 (diff)
downloadmfashby.net-54b7021b063a81bc1655a6b4519b9a41cd6ed30b.tar.gz
mfashby.net-54b7021b063a81bc1655a6b4519b9a41cd6ed30b.tar.bz2
mfashby.net-54b7021b063a81bc1655a6b4519b9a41cd6ed30b.tar.xz
mfashby.net-54b7021b063a81bc1655a6b4519b9a41cd6ed30b.zip
Bump mustache dep
Update .gitignore for new zig-cache location Remove old converter sources. Checked everything compiles with zig 0.13
Diffstat (limited to 'converter')
-rw-r--r--converter/build.zig36
-rw-r--r--converter/build.zig.zon13
-rw-r--r--converter/src/main.zig70
-rw-r--r--converter/src/root.zig10
4 files changed, 0 insertions, 129 deletions
diff --git a/converter/build.zig b/converter/build.zig
deleted file mode 100644
index f1563cf..0000000
--- a/converter/build.zig
+++ /dev/null
@@ -1,36 +0,0 @@
-const std = @import("std");
-
-pub fn build(b: *std.Build) void {
- const target = b.standardTargetOptions(.{});
- const optimize = b.standardOptimizeOption(.{});
-
- const exe = b.addExecutable(.{
- .name = "converter",
- .root_source_file = .{ .path = "src/main.zig" },
- .target = target,
- .optimize = optimize,
- });
- const ziggy = b.dependency("ziggy", .{});
- exe.root_module.addImport("ziggy", ziggy.module("ziggy"));
-
- b.installArtifact(exe);
-
- const run_cmd = b.addRunArtifact(exe);
- run_cmd.step.dependOn(b.getInstallStep());
-
- if (b.args) |args| {
- run_cmd.addArgs(args);
- }
- const run_step = b.step("run", "Run the app");
- run_step.dependOn(&run_cmd.step);
-
- const exe_unit_tests = b.addTest(.{
- .root_source_file = .{ .path = "src/main.zig" },
- .target = target,
- .optimize = optimize,
- });
-
- const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
- const test_step = b.step("test", "Run unit tests");
- test_step.dependOn(&run_exe_unit_tests.step);
-}
diff --git a/converter/build.zig.zon b/converter/build.zig.zon
deleted file mode 100644
index 1d3de63..0000000
--- a/converter/build.zig.zon
+++ /dev/null
@@ -1,13 +0,0 @@
-.{
- .name = "converter",
- .version = "0.0.0",
- .dependencies = .{
- .ziggy = .{
- .url = "https://github.com/kristoff-it/ziggy/archive/refs/heads/main.tar.gz",
- .hash = "1220037474a924385b0d2ccb0e5c416c595f43f93a3450d55f8b6d5ad6f3ba091ca5",
- }
- },
- .paths = .{
- "",
- },
-}
diff --git a/converter/src/main.zig b/converter/src/main.zig
deleted file mode 100644
index edaf51f..0000000
--- a/converter/src/main.zig
+++ /dev/null
@@ -1,70 +0,0 @@
-const std = @import("std");
-const ziggy = @import("ziggy");
-
-const Page = struct {
- title: ?[]const u8 = null,
- author: ?[]const u8 = null,
- date: ?[]const u8 = null,
- layout: ?[]const u8 = null,
- // draft: ?bool = null,
- // params: ?struct {
- // comments: bool,
- // } = null,
-};
-
-pub fn main() !void {
- const a = std.heap.page_allocator;
- var args = std.process.args();
- if (!args.skip()) @panic("errors kipping program name?");
- const contentdirname = args.next() orelse return error.NoDir;
- const contentdir = try std.fs.cwd().openDir(contentdirname, .{ .iterate = true });
- var walker = try contentdir.walk(a);
- while (try walker.next()) |we| {
- if (std.mem.endsWith(u8, we.basename, ".md")) {
- std.log.info("converting file {s}", .{we.basename});
- const file = try we.dir.readFileAlloc(a, we.basename, 1_000_000);
- const start = (std.mem.indexOf(u8, file, "---\n") orelse return error.NoFrontmatter) + 4;
- const end = (std.mem.lastIndexOf(u8, file, "---\n") orelse return error.NoFrontMatter);
-
- var childproc = std.process.Child.init(&.{ "yq", "-o", "json" }, a);
- childproc.stdin_behavior = .Pipe;
- childproc.stdout_behavior = .Pipe;
- childproc.stderr_behavior = .Pipe;
- std.log.info("spawn", .{});
- try childproc.spawn();
- std.log.info("writeAll", .{});
- try childproc.stdin.?.writeAll(file[start..end]);
- childproc.stdin.?.close();
- childproc.stdin = null;
-
- var stdout = std.ArrayList(u8).init(a);
- var stderr = std.ArrayList(u8).init(a);
- std.log.info("collectOutput", .{});
- try childproc.collectOutput(&stdout, &stderr, 1_000_000);
- std.log.info("got output {s}", .{stdout.items});
- std.log.info("wait", .{});
- const term = try childproc.wait();
- if (term.Exited != 0) {
- return error.ProcessError;
- }
- const fm_json = try stdout.toOwnedSlice();
- // Now parse it and add missing fields
- const fm_json_parsed_value = try std.json.parseFromSlice(Page, a, fm_json, .{
- .ignore_unknown_fields = true,
- });
- defer fm_json_parsed_value.deinit();
- var fm_json_parsed = fm_json_parsed_value.value;
- fm_json_parsed.title = fm_json_parsed.title orelse "";
- fm_json_parsed.author = fm_json_parsed.author orelse "Martin Ashby";
- fm_json_parsed.date = fm_json_parsed.date orelse "1900-01-01T00:00:00Z";
- fm_json_parsed.layout = fm_json_parsed.layout orelse "single.html";
-
- var out = std.ArrayList(u8).init(a);
- defer out.deinit();
- try ziggy.stringify(fm_json_parsed, .{.whitespace = .space_2}, out.writer());
- const newfile = try std.mem.concat(a, u8, &.{ "---\n", out.items, "\n", file[end..] });
- try we.dir.writeFile(we.basename, newfile);
- }
- }
- std.log.info("done!", .{});
-}
diff --git a/converter/src/root.zig b/converter/src/root.zig
deleted file mode 100644
index ecfeade..0000000
--- a/converter/src/root.zig
+++ /dev/null
@@ -1,10 +0,0 @@
-const std = @import("std");
-const testing = std.testing;
-
-export fn add(a: i32, b: i32) i32 {
- return a + b;
-}
-
-test "basic add functionality" {
- try testing.expect(add(3, 7) == 10);
-}