Skip to content

Commit 7c22846

Browse files
committed
astro v5
1 parent 81fa409 commit 7c22846

File tree

10 files changed

+57
-28
lines changed

10 files changed

+57
-28
lines changed

src/components/pages/bachelor/TeamCard.astro

+9-7
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ const { team, href } = Astro.props;
4040
facultyRef.collection,
4141
facultyRef.id,
4242
);
43-
return (
44-
<a href={`/~${facultyRef.id}`} class="faculty-name">
45-
{faculty.data.name
46-
? faculty.data.name
47-
: faculty.data.eng_name}
48-
</a>
49-
);
43+
if (faculty) {
44+
return (
45+
<a href={`/~${facultyRef.id}`} class="faculty-name">
46+
{faculty.data.name
47+
? faculty.data.name
48+
: faculty.data.eng_name}
49+
</a>
50+
);
51+
}
5052
})}
5153
</div>
5254
<div class="capacity-n">

src/components/pages/members/MemberCard.astro

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ interface Props {
1010
}
1111
1212
const props = Astro.props.faculty;
13-
const team = await getEntry("team", props.team.slug);
13+
const team = await getEntry("team", props.team.id);
14+
if (!team) {
15+
throw new Error(`${props.team.id} not found`);
16+
}
1417
---
1518

1619
<section>

