-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026 Shota FUJI
//
// This program is free software: you can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.
const builtin = @import("builtin");
const std = @import("std");
const pages: []const []const u8 = @import("./pages.zon");
const diagrams: []const []const u8 = @import("./diagrams.zon");
pub fn build(b: *std.Build) !void {
const pandoc_exe = pandoc_exe: {
const dep = if (builtin.os.tag == .linux and builtin.cpu.arch == .x86_64)
b.lazyDependency("pandoc_linux_amd64", .{}) orelse return
else {
@panic("このホスト用の pandoc が用意できません。 build.zig.zon と build.zig を編集してホストを追加してください。");
};
break :pandoc_exe dep.path("bin/pandoc");
};
const dist = dist: {
const dir = b.addWriteFiles();
for (pages) |page| {
if (!std.mem.startsWith(u8, page, "src/")) {
@panic(b.fmt("ページファイルは src/ 配下に置いてください: {s}", .{page}));
}
const ext = std.fs.path.extension(page);
const format = format: {
if (std.mem.eql(u8, ext, ".md")) {
break :format "gfm";
}
if (std.mem.eql(u8, ext, ".adoc")) {
break :format "asciidoc";
}
@panic(b.fmt("{s} ファイルは読み込めません: {s}", .{ ext, page }));
};
const pandoc = std.Build.Step.Run.create(b, "pandoc");
pandoc.addFileArg(pandoc_exe);
pandoc.addArgs(&.{ "--from", format });
pandoc.addArg("--to=html");
pandoc.addArg("--standalone");
pandoc.addFileArg(b.path(page));
const output = pandoc.addPrefixedOutputFileArg("--output=", "out.html");
_ = dir.addCopyFile(output, b.fmt("{s}.html", .{page["src/".len .. page.len - ext.len]}));
}
for (diagrams) |diagram| {
if (!std.mem.startsWith(u8, diagram, "src/")) {
@panic(b.fmt("図形ファイルは src/ 配下に置いてください: {s}", .{diagram}));
}
const ext = std.fs.path.extension(diagram);
if (!std.mem.eql(u8, ext, ".d2")) {
@panic(b.fmt("図形ファイルは d2 形式のみ対応しています: {s}", .{diagram}));
}
const d2 = b.addSystemCommand(&.{ "d2", "--dark-theme", "200", "--layout", "elk" });
// d2 は成功時でも stderr にメッセージを表示し、かつこの挙動を無効化することが
// できない。 "expectStdErrMatch" を使うと、出力された stderr がビルド成果物に
// なるのか zig build の結果に表示されなくなる。
d2.expectStdErrMatch("success: successfully compiled");
d2.addFileArg(b.path(diagram));
const svg = d2.addOutputFileArg("out.svg");
_ = dir.addCopyFile(svg, b.fmt("{s}.svg", .{diagram["src/".len .. diagram.len - ext.len]}));
}
break :dist dir;
};
// デフォルトインストール
{
const install = b.addInstallDirectory(.{
.source_dir = dist.getDirectory(),
.install_dir = .{ .custom = "" },
.install_subdir = "",
});
b.default_step.dependOn(&install.step);
}
}