Skip to content

Commit

Permalink
Fix/revalidate (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
WakuwakuP authored May 24, 2024
2 parents e4480e5 + 56fe11d commit 4daf223
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/app/api/revalidate/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable no-console */
import { revalidatePath } from 'next/cache'

export const revalidate = 0

export async function POST(request: Request) {
if (request.body === null) return new Response(null, { status: 400 })

Expand All @@ -13,19 +15,17 @@ export async function POST(request: Request) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
console.log(`revalidate: /content/detail/${data.id}`)

if (data.contents.old?.status[0] !== data.contents.new?.status[0]) {
revalidatePath('/')
revalidatePath('/content/latest/')
revalidatePath('/content/latest/[page]')
revalidatePath('/content/category/[categoryId]/')
revalidatePath('/content/category/[categoryId]/[page]')
revalidatePath('/feed')

console.log('revalidate: /')
console.log('revalidate: /feed')
console.log('revalidate: /content/latest/*')
console.log('revalidate: /content/category/*')
}
revalidatePath('/')
revalidatePath('/feed')
revalidatePath('/content/latest/page', 'page')
revalidatePath('/content/latest/[page]/page', 'page')
revalidatePath('/content/category/[categoryId]/page', 'page')
revalidatePath('/content/category/[categoryId]/[page]/page', 'page')

console.log('revalidate: /')
console.log('revalidate: /feed')
console.log('revalidate: /content/latest/*')
console.log('revalidate: /content/category/*')

return new Response(null, { status: 200 })
}
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const globalFont = M_PLUS_1p({
display: 'swap',
})

export const revalidate = 600

export const metadata: Metadata = {
title: { default: `Home | ${SITE_NAME}`, template: `%s | ${SITE_NAME}` },
description: SITE_DESCRIPTION,
Expand Down
2 changes: 2 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Home } from 'components/templates'
import { client } from 'libs/client'

export const revalidate = 600

export default async function HomePage() {
const contents = (
await client.get({
Expand Down

0 comments on commit 4daf223

Please sign in to comment.