diff options
Diffstat (limited to 'src/anim')
| -rw-r--r-- | src/anim/typst.zig | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/anim/typst.zig b/src/anim/typst.zig index d9df734..05a0d4e 100644 --- a/src/anim/typst.zig +++ b/src/anim/typst.zig @@ -50,12 +50,18 @@ pub fn generate(comptime SceneFile: type, comptime sources: []const []const u8, try out.writeFile(io, .{ .sub_path = "typst.zig", .data = module }); } -/// Runs `typst compile` on `preamble ++ source` and caches the SVG. +/// Runs `typst compile` on `preamble ++ source` and caches the SVG. The +/// root is `/`, so an absolute path in a source is the file's own path +/// (`#image("/home/me/manual.pdf", page: 31)`) and a relative one is +/// in the cache. Typst only reads what a source names, and a scene's +/// sources are its author's code, built by a build that can already read +/// anything. A file named this way is not part of the cache key: changed +/// in place, it keeps its old SVG until its entry in the cache goes. fn compile(gpa: std.mem.Allocator, io: std.Io, cache: std.Io.Dir, name: []const u8, preamble: []const u8, source: []const u8) ![]const u8 { const typ = try std.fmt.allocPrint(gpa, "{s}.typ", .{name}); try cache.writeFile(io, .{ .sub_path = typ, .data = try std.mem.concat(gpa, u8, &.{ preamble, "\n", source, "\n" }) }); const result = try std.process.run(gpa, io, .{ - .argv = &.{ "typst", "compile", "--format", "svg", typ, name }, + .argv = &.{ "typst", "compile", "--root", "/", "--format", "svg", typ, name }, .cwd = .{ .dir = cache }, }); if (result.term != .exited or result.term.exited != 0) { |
