From e138e04ed99dcbac3a85693710eb5f5c46fad7bc Mon Sep 17 00:00:00 2001 From: Johnson Mao Date: Sun, 25 Feb 2024 17:43:22 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=90=20modify=20i18n=20metadata=20and?= =?UTF-8?q?=20refactor=20architectural?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/i18n/locales/en.json | 9 +++++---- data/i18n/locales/zh.json | 9 +++++---- data/metadata.ts | 5 +++-- src/app/[lang]/{ => (home)}/Article.tsx | 0 src/app/[lang]/{ => (home)}/page.tsx | 2 +- src/app/[lang]/layout.tsx | 6 +++--- src/app/[lang]/posts/InfiniteList.tsx | 2 +- tests/app/[lang]/card.test.tsx | 2 +- tests/app/[lang]/page.test.tsx | 2 +- 9 files changed, 20 insertions(+), 17 deletions(-) rename src/app/[lang]/{ => (home)}/Article.tsx (100%) rename src/app/[lang]/{ => (home)}/page.tsx (96%) diff --git a/data/i18n/locales/en.json b/data/i18n/locales/en.json index 813ee06..d35e5e0 100644 --- a/data/i18n/locales/en.json +++ b/data/i18n/locales/en.json @@ -1,5 +1,6 @@ { "common": { + "title": "Mao's Corner", "home": "Home", "posts": "Posts", "about": "About", @@ -9,12 +10,12 @@ "morePosts": "More Posts" }, "homePage": { - "title": "Mao's Corner", - "description": "Welcome to Mao's Learning Corner, where I document my study notes. Looking forward to exploring the vast realms of knowledge together with you." + "title": "Hi! I'm Mao, a frontend engineer.", + "description": "Welcome to Mao's Corner, where I document my learning notes." }, "postsPage": { - "title": "Mao's Corner", - "description": "Welcome to Mao's Learning Corner, where I document my study notes. Looking forward to exploring the vast realms of knowledge together with you." + "title": "Welcome to visit my posts!", + "description": "If you have any questions or thoughts about any content, please feel free to share in the comments section. I look forward to engaging in conversation and discussion with you." }, "notFound": { "message": "Sorry we couldn't find this page." diff --git a/data/i18n/locales/zh.json b/data/i18n/locales/zh.json index 69196b2..a24ad7f 100644 --- a/data/i18n/locales/zh.json +++ b/data/i18n/locales/zh.json @@ -1,5 +1,6 @@ { "common": { + "title": "Mao's Corner", "home": "首頁", "posts": "文章", "about": "關於", @@ -9,12 +10,12 @@ "morePosts": "更多文章" }, "homePage": { - "title": "Mao's Corner", - "description": "歡迎來到阿毛的學習角落,這裡記錄著我的學習筆記,期待與你一同探索廣闊的知識領域。" + "title": "嗨!我是阿毛,是一位前端工程師。", + "description": "歡迎來到阿毛的角落,這裡記錄著我學習的筆記。" }, "postsPage": { - "title": "Mao's Corner", - "description": "歡迎來到阿毛的學習角落,這裡記錄著我的學習筆記,期待與你一同探索廣闊的知識領域。" + "title": "歡迎參觀我的文章!", + "description": "如果你對任何內容有疑問或想法,請隨時在留言區分享,我期待與你進行交流和討論。" }, "notFound": { "message": "抱歉!找不到此頁面。" diff --git a/data/metadata.ts b/data/metadata.ts index 459fdb7..371068a 100644 --- a/data/metadata.ts +++ b/data/metadata.ts @@ -13,12 +13,13 @@ export async function createMetadata( locale: Locale = defaultLocale ): Promise { const { - homePage: { title, description }, + common: { title }, + homePage: { description }, } = await getDictionary(locale); return { title: { - template: `%s | ${title}`, + template: `%s - ${title}`, default: title, }, description, diff --git a/src/app/[lang]/Article.tsx b/src/app/[lang]/(home)/Article.tsx similarity index 100% rename from src/app/[lang]/Article.tsx rename to src/app/[lang]/(home)/Article.tsx diff --git a/src/app/[lang]/page.tsx b/src/app/[lang]/(home)/page.tsx similarity index 96% rename from src/app/[lang]/page.tsx rename to src/app/[lang]/(home)/page.tsx index 713e23e..2959bfa 100644 --- a/src/app/[lang]/page.tsx +++ b/src/app/[lang]/(home)/page.tsx @@ -6,7 +6,7 @@ import { H1 } from '@/components/Heading'; import List from '@/components/List'; import { getAllDataFrontmatter } from '@/utils/mdx'; -import type { RootParams } from './layout'; +import type { RootParams } from '../layout'; import Article from './Article'; export async function generateMetadata({ diff --git a/src/app/[lang]/layout.tsx b/src/app/[lang]/layout.tsx index 41ee45b..ebe9043 100644 --- a/src/app/[lang]/layout.tsx +++ b/src/app/[lang]/layout.tsx @@ -19,12 +19,12 @@ export async function generateMetadata({ params: { lang }, }: RootParams): Promise { const { alternates } = await createMetadata(lang); - const { homePage } = await getDictionary(lang); - const { title } = homePage; + const { common } = await getDictionary(lang); + const { title } = common; return { title: { - template: `%s | ${title}`, + template: `%s - ${title}`, default: title, }, alternates: { diff --git a/src/app/[lang]/posts/InfiniteList.tsx b/src/app/[lang]/posts/InfiniteList.tsx index 97c6d3e..3a00fee 100644 --- a/src/app/[lang]/posts/InfiniteList.tsx +++ b/src/app/[lang]/posts/InfiniteList.tsx @@ -5,7 +5,7 @@ import { useSearchParams } from 'next/navigation'; import Link from '@/components/Link'; import List from '@/components/List'; import { clamp } from '@/utils/math'; -import Article from '../Article'; +import Article from '../(home)/Article'; type InfiniteListProps = { items: DataFrontmatter[]; diff --git a/tests/app/[lang]/card.test.tsx b/tests/app/[lang]/card.test.tsx index f83a76e..a79401d 100644 --- a/tests/app/[lang]/card.test.tsx +++ b/tests/app/[lang]/card.test.tsx @@ -1,7 +1,7 @@ import { render, screen } from '@testing-library/react'; import { formatDate } from '@/utils/date'; -import Article from '@/app/[lang]/Article'; +import Article from '@/app/[lang]/(home)/Article'; describe('Article component', () => { it('should render correct element', () => { diff --git a/tests/app/[lang]/page.test.tsx b/tests/app/[lang]/page.test.tsx index 16d3e0b..00d6436 100644 --- a/tests/app/[lang]/page.test.tsx +++ b/tests/app/[lang]/page.test.tsx @@ -1,6 +1,6 @@ import { render, screen } from '@testing-library/react'; import en from '~/data/i18n/locales/en.json'; -import Page, { generateMetadata } from '@/app/[lang]/page'; +import Page, { generateMetadata } from '@/app/[lang]/(home)/page'; jest.mock('@/utils/mdx', () => ({ getAllDataFrontmatter: () => [],