diff options
| author | Robert Günzler <r@gnzler.io> | 2025-09-10 13:38:16 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2025-09-29 17:06:10 +0200 |
| commit | 109b73a3936c90aa89cd12c60aacf51439d31370 (patch) | |
| tree | 77ec030f1676a9f8212b6f5eba2a70e74c99184c /src/exe.zig | |
| parent | 34f08e9b1036171bbcd217929c7df2c7f16b627e (diff) | |
| download | site-109b73a3936c90aa89cd12c60aacf51439d31370.tar.gz | |
use rbl for running pandoc
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'src/exe.zig')
| -rw-r--r-- | src/exe.zig | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/src/exe.zig b/src/exe.zig index ef38a67..bfe7370 100644 --- a/src/exe.zig +++ b/src/exe.zig @@ -9,19 +9,40 @@ pub fn run_pandoc(ctx: *Context) !void { defer ctx.progress_end(); for (ctx.markdown.items) |page| { - const targetpath = try fs.replace_extension(ctx.allocator(), page, "md"); - defer ctx.allocator().free(targetpath); + const source_path = try std.fs.path.join(ctx.allocator(), &.{ Context.params.PAGE_PATH, page }); + defer ctx.allocator().free(source_path); + const target_path = try fs.replace_extension(ctx.allocator(), source_path, "htm"); + defer ctx.allocator().free(target_path); - const f = try fs.FileSwapper.createAt(ctx.allocator(), targetpath); + const f = try fs.FileSwapper.createAt(ctx.allocator(), target_path); defer f.close(); - try run(ctx, &.{ "notify-send", "hi", page }); + try f.writer().print( + \\<!-- Generated file, you may edit and discard {s} :) --> + \\ + , + .{page}, + ); + + try capture_stdout(ctx, &.{ + Context.params.PANDOC, + "--from", + "markdown+wikilinks_title_after_pipe+autolink_bare_uris", + "--to", + "html5", + "--lua-filter", + // TODO: embed the preproc filter + Context.params.PANDOC_PREPROC, + "--strip-comments", + "--output=-", + source_path, + }, f.writer().any()); } - // @ echo "<!-- Generated file, you may edit and discard $< :) -->" >$@ - // $(PANDOC) -fmarkdown+wikilinks_title_after_pipe+autolink_bare_uris -thtml5 --lua-filter=$(PANDOC_PREPROC) --strip-comments $< >>$@ + + log.info("Processed {d} markdown files.", .{ctx.markdown.items.len}); } -pub fn run(ctx: *Context, argv: []const []const u8) !void { +pub fn capture_stdout(ctx: *Context, argv: []const []const u8, buf: std.io.AnyWriter) !void { const command = try std.mem.join(ctx.allocator(), " ", argv); defer ctx.allocator().free(command); const label = try std.fmt.allocPrint(ctx.allocator(), "running {s}", .{command}); @@ -30,10 +51,14 @@ pub fn run(ctx: *Context, argv: []const []const u8) !void { ctx.progress_start(label); defer ctx.progress_end(); - const result = try std.process.Child.run(.{ - .argv = argv, - .allocator = std.heap.page_allocator, - .progress_node = ctx.progress_nodes.getLast(), - }); + var p = std.process.Child.init(argv, std.heap.page_allocator); + p.stdout_behavior = .Pipe; + p.progress_node = ctx.progress_nodes.getLast(); + + try p.spawn(); + + try buf.writeFile(p.stdout.?); + + const result = try p.wait(); _ = result; } |