-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrate into Next.js App Router (#353)
* Migrate into app router * Update tsconfig * Configure export * Fix lint config * Move generateStaticParams * Fix to return correct data * Add missing peer dependencies * Remove unused function * Remove wrong peer * Remove needless stylelint plugin * Fix resolving conflict * Fix title * Remove passHref * Wrap GoogleAnalytics with Suspense
- Loading branch information
1 parent
4219ed8
commit ec340d6
Showing
66 changed files
with
512 additions
and
531 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,17 @@ | ||
module.exports = { | ||
extends: ["next/core-web-vitals", "prettier"], | ||
plugins: ["chakra-ui"], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: true, | ||
tsconfigRootDir: __dirname, | ||
}, | ||
rules: { | ||
"sort-imports": "error", | ||
"@next/next/no-img-element": "off", | ||
"chakra-ui/props-order": "error", | ||
"chakra-ui/props-shorthand": "error", | ||
"chakra-ui/require-specific-component": "error", | ||
}, | ||
ignorePatterns: [".eslintrc.js"], | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @ts-check | ||
|
||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = { | ||
output: "export", | ||
}; | ||
|
||
module.exports = nextConfig; |
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,20 @@ | ||
import { BlogInfo, BlogInfos, getAllBlogInfos, getBlogFromId } from "../../lib/blog-fetch"; | ||
import { Metadata } from "next"; | ||
import { Post } from "./post"; | ||
|
||
export async function generateMetadata({ params }: { params: BlogInfo }): Promise<Metadata> { | ||
const { title } = await getBlogFromId(params.id); | ||
return { title: `ブログ - ${title}` }; | ||
} | ||
|
||
export async function generateStaticParams(): Promise<BlogInfos> { | ||
return getAllBlogInfos(); | ||
} | ||
|
||
export default async function Page({ params }: { params?: BlogInfo }) { | ||
if (params == null) { | ||
throw new Error("invalid params"); | ||
} | ||
const post = await getBlogFromId(params.id); | ||
return <Post post={post} />; | ||
} |
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,50 @@ | ||
"use client"; | ||
import { | ||
Avatar, | ||
Button, | ||
Flex, | ||
HStack, | ||
Heading, | ||
Link, | ||
SimpleGrid, | ||
Spacer, | ||
VStack, | ||
} from "@chakra-ui/react"; | ||
import { DateString } from "../components/date"; | ||
import { Metadata } from "../lib/blog-fetch"; | ||
import NextLink from "next/link"; | ||
import { Metadata as NextMetadata } from "next"; | ||
import type { NextPage } from "next"; | ||
|
||
export const metadata: NextMetadata = { | ||
title: "限界開発鯖 - ブログ", | ||
}; | ||
|
||
const BlogCard = ({ id, title, date, author, authorId }: Metadata): JSX.Element => ( | ||
<HStack borderColor="shadowed" borderRightWidth="1px" borderBottomWidth="2px"> | ||
<Avatar as={NextLink} flex="0 0 sm" href={`/blog/${id}`} name={title} /> | ||
<VStack alignItems="self-start" flex="1 1" p={2} spacing="0.5"> | ||
<NextLink href={`/blog/${id}`}> | ||
<Heading as="h3" fontSize="lg"> | ||
{title} | ||
</Heading> | ||
</NextLink> | ||
<Flex align="self-end" wrap="wrap" gap={2} w="100%"> | ||
<Link href={`https://github.com/${authorId}`}>{author}</Link> | ||
<DateString dateString={date} /> | ||
<Spacer /> | ||
<Button as={NextLink} href={`/blog/${id}`} size="sm"> | ||
記事を読む → | ||
</Button> | ||
</Flex> | ||
</VStack> | ||
</HStack> | ||
); | ||
|
||
export const Blog: NextPage<{ blogs: Metadata[] }> = ({ blogs }) => ( | ||
<SimpleGrid gap={4} columns={1}> | ||
{blogs.map((blog) => ( | ||
<BlogCard key={blog.id} {...blog} /> | ||
))} | ||
</SimpleGrid> | ||
); |
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,7 @@ | ||
import { Blog } from "./blog"; | ||
import { getSortedBlogMetadata } from "../lib/blog-fetch"; | ||
|
||
export default async function Page() { | ||
const blogs = await getSortedBlogMetadata(); | ||
return <Blog blogs={blogs} />; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/components/date.test.tsx → src/app/components/date.test.tsx
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/components/footer.test.tsx → src/app/components/footer.test.tsx
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use client"; | ||
|
||
import { usePathname, useSearchParams } from "next/navigation"; | ||
import Script from "next/script"; | ||
import { useEffect } from "react"; | ||
|
||
export const GOOGLE_ANALYTICS_ID = process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_ID ?? ""; | ||
|
||
const notifyShowingPage = (url: string): void => { | ||
( | ||
window as unknown as { gtag(event: "config", id: string, options: { page_path: string }): void } | ||
).gtag("config", GOOGLE_ANALYTICS_ID, { | ||
page_path: url, | ||
}); | ||
}; | ||
|
||
export const GoogleAnalytics = () => { | ||
const pathname = usePathname(); | ||
const searchParams = useSearchParams(); | ||
useEffect(() => { | ||
notifyShowingPage(`${pathname}?${searchParams}`); | ||
}, [pathname, searchParams]); | ||
return ( | ||
<> | ||
<Script | ||
strategy="afterInteractive" | ||
src={`https://www.googletagmanager.com/gtag/js?id=${GOOGLE_ANALYTICS_ID}`} | ||
/> | ||
<Script strategy="afterInteractive" id="send-ga"> | ||
{` | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag() { | ||
dataLayer.push(arguments); | ||
} | ||
gtag("js", new Date()); | ||
gtag("config", "${GOOGLE_ANALYTICS_ID}", { | ||
page_path: window.location.pathname, | ||
}); | ||
`} | ||
</Script> | ||
</> | ||
); | ||
}; |
2 changes: 1 addition & 1 deletion
2
src/components/header.test.tsx → src/app/components/header.test.tsx
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,18 @@ | ||
import { Avatar, Center, Flex, Heading } from "@chakra-ui/react"; | ||
import NextLink from "next/link"; | ||
|
||
export const Header = (): JSX.Element => ( | ||
<Center as="header" w="100%" p={4} borderColor="shadowed" borderBottomWidth="2px"> | ||
<Flex as={NextLink} align="center" href="/"> | ||
<Avatar | ||
w={8} | ||
h={8} | ||
mr={2} | ||
borderRadius="37%" | ||
name="Approversロゴ" | ||
src="/android-chrome-192x192.png" | ||
/> | ||
<Heading as="span">Approvers</Heading> | ||
</Flex> | ||
</Center> | ||
); |
2 changes: 1 addition & 1 deletion
2
src/components/navigation.test.tsx → src/app/components/navigation.test.tsx
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
2 changes: 1 addition & 1 deletion
2
src/components/prev-next-link.test.tsx → src/app/components/prev-next-link.test.tsx
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.