Skip to content

Commit 9e8e73a

Browse files
committed
docs
1 parent c824a80 commit 9e8e73a

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

docs/src/pages/glossary.astro

+37-20
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,55 @@
11
---
22
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro";
3-
const basePath = `/${Astro.url.pathname.split("/")[1]}`;
3+
4+
interface GlossaryEntry {
5+
file: string;
6+
frontmatter: {
7+
title: string;
8+
};
9+
}
410
511
interface File {
612
fileBase: string;
713
title: string;
814
}
915
10-
const importedFiles = await Astro.glob("/src/content/docs/glossary/*.md");
16+
const basePath = `/${Astro.url.pathname.split("/")[1]}`;
1117
12-
const files: File[] = importedFiles.map(({ file, frontmatter: { title } }) => {
13-
const fileBase = file.toString().split("/").pop()?.split(".").shift();
14-
return { fileBase, title };
18+
// Get all markdown files
19+
const posts = import.meta.glob<GlossaryEntry>(
20+
"/src/content/docs/glossary/*.md",
21+
{
22+
eager: true,
23+
}
24+
);
25+
26+
// Convert posts object to array and map to File[]
27+
const files: File[] = Object.entries(posts).map(([path, post]) => {
28+
const fileBase = path.split("/").pop()?.split(".").shift() ?? "";
29+
return {
30+
fileBase,
31+
title: post.frontmatter.title,
32+
};
1533
});
1634
17-
const sections = files.reduce(
18-
(acc: { [key: string]: File[] }, { title, fileBase }) => {
19-
const firstLetter = title.charAt(0).toUpperCase();
20-
if (!acc[firstLetter]) {
21-
acc[firstLetter] = [];
22-
}
23-
acc[firstLetter].push({ fileBase, title });
24-
return acc;
25-
},
26-
{}
27-
);
35+
// Group files by first letter
36+
const sections = files.reduce((acc: { [key: string]: File[] }, file) => {
37+
const firstLetter = file.title.charAt(0).toUpperCase();
38+
if (!acc[firstLetter]) {
39+
acc[firstLetter] = [];
40+
}
41+
acc[firstLetter].push(file);
42+
return acc;
43+
}, {});
2844
29-
const headings = Object.entries(sections).map(
30-
([slug, _]: [string, File[]]) => ({
45+
// Generate headings for each section
46+
const headings = Object.entries(sections)
47+
.sort(([a], [b]) => a.localeCompare(b))
48+
.map(([slug]) => ({
3149
depth: 2,
3250
slug,
3351
text: slug,
34-
})
35-
);
52+
}));
3653
---
3754

3855
<StarlightPage frontmatter={{ title: "Glossary" }} headings={headings}>

0 commit comments

Comments
 (0)