Skip to content

Commit

Permalink
Merge pull request #95 from JohnsonMao/feature/posts-page
Browse files Browse the repository at this point in the history
✨ add posts page
  • Loading branch information
JohnsonMao authored Sep 29, 2023
2 parents 7ea3b4c + 2bbde4d commit 3061b6b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions i18n/locales/en/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const common = {
home: 'Home',
posts: 'Posts',
about: 'About',
tags: 'Tags',
Expand Down
1 change: 1 addition & 0 deletions i18n/locales/zh-TW/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const common = {
home: '首頁',
posts: '文章',
about: '關於',
tags: '標籤',
Expand Down
6 changes: 5 additions & 1 deletion src/app/[lang]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ async function I18nLayout({
};
const menu: HeaderProps['menu'] = [
{
text: common.posts,
text: common.home,
href: '/',
},
{
text: common.posts,
href: '/posts',
},
];

return (
Expand Down
5 changes: 0 additions & 5 deletions src/app/[lang]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';

import { getDictionary } from '~/i18n';
import Card from '@/components/Card';
Expand All @@ -11,8 +10,6 @@ import type { RootParams } from './layout';
export async function generateMetadata({
params: { lang },
}: RootParams): Promise<Metadata> {
if (!lang) notFound();

const { common } = await getDictionary(lang);

return {
Expand All @@ -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);

Expand Down
34 changes: 34 additions & 0 deletions src/app/[lang]/posts/page.tsx
Original file line number Diff line number Diff line change
@@ -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<Metadata> {
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 (
<Container as="main">
<p className="my-12 text-center text-3xl dark:text-white">
{metadata.title}
</p>
<List Item={Card} items={posts} />
</Container>
);
}

export default RootPage;

0 comments on commit 3061b6b

Please sign in to comment.