-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathTutorialsLayout.astro
76 lines (67 loc) · 2.25 KB
/
TutorialsLayout.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
import { type CollectionEntry } from "astro:content";
import Head from "@components/Head/index.astro";
import BaseLayout from "./BaseLayout.astro";
import { setJumpToState, type JumpToLink } from "../globals/state";
import { getCurrentLocale, getUiTranslator } from "../i18n/utils";
import { categories } from "../content/tutorials/config";
import LinkButton from "@components/LinkButton/index.astro";
import GridItemTutorial from "@components/GridItem/Tutorial.astro";
type TutorialEntry = CollectionEntry<"tutorials">;
const currentLocale = getCurrentLocale(Astro.url.pathname);
const t = await getUiTranslator(currentLocale);
const { entries } = Astro.props;
const sections = categories.map((slug) => {
const name = t("tutorialCategories", slug);
const sectionEntries = entries
.filter((e: TutorialEntry) => e.data.category === slug)
.sort(
(a: TutorialEntry, b: TutorialEntry) =>
(a.data.categoryIndex ?? 1000) - (b.data.categoryIndex ?? 1000)
);
return { slug, name, sectionEntries };
});
const pageJumpToLinks = categories
.map((category) => ({
url: `#${category}`,
label: t("tutorialCategories", category),
}))
.concat([
{
url: "#education-resources",
label: t("tutorialsPage", "education-resources"),
},
]);
setJumpToState({
links: pageJumpToLinks as JumpToLink[],
});
---
<Head title="Tutorials" locale={currentLocale} />
<BaseLayout title="Tutorials">
{
sections.map(({ slug, name, sectionEntries }) => (
<section>
<h2 id={slug} class="mb-gutter-md mt-0">
{name}
</h2>
<ul class="content-grid border-b border-sidebar-type-color last:border-0">
{sectionEntries.map((entry: TutorialEntry, i: number) => (
<li class="col-span-3">
<GridItemTutorial item={entry} lazyLoad={i > 3} />
</li>
))}
</ul>
</section>
))
}
<section>
<h2 class="mb-gutter-md mt-0">
{t("tutorialsPage", "education-resources")}<a id="education-resources"
></a>
</h2>
<p>{t("tutorialsPage", "education-resources-snippet")}</p>
<LinkButton url="/education-resources" variant="link" class="mt-lg">
{t("tutorialsPage", "view-education-resources")}
</LinkButton>
</section>
</BaseLayout>