From c785a66b64d894793381a9fa6b1927e16c6da67a Mon Sep 17 00:00:00 2001 From: Matthew M-B Date: Sun, 8 Sep 2024 11:00:12 -0400 Subject: [PATCH] Add alert for when solution is undefined --- src/pages/questions/solution/[...path].astro | 32 +++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/pages/questions/solution/[...path].astro b/src/pages/questions/solution/[...path].astro index 6c0d0232..e6564cfc 100644 --- a/src/pages/questions/solution/[...path].astro +++ b/src/pages/questions/solution/[...path].astro @@ -7,21 +7,37 @@ import Tag from "@components/Tag/Tag.astro"; import { dynamicImport } from "@utilities/index"; import { getCollection } from "astro:content"; import { default as Layout } from "src/layouts/Content/Content.astro"; +import { DiscordMessageType, sendAlert } from "@utilities/discord"; export async function getStaticPaths() { const questions = await getCollection("questions"); - return questions - .filter((question: any) => question.id.includes("index.md")) - .map((page) => { - return { - params: { path: page.slug }, - props: { page }, - }; - }); + const filteredQuestions = questions.filter((question: any) => { + return ( + question.data.solution !== undefined && question.id.includes("index.md") + ); + }); + return filteredQuestions.map((page) => { + return { + params: { path: page.slug }, + props: { page }, + }; + }); } const { path } = Astro.params; const { page } = Astro.props; + +if (page.data.solution === undefined) { + sendAlert({ + type: DiscordMessageType.ERROR, + data: { + message: `Solution not found for question ${page.data.path}`, + page: page, + path: path, + }, + }); +} + const { Content } = await page.render(); const solutionFile = await dynamicImport( `../../../content/questions/${page.data.solution}`,