Skip to content

Commit 357becb

Browse files
committed
[update] Next.jsのバージョンを13から15に
・Next.jsのバージョンを13から15にアップデート ・各パッケージのアップデート対応(cheerio, date-fns) ・CDN-Cache-Controlを指定 ・canonical,openGraph.titleを設定
1 parent 7cbcc55 commit 357becb

File tree

17 files changed

+2547
-3917
lines changed

17 files changed

+2547
-3917
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"typescript.enablePromptUseWorkspaceTsdk": true,
44
"editor.defaultFormatter": "esbenp.prettier-vscode",
55
"editor.codeActionsOnSave": {
6-
"source.fixAll.eslint": true
6+
"source.fixAll.eslint": "explicit"
77
},
88
"editor.formatOnSave": true
99
}

app/_libs/utils.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
import { format } from 'date-fns';
2-
import { utcToZonedTime } from 'date-fns-tz';
3-
import cheerio from 'cheerio';
1+
import { formatInTimeZone } from 'date-fns-tz';
2+
import { load } from 'cheerio';
43
import hljs from 'highlight.js';
54
import 'highlight.js/styles/hybrid.css';
65

76
export const formatDate = (date: string) => {
8-
const utcDate = new Date(date);
9-
const jstDate = utcToZonedTime(utcDate, 'Asia/Tokyo');
10-
return format(jstDate, 'yyyy/MM/dd');
7+
return formatInTimeZone(new Date(date), 'Asia/Tokyo', 'yyyy/MM/dd');
118
};
129

