Skip to content

Commit

Permalink
Merge pull request #4 from takusan23/nextjs_15
Browse files Browse the repository at this point in the history
Next.js 15 にアップデートしただけ
  • Loading branch information
takusan23 authored Jan 7, 2025
2 parents dd54925 + 61e3e1c commit 65561dd
Show file tree
Hide file tree
Showing 12 changed files with 579 additions and 150 deletions.
8 changes: 5 additions & 3 deletions app/pages/[page]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import "../../../styles/css/content.css"

/** 動的ルーティング */
type PageProps = {
params: { page: string }
params: Promise<{ page: string }>
}

/** head に値を入れる */
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
export async function generateMetadata(props: PageProps): Promise<Metadata> {
const params = await props.params;
const markdownData = await ContentFolderManager.getPageItem(params.page)
const ogpTitle = `${markdownData.title} - ${EnvironmentTool.SITE_NAME}`
const ogpUrl = `${EnvironmentTool.BASE_URL}${markdownData.link}`
Expand All @@ -36,7 +37,8 @@ export async function generateMetadata({ params }: PageProps): Promise<Metadata>
}

/** 固定ページの記事本文 */
export default async function PageDetailPage({ params }: PageProps) {
export default async function PageDetailPage(props: PageProps) {
const params = await props.params;
// サーバー側でロードする
const markdownData = await ContentFolderManager.getPageItem(params.page)

Expand Down
5 changes: 3 additions & 2 deletions app/posts/[blog]/opengraph-image.png/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import FileReadTool from "../../../../src/FileReadTool"

/** 動的ルーティング */
type PageProps = {
params: { blog: string }
params: Promise<{ blog: string }>
}

/**
Expand All @@ -17,7 +17,8 @@ type PageProps = {
* 使える CSS は以下参照:
* https://github.com/vercel/satori
*/
export async function GET(_: Request, { params }: PageProps) {
export async function GET(_: Request, props: PageProps) {
const params = await props.params;
// 記事を取得
const markdownData = await ContentFolderManager.getBlogItem(params.blog)

Expand Down
8 changes: 5 additions & 3 deletions app/posts/[blog]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import "../../../styles/css/content.css"

/** 動的ルーティング */
type PageProps = {
params: { blog: string }
params: Promise<{ blog: string }>
}

/** head に値を入れる */
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
export async function generateMetadata(props: PageProps): Promise<Metadata> {
const params = await props.params;
const markdownData = await ContentFolderManager.getBlogItem(params.blog)
const ogpTitle = `${markdownData.title} - ${EnvironmentTool.SITE_NAME}`
const ogpUrl = `${EnvironmentTool.BASE_URL}${markdownData.link}`
Expand All @@ -41,7 +42,8 @@ export async function generateMetadata({ params }: PageProps): Promise<Metadata>
* 記事本文。
* 反映されない場合はスーパーリロードしてみてください。
*/
export default async function BlogDetailPage({ params }: PageProps) {
export default async function BlogDetailPage(props: PageProps) {
const params = await props.params;
// サーバー側でロードする
const markdownData = await ContentFolderManager.getBlogItem(params.blog)

Expand Down
5 changes: 3 additions & 2 deletions app/posts/page/[page]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const BLOG_SIZE_LIMIT = 10

/** 動的ルーティング */
type PageProps = {
params: { page: string }
params: Promise<{ page: string }>
}

/** head に値を入れる */
Expand All @@ -20,7 +20,8 @@ export const metadata: Metadata = {
}

/** 記事一覧ページ */
export default async function BlogListPage({ params }: PageProps) {
export default async function BlogListPage(props: PageProps) {
const params = await props.params;
// posts/page/<ここ> を取得
const pageId = Number(params.page)
// 記事一覧を取得する。async なので待つ。-1してるのは1ページ目はskip:0にしたいため
Expand Down
8 changes: 5 additions & 3 deletions app/posts/tag/[tag]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import BlogListItem from "../../../../components/BlogListItem"

/** 動的ルーティング */
type PageProps = {
params: { tag: string }
params: Promise<{ tag: string }>
}

/** head に値を入れる */
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
export async function generateMetadata(props: PageProps): Promise<Metadata> {
const params = await props.params;
const unEscapeText = decodeURIComponent(params.tag)
return {
title: `タグ名:${unEscapeText} - ${EnvironmentTool.SITE_NAME}`,
Expand All @@ -22,7 +23,8 @@ export async function generateMetadata({ params }: PageProps): Promise<Metadata>
}

/** タグがついてる記事一覧ページ */
export default async function TagListPage({ params }: PageProps) {
export default async function TagListPage(props: PageProps) {
const params = await props.params;
// パーセントエンコーディングされているため戻す
const unEscapeText = decodeURIComponent(params.tag)
// ページネーションは後で
Expand Down
4 changes: 4 additions & 0 deletions app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { MetadataRoute } from "next";
import EnvironmentTool from "../src/EnvironmentTool";
import ContentFolderManager from "../src/ContentFolderManager";

// 静的書き出しなので指定する必要がないはずだが、Next.js 15 から無いとエラーになってしまう
// https://github.com/vercel/next.js/issues/68667
export const dynamic = "force-static"

/**
* サイトマップを生成する。Next.js 単体で作れるようになった。
* Trailing Slash が有効なので最後にスラッシュ入れました。
Expand Down
16 changes: 7 additions & 9 deletions components/TagChipGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ export default function TagChipGroup({ tagList }: TagChipGroupProps) {
<div className="flex flex-row flex-wrap gap-2">
{
tagList.map(tagName => (
<>
<NextLinkButton
size="small"
key={tagName}
href={`/posts/tag/${tagName}/`}
startIcon={<SellIcon />}
text={tagName}
/>
</>
<NextLinkButton
size="small"
key={tagName}
href={`/posts/tag/${tagName}/`}
startIcon={<SellIcon />}
text={tagName}
/>
))
}
</div>
Expand Down
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
8 changes: 8 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,13 @@ module.exports = {
},
experimental: {
scrollRestoration: true,
turbo: {
rules: {
'*.svg': {
loaders: ['@svgr/webpack'],
as: '*.js',
},
},
}
}
}
Loading

0 comments on commit 65561dd

Please sign in to comment.