Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌐 modify i18n metadata and refactor architectural #131

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions data/i18n/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"common": {
"title": "Mao's Corner",
"home": "Home",
"posts": "Posts",
"about": "About",
Expand All @@ -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."
Expand Down
9 changes: 5 additions & 4 deletions data/i18n/locales/zh.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"common": {
"title": "Mao's Corner",
"home": "首頁",
"posts": "文章",
"about": "關於",
Expand All @@ -9,12 +10,12 @@
"morePosts": "更多文章"
},
"homePage": {
"title": "Mao's Corner",
"description": "歡迎來到阿毛的學習角落,這裡記錄著我的學習筆記,期待與你一同探索廣闊的知識領域。"
"title": "嗨!我是阿毛,是一位前端工程師。",
"description": "歡迎來到阿毛的角落,這裡記錄著我學習的筆記。"
},
"postsPage": {
"title": "Mao's Corner",
"description": "歡迎來到阿毛的學習角落,這裡記錄著我的學習筆記,期待與你一同探索廣闊的知識領域。"
"title": "歡迎參觀我的文章!",
"description": "如果你對任何內容有疑問或想法,請隨時在留言區分享,我期待與你進行交流和討論。"
},
"notFound": {
"message": "抱歉!找不到此頁面。"
Expand Down
5 changes: 3 additions & 2 deletions data/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ export async function createMetadata(
locale: Locale = defaultLocale
): Promise<Metadata> {
const {
homePage: { title, description },
common: { title },
homePage: { description },
} = await getDictionary(locale);

return {
title: {
template: `%s | ${title}`,
template: `%s - ${title}`,
default: title,
},
description,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/app/[lang]/page.tsx → src/app/[lang]/(home)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
6 changes: 3 additions & 3 deletions src/app/[lang]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export async function generateMetadata({
params: { lang },
}: RootParams): Promise<Metadata> {
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: {
Expand Down
2 changes: 1 addition & 1 deletion src/app/[lang]/posts/InfiniteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
2 changes: 1 addition & 1 deletion tests/app/[lang]/card.test.tsx
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/app/[lang]/page.test.tsx
Original file line number Diff line number Diff line change
@@ -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: () => [],
Expand Down
Loading