1
0
Fork 0

fix(org): Avoid confusing about what slug means

This commit is contained in:
joostdecock 2023-07-21 19:22:10 +02:00
parent f985389236
commit efc1821150
2 changed files with 17 additions and 31 deletions

View file

@ -15,9 +15,9 @@ const namespaces = [...layoutNs, ...postNs, ...pageNs]
* when path and locale come from static props (as here)
* or set them manually.
*/
const BlogPage = ({ locale, slug, page }) => {
const BlogPage = ({ locale, dir, page }) => {
// function to load the correct markdown
const loader = useCallback(() => import(`orgmarkdown/blog/${slug}/${locale}.md`), [slug, locale])
const loader = useCallback(() => import(`orgmarkdown/blog/${dir}/${locale}.md`), [dir, locale])
// load the markdown
const { frontmatter, MDX } = useDynamicMdx(loader)
@ -28,14 +28,7 @@ const BlogPage = ({ locale, slug, page }) => {
title={frontmatter.title}
layout={(props) => <PostLayout {...props} {...{ slug: page.path.join('/'), frontmatter }} />}
>
<PostArticle
{...{
slug,
frontmatter,
MDX,
page,
}}
/>
<PostArticle {...{ frontmatter, MDX }} />
</PageWrapper>
)
}
@ -51,19 +44,19 @@ const BlogPage = ({ locale, slug, page }) => {
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
*/
export async function getStaticProps({ params, locale }) {
const { slug } = params
const { dir } = params
// if the slug isn't present in the prebuilt posts, return 404
if (!Object.keys(posts).includes(`blog/${slug}`)) return { notFound: true }
// if the dir isn't present in the prebuilt posts, return 404
if (!Object.keys(posts[locale]).includes(`blog/${dir}`)) return { notFound: true }
return {
props: {
slug,
dir,
locale,
...(await serverSideTranslations(locale, namespaces)),
page: {
locale,
path: ['blog', slug],
path: ['blog', dir],
},
},
}

View file

@ -15,11 +15,11 @@ const namespaces = [...layoutNs, ...postNs, ...pageNs]
* when path and locale come from static props (as here)
* or set them manually.
*/
const ShowcasePage = ({ locale, slug, page }) => {
const ShowcasePage = ({ locale, dir, page }) => {
// function to load the correct markdown
const loader = useCallback(
() => import(`orgmarkdown/showcase/${slug}/${locale}.md`),
[slug, locale]
() => import(`orgmarkdown/showcase/${dir}/${locale}.md`),
[dir, locale]
)
const { frontmatter, MDX } = useDynamicMdx(loader)
@ -31,14 +31,7 @@ const ShowcasePage = ({ locale, slug, page }) => {
title={frontmatter.title}
layout={(props) => <PostLayout {...props} {...{ slug: page.path.join('/'), frontmatter }} />}
>
<PostArticle
{...{
slug,
frontmatter,
MDX,
page,
}}
/>
<PostArticle {...{ frontmatter, MDX }} />
</PageWrapper>
)
}
@ -54,19 +47,19 @@ const ShowcasePage = ({ locale, slug, page }) => {
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
*/
export async function getStaticProps({ params, locale }) {
const { slug } = params
const { dir } = params
// if the slug isn't present in the prebuilt posts, return 404
if (!Object.keys(posts).includes(`showcase/${slug}`)) return { notFound: true }
// if the dir isn't present in the prebuilt posts, return 404
if (!Object.keys(posts[locale]).includes(`showcase/${dir}`)) return { notFound: true }
return {
props: {
slug,
dir,
locale,
...(await serverSideTranslations(locale, namespaces)),
page: {
locale,
path: ['showcase', slug],
path: ['showcase', dir],
},
},
}