aboutsummaryrefslogtreecommitdiff
path: root/docs/tools/docs.tl
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--docs/tools/docs.tl74
1 files changed, 74 insertions, 0 deletions
diff --git a/docs/tools/docs.tl b/docs/tools/docs.tl
new file mode 100644
index 00000000..502de3c4
--- /dev/null
+++ b/docs/tools/docs.tl
@@ -0,0 +1,74 @@
1local lfs = require("lfs")
2
3local args = {...}
4
5if not args[1] then
6 print("missing argument: <dirname>")
7 os.exit(1)
8end
9
10local dirname = args[1]
11
12local function path(filename: string): string
13 return dirname .. "/" .. filename
14end
15
16local function process_md(filename: string)
17 local data = assert(io.open(path(filename))):read("*a")
18 local missing = {}
19 for link in data:gmatch("%]%(([^)]*%.md)[^)]*%)") do
20 if not lfs.attributes(path(link)) then
21 table.insert(missing, { at = filename, link = link })
22 end
23 end
24
25 if #missing == 0 then
26 return
27 end
28
29 print("Broken links:")
30
31 for _, link in ipairs(missing) do
32 print("* At " .. link.at .. " : " .. link.link)
33 end
34
35 os.exit(1)
36end
37
38local function check_index(filename: string, all_pages: {string: boolean})
39 local data = assert(io.open(path(filename))):read("*a")
40 for link in data:gmatch("%]%(([^)]*%.md)[^)]*%)") do
41 all_pages[link] = nil
42 end
43
44 if not next(all_pages) then
45 return
46 end
47
48 local missing = {}
49 for k, _ in pairs(all_pages) do
50 table.insert(missing, k)
51 end
52 table.sort(missing)
53
54 print("Pages not referenced in index:")
55
56 for _, page in ipairs(missing) do
57 print("* " .. page)
58 end
59
60 os.exit(1)
61end
62
63local all_pages = {}
64for f in lfs.dir(args[1]) do
65 if f:match("%.md$") then
66 process_md(f)
67 all_pages[f] = true
68 end
69end
70
71check_index("index.md", all_pages)
72
73print("All ok!")
74