-
Notifications
You must be signed in to change notification settings - Fork 7
/
Sidebar.astro
48 lines (46 loc) · 1.52 KB
/
Sidebar.astro
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
---
import Default from "@astrojs/starlight/components/Sidebar.astro";
import type { StarlightRouteData } from "node_modules/@astrojs/starlight/utils/route-data";
import type { SidebarEntry } from "node_modules/@astrojs/starlight/utils/navigation";
const isBlog = Astro.props.id.includes("blog");
const blogPosts = await Astro.glob("../content/docs/blog/*.mdx");
const sidebarPostList: StarlightRouteData["sidebar"] = blogPosts
.filter((p) => !p.url?.includes("index"))
.sort(
(a, b) =>
new Date(b.frontmatter.date).getTime() -
new Date(a.frontmatter.date).getTime(),
)
.map((p) => {
const url = p.url?.replace("src/content/docs", "").replace(".mdx", "");
return {
attrs: {},
badge: undefined,
href: url,
isCurrent: Astro.url.pathname.includes(url || ""),
label: ` ${p.frontmatter.title} (${new Date(p.frontmatter.date).toISOString().substring(0, 10)})`,
type: "link",
} as SidebarEntry;
});
const blogSidebar: StarlightRouteData["sidebar"] = [
{
attrs: {},
badge: undefined,
href: "/blog",
isCurrent: Astro.props.id === "blog/index.mdx",
label: "BlueBuild blog",
type: "link",
},
{
badge: undefined,
label: "All posts",
type: "group",
collapsed: false,
entries: sidebarPostList,
},
];
---
<Default
{...Astro.props as StarlightRouteData}
sidebar={isBlog ? blogSidebar : Astro.props.sidebar}
/>