|
| 1 | + |
| 2 | + |
| 3 | +import style from '@/css/components/article.module.css'; |
| 4 | +import path from "path"; |
| 5 | +import Article from '../../components/Article'; |
| 6 | +import { getAllDocPaths2 } from '../../blog/[...slug]/getAllDocPaths'; |
| 7 | + |
| 8 | + |
| 9 | +type Params = { |
| 10 | + slug: string[] |
| 11 | +} |
| 12 | +export async function generateStaticParams(): Promise<Params[]>{ |
| 13 | + const folderDir = path.join(process.cwd(), `src/content/blog`); |
| 14 | + const paths =await getAllDocPaths2(folderDir); |
| 15 | + |
| 16 | + const result = paths.map( |
| 17 | + (pathArray: any ) => ({slug: pathArray})); |
| 18 | + console.log(result); |
| 19 | + if(!result || result.length===0){ |
| 20 | + return [{slug: ['not-found']}]; |
| 21 | + } |
| 22 | + return result |
| 23 | +} |
| 24 | +export default async function BlogPage( |
| 25 | + props: any |
| 26 | +) { |
| 27 | + |
| 28 | + try{ |
| 29 | + //join slug array with '/' |
| 30 | + const params = props.params; |
| 31 | + const {slug: slugArray, lang: lang} = await params; |
| 32 | + const decodeURISlugArray = slugArray.map( |
| 33 | + (segment: any)=> (decodeURIComponent(segment)) |
| 34 | + ) |
| 35 | + const slugPath = decodeURISlugArray.join('/') |
| 36 | + const {default: Post, metadata} = await import(`@/content/blog/${slugPath}.mdx`) |
| 37 | + if (lang==='en') { |
| 38 | + const {default: PostEn, metadata} = await import(`@/content/blogen/${slugPath}.mdx`) |
| 39 | + return ( |
| 40 | + <article className={style.article}> |
| 41 | + <PostEn/> |
| 42 | + </article> |
| 43 | + ) |
| 44 | + } |
| 45 | + return (<article className={style.article}> |
| 46 | + <Post/> |
| 47 | + </article>) |
| 48 | + } |
| 49 | + catch(error){ |
| 50 | + console.error('Error loading this blog post') |
| 51 | + return ( |
| 52 | + <div className=""> |
| 53 | + <h1 className="">Error</h1> |
| 54 | + <p className="">Sorry, there was an error loading this blog post.</p> |
| 55 | + </div> |
| 56 | + ) |
| 57 | + } |
| 58 | +} |
0 commit comments