From d998e8cd92134b1cc3d51b83d80058e7029dd426 Mon Sep 17 00:00:00 2001 From: Mohammed Rabay'a Date: Sun, 7 Apr 2024 12:03:53 +0200 Subject: [PATCH] fix: build issue --- pages/posts/[slug].tsx | 5 ++++- pages/work/[slug].tsx | 25 +++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pages/posts/[slug].tsx b/pages/posts/[slug].tsx index d097f03..694b56b 100644 --- a/pages/posts/[slug].tsx +++ b/pages/posts/[slug].tsx @@ -143,7 +143,6 @@ const getStaticPaths = async () => { const paths = files.reduce((prev: object[], filename) => { prev.push({ params: { slug: filename.replace(".mdx", "") }, - locale: "en-US", }); prev.push({ params: { slug: filename.replace(".mdx", "") }, locale: "ar" }); return prev; @@ -165,6 +164,10 @@ const getStaticProps = async ({ params: { slug }, locale }: any) => { const mdxSource = await serialize(content); if (locale === "ar") { + if (process.env.npm_lifecycle_event === "build") + return { + notFound: true, + }; return { redirect: { destination: `/posts/${slug}`, diff --git a/pages/work/[slug].tsx b/pages/work/[slug].tsx index 31c72a8..d249c93 100644 --- a/pages/work/[slug].tsx +++ b/pages/work/[slug].tsx @@ -36,6 +36,7 @@ const components = { const Project = ({ mdxSource, meta, hasReadPermission }: ProjectProps) => { const { pathname, asPath } = useRouter(); + if (!meta) return; if (meta.password && !hasReadPermission?.[meta.slug]) { return ; } @@ -121,7 +122,6 @@ const getStaticPaths = async () => { const paths = files.reduce((prev: object[], filename) => { prev.push({ params: { slug: filename.replace(".mdx", "") }, - locale: "en-US", }); prev.push({ params: { slug: filename.replace(".mdx", "") }, locale: "ar" }); return prev; @@ -157,25 +157,30 @@ const getStaticProps = async ({ params, locale, ...rest }: any) => { const next = filenames[current + 1]?.replace(".mdx", "") ?? null; const previous = filenames[current - 1]?.replace(".mdx", "") ?? null; - console.log(params, rest); - + const props = { + meta: frontMatter as IProject, + slug: slug as string, + mdxSource, + next, + previous, + }; if (locale === "ar") { + if (process.env.npm_lifecycle_event === "build") + return { + notFound: true, + props, + }; return { redirect: { destination: `/work/${slug}`, permanent: false, }, + props, }; } return { - props: { - meta: frontMatter as IProject, - slug: slug as string, - mdxSource, - next, - previous, - }, + props, }; };