-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from ooooorobo/migrate-app-router
Migrate to app router
- Loading branch information
Showing
23 changed files
with
394 additions
and
399 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
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,16 @@ | ||
import Script from "next/script"; | ||
|
||
export const AnalyticsScript = () => ( | ||
<> | ||
<Script src="https://www.googletagmanager.com/gtag/js?id=G-W8WNQ2WC88" /> | ||
<Script id={"google-analytics"}> | ||
{` | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', 'G-W8WNQ2WC88'); | ||
`} | ||
</Script> | ||
</> | ||
); |
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 @@ | ||
"use client"; | ||
|
||
import React, { ReactNode, useState } from "react"; | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import { MDXProvider } from "@mdx-js/react"; | ||
import ThemeProvider from "@src/utils/context/ThemeProvider"; | ||
import DarkModeProvider from "@src/utils/context/DarkModeContext"; | ||
import components from "@src/components/mdx/MDXComponents"; | ||
import StyledComponentsRegistry from "@src/registry/StyledComponentsRegistry"; | ||
import GlobalStyle from "@src/styles/GlobalStyle"; | ||
|
||
export const Providers = ({ children }: { children: ReactNode }) => { | ||
const [queryClient] = useState( | ||
() => | ||
new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
refetchOnWindowFocus: false, | ||
refetchOnMount: false, | ||
refetchOnReconnect: false, | ||
refetchInterval: false, | ||
}, | ||
}, | ||
}), | ||
); | ||
|
||
return ( | ||
<QueryClientProvider client={queryClient}> | ||
<DarkModeProvider> | ||
<StyledComponentsRegistry> | ||
<ThemeProvider> | ||
<GlobalStyle /> | ||
<MDXProvider components={components}>{children}</MDXProvider> | ||
</ThemeProvider> | ||
</StyledComponentsRegistry> | ||
</DarkModeProvider> | ||
</QueryClientProvider> | ||
); | ||
}; |
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,36 @@ | ||
import { PropsWithChildren } from "react"; | ||
import { Metadata } from "next"; // import "data://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css"; | ||
import Header from "@src/components/Header"; | ||
import { Providers } from "@src/app/Providers"; | ||
import { AnalyticsScript } from "@src/app/AnalyticsScript"; | ||
|
||
export const metadata: Metadata = { | ||
title: { template: "%s | oooooroblog", default: "oooooroblog" }, | ||
description: "웹 프론트엔드 개발 블로그", | ||
icons: { | ||
icon: "/favicon-32x32.png", | ||
shortcut: "/favicon-32x32.png", | ||
apple: "/apple-touch-icon.png", | ||
}, | ||
manifest: "/site.webmanifest", | ||
openGraph: { | ||
type: "website", | ||
url: "https://www.oooooroblog.com", | ||
title: "oooooroblog", | ||
description: "웹 프론트엔드 개발 블로그", | ||
}, | ||
}; | ||
|
||
export default function RootLayout({ children }: PropsWithChildren) { | ||
return ( | ||
<html lang={"ko"}> | ||
<body> | ||
<Providers> | ||
<Header /> | ||
{children} | ||
</Providers> | ||
<AnalyticsScript /> | ||
</body> | ||
</html> | ||
); | ||
} |
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 @@ | ||
"use client"; | ||
import styled from "styled-components"; | ||
import { useEffect } from "react"; | ||
import { getAllPostMeta } from "@src/business/post"; | ||
import PostList from "@src/components/main/PostList"; | ||
import { StorageKey } from "@src/constants/constants"; | ||
import Profile from "@src/components/main/Profile"; | ||
|
||
export default function Page() { | ||
const posts = getAllPostMeta(); | ||
|
||
useEffect(() => { | ||
const scroll = parseInt( | ||
sessionStorage.getItem(StorageKey.MAIN_SCROLL_Y) ?? "0", | ||
); | ||
window.scrollTo({ top: scroll, behavior: "auto" }); | ||
}, []); | ||
|
||
const onClickPost = () => { | ||
sessionStorage.setItem(StorageKey.MAIN_SCROLL_Y, window.scrollY.toString()); | ||
}; | ||
|
||
return ( | ||
<Wrapper> | ||
<Profile /> | ||
<div> | ||
<PostList posts={posts} onClickPost={onClickPost} /> | ||
</div> | ||
</Wrapper> | ||
); | ||
} | ||
|
||
const Wrapper = styled.div` | ||
margin: 2.5rem auto; | ||
max-width: 760px; | ||
padding: 0 1rem; | ||
display: flex; | ||
flex-direction: column; | ||
row-gap: 20px; | ||
`; |
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,18 @@ | ||
import { PropsWithChildren } from "react"; | ||
import { Metadata } from "next"; | ||
import { getPostDetail } from "@src/business/post"; | ||
import { PostPageProps } from "@src/app/posts/[slug]/page"; | ||
|
||
export function generateMetadata({ | ||
params: { slug }, | ||
}: PostPageProps): Metadata { | ||
const { detail: post } = getPostDetail(slug); | ||
return { | ||
title: post.title, | ||
description: post.description, | ||
}; | ||
} | ||
|
||
export default function PostLayout({ children }: PropsWithChildren) { | ||
return <>{children}</>; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { compareDesc } from "date-fns"; | ||
import { allPosts } from "contentlayer/generated"; | ||
import { PostListElement } from "@src/types/post"; | ||
|
||
const getSortedPosts = () => { | ||
return allPosts.sort((a, b) => { | ||
const compareByDate = compareDesc(new Date(a.date), new Date(b.date)); | ||
if (compareByDate !== 0) return compareByDate; | ||
return b.id - a.id; | ||
}); | ||
}; | ||
|
||
export const getAllPostMeta = (): PostListElement[] => { | ||
return getSortedPosts().map( | ||
(meta) => | ||
({ | ||
slug: meta.url, | ||
meta: { | ||
index: meta.id, | ||
title: meta.title, | ||
description: meta.description || "", | ||
postedAt: meta.date, | ||
category: "", | ||
series: "", | ||
tags: [], | ||
keywords: [], | ||
}, | ||
}) satisfies PostListElement, | ||
); | ||
}; | ||
|
||
export const getPostDetail = (slug: string) => { | ||
const sorted = getSortedPosts(); | ||
const postIdx = sorted.findIndex((post) => post._raw.flattenedPath === slug); | ||
return { | ||
postIdx, | ||
detail: sorted[postIdx], | ||
}; | ||
}; | ||
|
||
export const getPostMeta = (idx: number) => { | ||
return getSortedPosts()[idx]; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use client"; | ||
import { useContext } from "react"; | ||
import { DarkModeContext } from "@src/utils/context/DarkModeContext"; | ||
|
||
export const ThemeToggleButton = () => { | ||
const { isDarkMode, toggleDarkMode } = useContext(DarkModeContext); | ||
|
||
return ( | ||
<button onClick={toggleDarkMode}> | ||
{isDarkMode ? ( | ||
<i className="bi bi-moon-fill" /> | ||
) : ( | ||
<i className="bi bi-sun-fill" /> | ||
)} | ||
</button> | ||
); | ||
}; |
Oops, something went wrong.
d8956a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
oooooroblog – ./
oooooroblog.vercel.app
oooooroblog-ooooorobo.vercel.app
oooooroblog-git-main-ooooorobo.vercel.app
www.oooooroblog.com
oooooroblog.com