Skip to content

Commit

Permalink
fix: build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
moerabaya committed Apr 7, 2024
1 parent 9563b5f commit d998e8c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
5 changes: 4 additions & 1 deletion pages/posts/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}`,
Expand Down
25 changes: 15 additions & 10 deletions pages/work/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Login slug={meta.slug} redirectPath={asPath} />;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
};
};

Expand Down

0 comments on commit d998e8c

Please sign in to comment.