-
Notifications
You must be signed in to change notification settings - Fork 355
Expand file tree
/
Copy pathfrontmatter_test.ts
More file actions
46 lines (38 loc) · 1.47 KB
/
frontmatter_test.ts
File metadata and controls
46 lines (38 loc) · 1.47 KB
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
import { walk } from "@std/fs";
import { extract } from "@std/front-matter/yaml";
import { assert, assertEquals } from "@std/assert";
const DIRS_TO_CHECK = ["./runtime", "./deploy", "./examples"];
Deno.test("Frontmatter titles must not contain backticks", async (t) => {
for (const dir of DIRS_TO_CHECK) {
for await (const entry of walk(dir, { exts: [".md", ".mdx"] })) {
const content = await Deno.readTextFile(entry.path);
if (!content.startsWith("---")) continue;
const { attrs } = extract<{ title?: string }>(content);
if (typeof attrs.title !== "string") continue;
await t.step(entry.path, () => {
assert(
!attrs.title!.includes("`"),
`Title contains backticks: "${attrs.title}". Use plain text instead.`,
);
});
}
}
});
Deno.test("CLI command page titles must be just the command name", async (t) => {
for await (
const entry of walk("./runtime/reference/cli", { exts: [".md"] })
) {
const content = await Deno.readTextFile(entry.path);
if (!content.startsWith("---")) continue;
const { attrs } = extract<{ title?: string; command?: string }>(content);
if (typeof attrs.command !== "string") continue;
const expected = `deno ${attrs.command}`;
await t.step(entry.path, () => {
assertEquals(
attrs.title,
expected,
`Title should be "${expected}", got "${attrs.title}". Put descriptions in the "description" field instead.`,
);
});
}
});