forked from denoland/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_data.ts
More file actions
53 lines (44 loc) · 1.28 KB
/
_data.ts
File metadata and controls
53 lines (44 loc) · 1.28 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
47
48
49
50
51
52
53
import { extractYaml } from "@std/front-matter";
import { walk } from "jsr:@std/fs";
import { basename } from "jsr:@std/path";
import { Sidebar, SidebarLink } from "../types.ts";
async function generateSidebarItems() {
const sidebarItems = [];
for await (
const dirEntry of walk(
new URL(import.meta.resolve("./rules/")),
{ exts: ["md"] },
)
) {
const lintRuleName = basename(dirEntry.path).split(".")[0];
const mdContent = await Deno.readTextFile(dirEntry.path);
let frontMatterData = { body: "", attrs: {} };
try {
frontMatterData = extractYaml(mdContent);
} catch {
frontMatterData.body = mdContent;
}
const tags = frontMatterData.attrs.tags ?? [];
const content = frontMatterData.body;
sidebarItems.push(
{
href: `/lint/rules/${lintRuleName}/`,
title: lintRuleName,
tags,
content,
} satisfies SidebarLink,
);
}
sidebarItems.sort((a, b) => a.title.localeCompare(b.title));
return sidebarItems;
}
export const lintRulePages = await generateSidebarItems();
export const sectionTitle = "Lint rules";
export const sectionHref = "/lint/";
export const sidebar = [
{
title: "List of rules",
href: sectionHref,
items: lintRulePages,
},
] satisfies Sidebar;