From 2bbde4d23b3fb816960e7b308f1257db64d6cafd Mon Sep 17 00:00:00 2001 From: Johnson Mao Date: Fri, 29 Sep 2023 20:30:44 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20posts=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- i18n/locales/en/common.ts | 1 + i18n/locales/zh-TW/common.ts | 1 + src/app/[lang]/layout.tsx | 6 +++++- src/app/[lang]/page.tsx | 5 ----- src/app/[lang]/posts/page.tsx | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 src/app/[lang]/posts/page.tsx diff --git a/i18n/locales/en/common.ts b/i18n/locales/en/common.ts index 4ba7121d..532deca2 100644 --- a/i18n/locales/en/common.ts +++ b/i18n/locales/en/common.ts @@ -1,4 +1,5 @@ const common = { + home: 'Home', posts: 'Posts', about: 'About', tags: 'Tags', diff --git a/i18n/locales/zh-TW/common.ts b/i18n/locales/zh-TW/common.ts index 5a329a04..0554f8f8 100644 --- a/i18n/locales/zh-TW/common.ts +++ b/i18n/locales/zh-TW/common.ts @@ -1,4 +1,5 @@ const common = { + home: '首頁', posts: '文章', about: '關於', tags: '標籤', diff --git a/src/app/[lang]/layout.tsx b/src/app/[lang]/layout.tsx index 0d756525..c002735d 100644 --- a/src/app/[lang]/layout.tsx +++ b/src/app/[lang]/layout.tsx @@ -44,9 +44,13 @@ async function I18nLayout({ }; const menu: HeaderProps['menu'] = [ { - text: common.posts, + text: common.home, href: '/', }, + { + text: common.posts, + href: '/posts', + }, ]; return ( diff --git a/src/app/[lang]/page.tsx b/src/app/[lang]/page.tsx index 86e423be..f6c48fad 100644 --- a/src/app/[lang]/page.tsx +++ b/src/app/[lang]/page.tsx @@ -1,5 +1,4 @@ import type { Metadata } from 'next'; -import { notFound } from 'next/navigation'; import { getDictionary } from '~/i18n'; import Card from '@/components/Card'; @@ -11,8 +10,6 @@ import type { RootParams } from './layout'; export async function generateMetadata({ params: { lang }, }: RootParams): Promise { - if (!lang) notFound(); - const { common } = await getDictionary(lang); return { @@ -21,8 +18,6 @@ export async function generateMetadata({ } async function RootPage({ params: { lang } }: RootParams) { - if (!lang) notFound(); - const posts = await getAllDataFrontmatter('posts'); const { metadata } = await getDictionary(lang); diff --git a/src/app/[lang]/posts/page.tsx b/src/app/[lang]/posts/page.tsx new file mode 100644 index 00000000..a8ecceee --- /dev/null +++ b/src/app/[lang]/posts/page.tsx @@ -0,0 +1,34 @@ +import type { Metadata } from 'next'; + +import { getDictionary } from '~/i18n'; +import Card from '@/components/Card'; +import Container from '@/components/Container'; +import List from '@/components/List'; +import { getAllDataFrontmatter } from '@/utils/mdx'; +import type { RootParams } from '../layout'; + +export async function generateMetadata({ + params: { lang }, +}: RootParams): Promise { + const { common } = await getDictionary(lang); + + return { + title: common.posts, + }; +} + +async function RootPage({ params: { lang } }: RootParams) { + const posts = await getAllDataFrontmatter('posts'); + const { metadata } = await getDictionary(lang); + + return ( + +

+ {metadata.title} +

+ +
+ ); +} + +export default RootPage;