aboutsummaryrefslogtreecommitdiff
path: root/converter
diff options
context:
space:
mode:
Diffstat (limited to 'converter')
-rw-r--r--converter/build.zig36
-rw-r--r--converter/build.zig.zon14
-rw-r--r--converter/convert_posts.zig0
-rw-r--r--converter/src/main.zig41
-rw-r--r--converter/src/root.zig10
5 files changed, 101 insertions, 0 deletions
diff --git a/converter/build.zig b/converter/build.zig
new file mode 100644
index 0000000..10f855a
--- /dev/null
+++ b/converter/build.zig
@@ -0,0 +1,36 @@
+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 zig_yaml = b.dependency("zig-yaml", .{});
+ // exe.root_module.addImport("yaml", zig_yaml.module("yaml"));
+
+ 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
new file mode 100644
index 0000000..6e262b1
--- /dev/null
+++ b/converter/build.zig.zon
@@ -0,0 +1,14 @@
+.{
+ .name = "converter",
+ .version = "0.0.0",
+ .dependencies = .{
+ // It doesn't work!
+ //.@"zig-yaml" = .{
+ // .url = "https://github.com/kubkon/zig-yaml/archive/refs/heads/main.tar.gz",
+ // .hash = "122084941d6e06491a85e1356c7cca24a078103d34155e34a10a16a53f420d6bc37b",
+ //},
+ },
+ .paths = .{
+ "",
+ },
+}
diff --git a/converter/convert_posts.zig b/converter/convert_posts.zig
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/converter/convert_posts.zig
diff --git a/converter/src/main.zig b/converter/src/main.zig
new file mode 100644
index 0000000..bc60e35
--- /dev/null
+++ b/converter/src/main.zig
@@ -0,0 +1,41 @@
+const std = @import("std");
+
+pub fn main() !void {
+ const a = std.heap.page_allocator;
+ const contentdir = try std.fs.cwd().openDir("../content", .{.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();
+ const newfile = try std.mem.concat(a, u8, &.{"---\n", fm_json, file[end..]});
+ try we.dir.writeFile(we.basename, newfile);
+ }
+ }
+ std.log.info("done!", .{});
+} \ No newline at end of file
diff --git a/converter/src/root.zig b/converter/src/root.zig
new file mode 100644
index 0000000..ecfeade
--- /dev/null
+++ b/converter/src/root.zig
@@ -0,0 +1,10 @@
+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);
+}