-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-router): switch to app router (#1252)
* feat(app-router): switch to app router - Refactor ant design, sandpack, and nprogress usage. - Remove `next-seo`, use Next.js built-in Metadata API instead. - Remove `<MetaHeader />` component. - Rename metadata files. - Add 'use client' directive to components that use client-side code. * build(ts-paths): change resolve paths to `@/*` * fix(app): migrate 404.tsx to not-found.tsx * fix(app): refactor all pages components * fix(app-tag): normalize tag name before using it as a filter * fix(lib-posts): remove global postsData variable * style: format code
- Loading branch information
1 parent
5392e78
commit 849a184
Showing
177 changed files
with
765 additions
and
921 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { Metadata } from 'next' | ||
import { GithubCard } from '@/components' | ||
import { Layout } from '@/layouts' | ||
import { getBuildTime, getGitHubData, getPostsMeta } from '@/lib' | ||
|
||
export const metadata: Metadata = { | ||
title: 'About Me', | ||
} | ||
|
||
export default async function About() { | ||
const buildTime = getBuildTime() | ||
const { profile, repos } = await getGitHubData() | ||
const postsMeta = await getPostsMeta() | ||
|
||
return ( | ||
<Layout banner="About Me" buildTime={buildTime} posts={postsMeta}> | ||
<GithubCard profile={profile} repos={repos} /> | ||
</Layout> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Metadata } from 'next' | ||
import { BooksGrid } from '@/components' | ||
import { Layout } from '@/layouts' | ||
import { getBuildTime, getPostsMeta } from '@/lib' | ||
|
||
export const metadata: Metadata = { | ||
title: 'Books', | ||
} | ||
|
||
export default async function Books() { | ||
const buildTime = getBuildTime() | ||
const postsMeta = await getPostsMeta() | ||
|
||
return ( | ||
<Layout banner="Books" buildTime={buildTime} posts={postsMeta}> | ||
<BooksGrid /> | ||
</Layout> | ||
) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { AntdRegistry } from '@ant-design/nextjs-registry' | ||
import type { Metadata, Viewport } from 'next' | ||
import type { ReactNode } from 'react' | ||
import ProgressBarProvider from '@/components/ProgressBarProvider' | ||
import SandpackProvider from '@/components/SandpackProvider' | ||
import { getMetadata, getViewport } from '@/config' | ||
|
||
// Keep stylesheets importing order | ||
import '@/styles/globals.css' | ||
import '@/components/Article/Article.css' | ||
import '@/components/Button/Button.css' | ||
import '@/components/Card/Card.css' | ||
import '@/components/Skeleton/Skeleton.css' | ||
|
||
export function generateMetadata(): Metadata { | ||
return getMetadata() | ||
} | ||
|
||
export function generateViewport(): Viewport { | ||
return getViewport() | ||
} | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: ReactNode | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<head> | ||
<SandpackProvider /> | ||
</head> | ||
<body> | ||
<AntdRegistry> | ||
<ProgressBarProvider> | ||
{children} | ||
</ProgressBarProvider> | ||
</AntdRegistry> | ||
</body> | ||
</html> | ||
) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { Metadata } from 'next' | ||
import { NotFoundResult } from '@/components' | ||
import { Layout } from '@/layouts' | ||
import { getBuildTime, getPostsMeta } from '@/lib' | ||
|
||
export const metadata: Metadata = { | ||
title: 'Exploring', | ||
} | ||
|
||
export default async function NotFound() { | ||
const buildTime = getBuildTime() | ||
const postsMeta = await getPostsMeta() | ||
|
||
return ( | ||
<div> | ||
<Layout banner="Exploring" buildTime={buildTime} posts={postsMeta}> | ||
<NotFoundResult /> | ||
</Layout> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { LandingNav, TypingTitle } from '@/components' | ||
import { LandingLayout } from '@/layouts' | ||
|
||
export default function Home() { | ||
return ( | ||
<LandingLayout> | ||
<LandingNav /> | ||
<TypingTitle /> | ||
</LandingLayout> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { ParsedUrlQuery } from 'node:querystring' | ||
import type { Metadata } from 'next' | ||
import { Article } from '@/components' | ||
import { getMetadata } from '@/config' | ||
import { PostLayout } from '@/layouts' | ||
import { getBuildTime, getPostData, getPostsMeta } from '@/lib' | ||
import 'katex/dist/katex.css' | ||
|
||
interface QueryParams extends ParsedUrlQuery { | ||
slug: string | ||
} | ||
|
||
export async function generateStaticParams() { | ||
const postsMeta = await getPostsMeta() | ||
return postsMeta.map(({ slug }) => ({ | ||
slug, | ||
})) | ||
} | ||
|
||
export async function generateMetadata({ params }: { params: QueryParams }): Promise<Metadata> { | ||
const postData = await getPostData(params.slug) | ||
return postData ? getMetadata({ title: postData.title }) : getMetadata() | ||
} | ||
|
||
export default async function Post({ params }: { params: QueryParams }) { | ||
const buildTime = getBuildTime() | ||
const postsMeta = await getPostsMeta() | ||
const postData = await getPostData(params.slug) | ||
|
||
return ( | ||
postData && ( | ||
<PostLayout | ||
buildTime={buildTime} | ||
posts={postsMeta} | ||
> | ||
<Article post={postData} /> | ||
</PostLayout> | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Metadata } from 'next' | ||
import { PostsGrid } from '@/components' | ||
import { Layout } from '@/layouts' | ||
import { getBuildTime, getPostsMeta } from '@/lib' | ||
|
||
export const metadata: Metadata = { | ||
title: 'Posts', | ||
} | ||
|
||
export default async function Posts() { | ||
const buildTime = getBuildTime() | ||
const postsMeta = await getPostsMeta() | ||
|
||
return ( | ||
<Layout banner="Posts" buildTime={buildTime} posts={postsMeta}> | ||
<PostsGrid posts={postsMeta} /> | ||
</Layout> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { ParsedUrlQuery } from 'node:querystring' | ||
import type { Metadata } from 'next' | ||
import { PostsList, TagsCloud } from '@/components' | ||
import { getMetadata } from '@/config' | ||
import { Layout } from '@/layouts' | ||
import { getBuildTime, getPostsMeta, getTagsData } from '@/lib' | ||
|
||
interface QueryParams extends ParsedUrlQuery { | ||
tag: string | ||
} | ||
|
||
export async function generateStaticParams() { | ||
const tagsData = await getTagsData() | ||
return Object.keys(tagsData).map(tag => ({ | ||
tag, | ||
})) | ||
} | ||
|
||
export async function generateMetadata({ params }: { params: QueryParams }): Promise<Metadata> { | ||
return getMetadata({ title: params.tag }) | ||
} | ||
|
||
export default async function Tags({ params }: { params: QueryParams }) { | ||
const buildTime = getBuildTime() | ||
const postsMeta = await getPostsMeta() | ||
const tagsData = await getTagsData() | ||
const activeTag = decodeURI(params.tag) | ||
|
||
const postsMetaByTag = postsMeta.filter( | ||
({ tags }) => tags && tags.includes(activeTag), | ||
) | ||
|
||
return ( | ||
<Layout banner={activeTag} buildTime={buildTime} posts={postsMeta}> | ||
<TagsCloud tags={tagsData} activeTag={activeTag} /> | ||
<PostsList posts={postsMetaByTag} /> | ||
</Layout> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { Metadata } from 'next' | ||
import { PostsList, TagsCloud } from '@/components' | ||
import { Layout } from '@/layouts' | ||
import { getBuildTime, getPostsMeta, getTagsData } from '@/lib' | ||
|
||
export const metadata: Metadata = { | ||
title: 'Tags', | ||
} | ||
|
||
export default async function Tags() { | ||
const buildTime = getBuildTime() | ||
const postsMeta = await getPostsMeta() | ||
const tagsData = await getTagsData() | ||
|
||
return ( | ||
<Layout banner="Tags" buildTime={buildTime} posts={postsMeta}> | ||
<TagsCloud tags={tagsData} /> | ||
<PostsList posts={postsMeta} /> | ||
</Layout> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use client' | ||
|
||
import type { BackTopProps } from 'antd' | ||
import { FloatButton } from 'antd' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.