Skip to content

Commit c785a66

Browse files
committed
Add alert for when solution is undefined
1 parent 18dbd30 commit c785a66

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/pages/questions/solution/[...path].astro

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,37 @@ import Tag from "@components/Tag/Tag.astro";
77
import { dynamicImport } from "@utilities/index";
88
import { getCollection } from "astro:content";
99
import { default as Layout } from "src/layouts/Content/Content.astro";
10+
import { DiscordMessageType, sendAlert } from "@utilities/discord";
1011
1112
export async function getStaticPaths() {
1213
const questions = await getCollection("questions");
13-
return questions
14-
.filter((question: any) => question.id.includes("index.md"))
15-
.map((page) => {
16-
return {
17-
params: { path: page.slug },
18-
props: { page },
19-
};
20-
});
14+
const filteredQuestions = questions.filter((question: any) => {
15+
return (
16+
question.data.solution !== undefined && question.id.includes("index.md")
17+
);
18+
});
19+
return filteredQuestions.map((page) => {
20+
return {
21+
params: { path: page.slug },
22+
props: { page },
23+
};
24+
});
2125
}
2226
2327
const { path } = Astro.params;
2428
const { page } = Astro.props;
29+
30+
if (page.data.solution === undefined) {
31+
sendAlert({
32+
type: DiscordMessageType.ERROR,
33+
data: {
34+
message: `Solution not found for question ${page.data.path}`,
35+
page: page,
36+
path: path,
37+
},
38+
});
39+
}
40+
2541
const { Content } = await page.render();
2642
const solutionFile = await dynamicImport(
2743
`../../../content/questions/${page.data.solution}`,

0 commit comments

Comments
 (0)