src/content/config.ts src/content.config.ts

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { glob } from "astro/loaders";
12
import {
23
z,
34
defineCollection,
@@ -318,27 +319,45 @@ export type CarouselPicture = z.infer<ReturnType<typeof carouselSchema>>;
318319

319320
export const collections = {
320321
news: defineCollection({
321-
type: "content",
322322
schema: newsSchema,
323+
loader: glob({
324+
base: "./content/news",
325+
pattern: "**/*.mdx",
326+
}),
323327
}),
324328
publication: defineCollection({
325-
type: "data",
326329
schema: publicationSchema,
330+
loader: glob({
331+
base: "./content/publication",
332+
pattern: "**/*.yml",
333+
}),
327334
}),
328335
member: defineCollection({
329-
type: "data",
330336
schema: memberSchema,
337+
loader: glob({
338+
base: "./content/member",
339+
pattern: "**/*.yml",
340+
}),
331341
}),
332342
alumni: defineCollection({
333-
type: "data",
334343
schema: alumnusSchema,
344+
loader: glob({
345+
base: "./content/alumni",
346+
pattern: "**/*.yml",
347+
}),
335348
}),
336349
team: defineCollection({
337-
type: "content",
338350
schema: teamSchema,
351+
loader: glob({
352+
base: "./content/team",
353+
pattern: "**/*.mdx",
354+
}),
339355
}),
340356
carousel: defineCollection({
341-
type: "data",
342357
schema: carouselSchema,
358+
loader: glob({
359+
base: "./content/carousel",
360+
pattern: "**/*.yml",
361+
}),
343362
}),
344363
};

src/layouts/base/parts/header/sitemap.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const bachelorPage: JustLinkIndex = {
3737

3838
const teamPages = (await getCollection("team")).map((team) => ({
3939
title: team.data.name,
40-
url: `/teams/${team.slug}`,
40+
url: `/teams/${team.id}`,
4141
icon: team.data.icon,
4242
}));
4343

src/pages/bachelor.astro

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const generalSessionFormLink = "https://forms.gle/meqA8rHAmdPdb2Cd9";
106106
<Teams>
107107
{
108108
teams.map((team) => (
109-
<TeamCard team={team.data} href={`/teams/${team.slug}`} />
109+
<TeamCard team={team.data} href={`/teams/${team.id}`} />
110110
))
111111
}
112112
</Teams>

src/pages/index.astro

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const carouselPictures = (await getCollection("carousel"))
8080
<ListItem class="news-headline">
8181
<div>
8282
<span class="news-date">{news.data.date}</span>
83-
<ExternalLink href={`/news/${news.slug}`}>
83+
<ExternalLink href={`/news/${news.id}`}>
8484
{news.data.title}
8585
</ExternalLink>
8686
</div>

src/pages/news/[year]/[slug].astro

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { getCollection, getEntry } from "astro:content";
44
import Base from "@layouts/base/index.astro";
55
import NoImageHeader from "@components/composite/header/NoImageHeader.astro";
66
import ResponsiveWidth from "@components/layout/ResponsiveWidth.astro";
7+
import { render } from "astro:content";
78
89
export const getStaticPaths = (async () => {
910
const news = await getCollection("news");
1011
return news.map((news) => {
11-
const matched = /(\d{4})\/(.+)/.exec(news.slug);
12+
const matched = /(\d{4})\/(.+)/.exec(news.id);
1213
if (matched && matched[1] && matched[2]) {
1314
return {
1415
params: {
@@ -25,11 +26,11 @@ export const getStaticPaths = (async () => {
2526
const params = Astro.params;
2627
2728
const news = await getEntry("news", `${params.year}/${params.slug}`);
28-
if (news === undefined) {
29+
if (!news) {
2930
throw new Error(`${params.year}/${params.slug} not found`);
3031
}
3132
32-
const Body = await news.render();
33+
const Body = await render(news);
3334
---
3435

3536
<Base title={news.data.title} description={news.data.description}>

src/pages/news/index.astro

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const news = (await getCollection("news")).sort(
1919
news.map((article) => (
2020
<li class="news-heading">
2121
<h2 class="title">
22-
<ExternalLink href={`/news/${article.slug}`}>
22+
<ExternalLink href={`/news/${article.id}`}>
2323
{article.data.title}
2424
</ExternalLink>
2525
</h2>

src/pages/teams/[slug].astro

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
import type { GetStaticPaths } from "astro";
3-
import { getCollection, getEntry } from "astro:content";
3+
import { getCollection, getEntry, render } from "astro:content";
44
import Base from "@layouts/base/index.astro";
55
import BlurImageHeader from "@components/composite/header/BlurImageHeader.astro";
66
import ResponsiveWidth from "@components/layout/ResponsiveWidth.astro";
@@ -11,31 +11,35 @@ import H2 from "@components/composite/heading/h2.astro";
1111
import VSpace from "@components/layout/VSpace.astro";
1212
import RecentWorks from "@components/pages/teams/RecentWorks.astro";
1313
import { viewRank } from "@content";
14+
import type { CollectionEntry } from "astro:content";
1415
1516
export const getStaticPaths = (async () => {
1617
return (await getCollection("team")).map((team) => ({
17-
params: { slug: team.slug },
18+
params: { slug: team.id },
1819
}));
1920
}) satisfies GetStaticPaths;
2021
21-
const team = await getEntry("team", Astro.params.slug);
22+
const team = (await getEntry(
23+
"team",
24+
Astro.params.slug,
25+
)) as CollectionEntry<"team">;
2226
23-
const Rendered = await team.render();
27+
const Rendered = await render(team);
2428
2529
const faculties = await getCollection(
2630
"member",
2731
(member) =>
2832
(member.data.occupation === "Faculty" ||
2933
member.data.occupation === "Researcher") &&
30-
member.data.team.slug === Astro.params.slug,
34+
member.data.team.id === Astro.params.slug,
3135
);
3236
3337
const students = await getCollection(
3438
"member",
3539
(member) =>
3640
(member.data.occupation === "Student" ||
3741
member.data.occupation === "Research Student") &&
38-
member.data.team.slug === Astro.params.slug,
42+
member.data.team.id === Astro.params.slug,
3943
);
4044
---
4145

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"@components/*": ["src/components/*"],
88
"@layouts/*": ["src/layouts/*"],
99
"@asset/*": ["src/asset/*"],
10-
"@content": ["src/content/config.ts"]
10+
"@content": ["src/content.config.ts"]
1111
}
1212
},
1313
"include": [

0 commit comments

Comments
 (0)