This commit is contained in:
Anthon van der Neut 2025-11-25 07:50:12 +01:00 committed by GitHub
commit 8c530e9d56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View file

@ -1455,6 +1455,9 @@ fn generateLangRef(b: *std.Build) std.Build.LazyPath {
const docgen_cmd = b.addRunArtifact(docgen_exe);
docgen_cmd.addArgs(&.{"--code-dir"});
docgen_cmd.addDirectoryArg(wf.getDirectory());
var buf: [std.fs.max_path_bytes]u8 = undefined;
const os_cwd = std.process.getCwd(&buf) catch unreachable;
docgen_cmd.addArgs(&.{"--base-dir", os_cwd });
docgen_cmd.addFileArg(b.path("doc/langref.html.in"));
return docgen_cmd.addOutputFileArg("langref.html");

View file

@ -43,6 +43,7 @@ pub fn main() !void {
const io = threaded.io();
var opt_code_dir: ?[]const u8 = null;
var opt_base_dir: ?[]const u8 = null;
var opt_input: ?[]const u8 = null;
var opt_output: ?[]const u8 = null;
@ -57,6 +58,12 @@ pub fn main() !void {
} else {
fatal("expected parameter after --code-dir", .{});
}
} else if (mem.eql(u8, arg, "--base-dir")) {
if (args_it.next()) |param| {
opt_base_dir = param;
} else {
fatal("expected parameter after --base-dir", .{});
}
} else {
fatal("unrecognized option: '{s}'", .{arg});
}
@ -89,7 +96,7 @@ pub fn main() !void {
var tokenizer = Tokenizer.init(input_path, input_file_bytes);
var toc = try genToc(arena, &tokenizer);
try genHtml(arena, &tokenizer, &toc, code_dir, &out_file_writer.interface);
try genHtml(arena, &tokenizer, &toc, code_dir, opt_base_dir, &out_file_writer.interface);
try out_file_writer.end();
}
@ -991,6 +998,7 @@ fn genHtml(
tokenizer: *Tokenizer,
toc: *Toc,
code_dir: std.fs.Dir,
opt_base_dir: ?[]const u8,
out: *Writer,
) !void {
for (toc.nodes) |node| {
@ -1051,7 +1059,13 @@ fn genHtml(
};
defer allocator.free(contents);
try out.writeAll(contents);
if (opt_base_dir) |base_dir| {
const rep_contents = try mem.replaceOwned(u8, allocator, contents, base_dir, "");
defer allocator.free(rep_contents);
try out.writeAll(rep_contents);
} else {
try out.writeAll(contents);
}
},
}
}