Skip to content

Commit f69865e

Browse files
committed
fix types
1 parent e1c28fb commit f69865e

File tree

3 files changed

+61
-52
lines changed

3 files changed

+61
-52
lines changed

contents/project-kinds.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export const kinds = [
2+
{
3+
frontmatter: "long-term",
4+
path: undefined,
5+
title: "長期プロジェクト",
6+
tabTitle: "長期プロジェクト",
7+
},
8+
{
9+
frontmatter: "festival",
10+
path: "festival",
11+
title: "学園祭プロジェクト",
12+
tabTitle: "学園祭",
13+
},
14+
{
15+
frontmatter: "hackathon",
16+
path: "hackathon",
17+
title: "ハッカソンプロジェクト",
18+
tabTitle: "ハッカソン",
19+
},
20+
] as const;

src/pages/projects/[...kind].astro

Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,20 @@ import { getCollection } from "astro:content";
33
import ProjectList from "+/components/ProjectList.astro";
44
import GlobalLayout from "+/layouts/GlobalLayout.astro";
55
import { Focus } from "+/schema";
6+
import { kinds } from "+contents/project-kinds.ts";
67
7-
const kinds = [
8-
{
9-
path: undefined,
10-
kind: "long-term",
11-
title: "長期プロジェクト",
12-
tab: "長期プロジェクト",
13-
},
14-
{
15-
path: "hackathon",
16-
kind: "hackathon",
17-
title: "ハッカソン",
18-
tab: "ハッカソン",
19-
},
20-
{
21-
path: "festival",
22-
kind: "festival",
23-
title: "学園祭プロジェクト",
24-
tab: "学園祭",
25-
},
26-
];
27-
export function getStaticPaths(params) {
8+
export function getStaticPaths() {
289
return kinds.map((kind) => ({
2910
params: { kind: kind.path },
3011
props: { kind },
3112
}));
3213
}
3314
34-
const tabFocus = Astro.props.kind.kind;
35-
const titles = new Map([
36-
["long-term", "長期プロジェクト"],
37-
["festival", "学園祭プロジェクト"],
38-
["hackathon", "ハッカソン"],
39-
]);
40-
function getTitle() {
41-
return titles.get(Astro.props.kind);
42-
}
15+
const kind = Astro.props.kind;
4316
4417
const projects = (await getCollection("projects"))
4518
.filter((project) => {
46-
return project.data.kind === Astro.props.kind;
19+
return project.data.kind === kind.frontmatter;
4720
})
4821
.sort((a, b) => {
4922
const a_order = a.data.order ?? Number.POSITIVE_INFINITY;
@@ -62,26 +35,40 @@ const projects = (await getCollection("projects"))
6235
image={null}
6336
>
6437
<main class="container mx-auto px-4 py-24">
65-
<h1 class="text-center text-4xl">長期プロジェクト</h1>
66-
<div role="tablist" class="tabs">
67-
<a
68-
role="tab"
69-
class:list={["tab", { "tab-active": tabFocus === "long-term" }]}
70-
href="/projects">長期プロジェクト</a
71-
>
72-
<a
73-
role="tab"
74-
class="tab"
75-
class:list={["tab", { "tab-active": tabFocus === "festival" }]}
76-
href="/projects/festival">学園祭</a
77-
>
78-
<a
79-
role="tab"
80-
class="tab"
81-
class:list={["tab", { "tab-active": tabFocus === "hackathon" }]}
82-
href="/projects/hackathon">ハッカソン</a
83-
>
38+
<h1 class="text-center text-4xl">{kind.title}</h1>
39+
<div role="tablist" class="tabs tabs-lift">
40+
{
41+
kinds.map((tab) => (
42+
<a>
43+
<a
44+
role="tab"
45+
class:list={[
46+
"tab",
47+
{ "tab-active": kind.frontmatter === tab.frontmatter },
48+
]}
49+
href={tab.path ? `/projects/${tab.path}` : "/projects"}
50+
>
51+
{tab.tabTitle}
52+
</a>
53+
</a>
54+
))
55+
}
8456
</div>
85-
<ProjectList {projects} class="mt-16" variant="full" />
57+
{
58+
projects.length === 0 ? (
59+
<p class="mt-30 text-center text-gray-500">
60+
プロジェクトはまだありません。
61+
</p>
62+
) : (
63+
<ProjectList {projects} class="mt-16" variant="full" />
64+
)
65+
}
66+
{
67+
projects.length < 10 && (
68+
<p class="mt-30 text-center text-gray-500">
69+
このページは準備中です。ほとんどのプロジェクトは反映されていません。
70+
</p>
71+
)
72+
}
8673
</main>
8774
</GlobalLayout>

src/schema.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { type ImageFunction, reference } from "astro:content";
22
import { z } from "astro:schema";
3+
import { kinds } from "+contents/project-kinds";
34
import { TZDate } from "@date-fns/tz";
45

56
export type Article = z.infer<ReturnType<typeof CreateArticleSchema>>;
@@ -33,10 +34,11 @@ export const CreateArticleSchema = ({ image }: { image: ImageFunction }) =>
3334
},
3435
);
3536

37+
type Kind = (typeof kinds)[number]["frontmatter"];
3638
export const CreateProjectSchema = ({ image }: { image: ImageFunction }) =>
3739
z.object({
3840
title: z.string(),
39-
kind: z.enum(["long-term", "hackathon", "festival"]),
41+
kind: z.enum(kinds.map((kind) => kind.frontmatter) as [Kind, ...Kind[]]),
4042
status: z.enum([
4143
"plan",
4244
"under-development",

0 commit comments

Comments
 (0)