1310
export const formatRichText = (richText: string) => {
14-
const $ = cheerio.load(richText);
11+
const $ = load(richText);
1512
$('pre code').each((_, elm) => {
1613
const lang = $(elm).attr('class');
1714
const res = lang

app/api/submit-contact/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NextRequest, NextResponse } from 'next/server';
1+
import { NextRequest, NextResponse } from "next/server";
22

33
function validateEmail(email: string) {
44
const pattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

app/business/layout.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import Sheet from '@/app/_components/Sheet';
33

44
export const metadata = {
55
title: '事業内容|シンプルなコーポレートサイト',
6+
openGraph: {
7+
title: '事業内容|シンプルなコーポレートサイト',
8+
},
9+
alternates: {
10+
canonical: '/business',
11+
},
612
};
713

814
type Props = {

app/business/page.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import styles from './page.module.css';
44
import ButtonLink from '@/app/_components/ButtonLink';
55

66
type Props = {
7-
searchParams: {
7+
searchParams: Promise<{
88
dk: string;
9-
};
9+
}>;
1010
};
1111

12-
export const revalidate = 60;
13-
14-
export default async function Page({ searchParams }: Props) {
12+
export default async function Page(props: Props) {
13+
const searchParams = await props.searchParams;
1514
const data = await getBusinessList({
1615
draftKey: searchParams.dk,
1716
});

app/contact/layout.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import Sheet from '@/app/_components/Sheet';
33

44
export const metadata = {
55
title: 'コンタクト|シンプルなコーポレートサイト',
6+
openGraph: {
7+
title: 'コンタクト|シンプルなコーポレートサイト',
8+
},
9+
alternates: {
10+
canonical: '/contact',
11+
},
612
};
713

814
type Props = {

app/layout.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import Header from '@/app/_components/Header';
66
import './globals.css';
77
import styles from './layout.module.css';
88

9-
export const revalidate = 60;
10-
119
export async function generateMetadata(): Promise<Metadata> {
1210
const data = await getMeta();
1311
if (!data) {

app/members/layout.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import Sheet from '@/app/_components/Sheet';
33

44
export const metadata = {
55
title: 'メンバー|シンプルなコーポレートサイト',
6+
openGraph: {
7+
title: 'メンバー|シンプルなコーポレートサイト',
8+
},
9+
alternates: {
10+
canonical: '/members',
11+
},
612
};
713

814
type Props = {

app/members/page.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import styles from './page.module.css';
44
import ButtonLink from '@/app/_components/ButtonLink';
55

66
type Props = {
7-
searchParams: {
7+
searchParams: Promise<{
88
dk: string;
9-
};
9+
}>;
1010
};
1111

12-
export const revalidate = 60;
13-
14-
export default async function Page({ searchParams }: Props) {
12+
export default async function Page(props: Props) {
13+
const searchParams = await props.searchParams;
1514
const data = await getMembersList({
1615
draftKey: searchParams.dk,
1716
});

app/news/[slug]/page.tsx

+13-8
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import styles from './page.module.css';
55
import ButtonLink from '@/app/_components/ButtonLink';
66

77
type Props = {
8-
params: {
8+
params: Promise<{
99
slug: string;
10-
};
11-
searchParams: {
10+
}>;
11+
searchParams: Promise<{
1212
dk: string;
13-
};
13+
}>;
1414
};
1515

16-
export const revalidate = 60;
17-
18-
export async function generateMetadata({ params, searchParams }: Props): Promise<Metadata> {
16+
export async function generateMetadata(props: Props): Promise<Metadata> {
17+
const searchParams = await props.searchParams;
18+
const params = await props.params;
1919
const data = await getNewsDetail(params.slug, {
2020
draftKey: searchParams.dk,
2121
});
@@ -28,10 +28,15 @@ export async function generateMetadata({ params, searchParams }: Props): Promise
2828
description: data.description,
2929
images: [data?.thumbnail?.url || ''],
3030
},
31+
alternates: {
32+
canonical: `/news/${params.slug}`,
33+
},
3134
};
3235
}
3336

34-
export default async function Page({ params, searchParams }: Props) {
37+
export default async function Page(props: Props) {
38+
const searchParams = await props.searchParams;
39+
const params = await props.params;
3540
const data = await getNewsDetail(params.slug, {
3641
draftKey: searchParams.dk,
3742
});

app/news/layout.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import Sheet from '@/app/_components/Sheet';
33

44
export const metadata = {
55
title: 'ニュース|シンプルなコーポレートサイト',
6+
openGraph: {
7+
title: 'ニュース|シンプルなコーポレートサイト',
8+
},
9+
alternates: {
10+
canonical: '/news',
11+
},
612
};
713

814
type Props = {

app/news/p/[current]/page.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import Pagination from '@/app/_components/Pagination';
44
import ArticleList from '@/app/_components/NewsList';
55

66
type Props = {
7-
params: {
7+
params: Promise<{
88
current: string;
9-
};
9+
}>;
1010
};
1111

12-
export const revalidate = 60;
13-
14-
export default async function Page({ params }: Props) {
12+
export default async function Page(props: Props) {
13+
const params = await props.params;
1514
const current = parseInt(params.current as string, 10);
1615
const data = await getNewsList({
1716
limit: NEWS_LIST_LIMIT,

app/news/page.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { NEWS_LIST_LIMIT } from '@/app/_constants';
33
import NewsList from '@/app/_components/NewsList';
44
import Pagination from '@/app/_components/Pagination';
55

6-
export const revalidate = 60;
7-
86
export default async function Page() {
97
const data = await getNewsList({
108
limit: NEWS_LIST_LIMIT,

app/page.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import NewsList from '@/app/_components/NewsList';
55
import styles from './page.module.css';
66
import ButtonLink from '@/app/_components/ButtonLink';
77

8-
export const revalidate = 60;
9-
108
export default async function Page() {
119
const data = await getNewsList({
1210
limit: TOP_NEWS_LIMIT,

middleware.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { NextRequest, NextResponse } from 'next/server';
2+
3+
const cachePolicies = {
4+
noCache: 'no-store, must-revalidate',
5+
publicIsr: 'public, s-maxage=60, stale-while-revalidate=300',
6+
};
7+
8+
export function middleware(req: NextRequest) {
9+
const searchParams = req.nextUrl.searchParams;
10+
const cachePolicy = searchParams.has('dk') ? cachePolicies.noCache : cachePolicies.publicIsr;
11+
12+
const response = NextResponse.next();
13+
14+
response.headers.set('CDN-Cache-Control', cachePolicy);
15+
16+
return response;
17+
}
18+
19+
export const config = {
20+
matcher: ['/news/:path*', '/business', '/members'],
21+
};

0 commit comments

Comments
 (0)