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

✨ add posts page #95

Merged
merged 1 commit into from
Sep 29, 2023
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
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;
Loading