Skip to content

Commit 6a8cc4c

Browse files
committed
fix ISR -> SSR because images uploaded in Notion were expired 1 hour.
1 parent dc529ea commit 6a8cc4c

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

pages/articles/[slug].tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@ import Layout from '@/components/Layout'
44
import { ArticleProps, Params } from '@/types/types'
55
import { fetchBlocksByPageId, fetchPages } from '@/utils/notion'
66
import { getText } from '@/utils/property'
7-
import { GetStaticPaths, GetStaticProps, NextPage } from 'next'
7+
import { GetServerSideProps, GetStaticPaths, GetStaticProps, NextPage } from 'next'
88
import NotionBlocks from 'notion-block-renderer'
99
import { monokai } from 'react-syntax-highlighter/dist/cjs/styles/hljs';
1010

11-
export const getStaticPaths: GetStaticPaths = async () => {
12-
const { results } = await fetchPages({})
13-
const paths = results.map((page: any) => {
14-
return {
15-
params: {
16-
slug: getText(page.properties.slug.rich_text)
17-
}
18-
}
19-
})
20-
return {
21-
paths: paths,
22-
fallback: 'blocking' // Notionからのデータ取得が完了してからレンダリングするようブロッキングする
23-
}
24-
}
11+
// NOTE: Notion内にあるImageは有効期限が1時間のため、ISRではなくSSRで都度データを取得する
12+
// export const getStaticPaths: GetStaticPaths = async () => {
13+
// const { results } = await fetchPages({})
14+
// const paths = results.map((page: any) => {
15+
// return {
16+
// params: {
17+
// slug: getText(page.properties.slug.rich_text)
18+
// }
19+
// }
20+
// })
21+
// return {
22+
// paths: paths,
23+
// fallback: 'blocking' // Notionからのデータ取得が完了してからレンダリングするようブロッキングする
24+
// }
25+
// }
2526

26-
export const getStaticProps: GetStaticProps = async (ctx) => {
27+
export const getServerSideProps: GetServerSideProps = async (ctx) => {
2728
const { slug } = ctx.params as Params
2829
const { results } = await fetchPages({ slug: slug })
2930
const page = results[0]
3031
const pageId = page.id
3132
const { results: blocks } = await fetchBlocksByPageId(pageId)
3233

3334
return {
34-
props: { page, blocks },
35-
revalidate: 10
35+
props: { page, blocks }
3636
}
3737
}
3838

pages/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ import Layout from '@/components/Layout'
22
import { siteConfig } from '@/site.config'
33
import Card from '@/components/Card'
44
import { fetchPages } from '@/utils/notion'
5-
import { GetStaticProps, NextPage } from 'next'
5+
import { GetServerSideProps, NextPage } from 'next'
66
import { IndexProps } from '@/types/types'
77

8-
export const getStaticProps: GetStaticProps = async () => {
8+
export const getServerSideProps: GetServerSideProps = async () => {
99
const { results } = await fetchPages({})
1010
return {
1111
props: {
1212
pages: results ? results : []
1313
},
14-
revalidate: 10 // ISRを実行するために必要な設定。指定した秒数が経過したらfetchが走り、記事に差分があれば再ビルド
1514
}
1615
}
1716

pages/tags/[tag].tsx

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
11
import Layout from '@/components/Layout'
22
import Card from '@/components/Card'
33
import { fetchPages } from '@/utils/notion'
4-
import { GetStaticPaths, GetStaticProps, NextPage } from 'next'
4+
import { GetServerSideProps, GetStaticPaths, GetStaticProps, NextPage } from 'next'
55
import { IndexProps, Params, TagProps } from '@/types/types'
66
import { getMultiSelect } from '@/utils/property'
77

8-
export const getStaticPaths: GetStaticPaths = async () => {
9-
const { results }: { results: Record<string, any>[] } = await fetchPages({})
8+
// NOTE: Notion内にあるImageは有効期限が1時間のため、ISRではなくSSRで都度データを取得する
9+
// export const getStaticPaths: GetStaticPaths = async () => {
10+
// const { results }: { results: Record<string, any>[] } = await fetchPages({})
1011

11-
const pathSet: Set<string> = new Set()
12-
for(const page of results) {
13-
for (const tag of getMultiSelect(page.properties.tags.multi_select)) {
14-
pathSet.add(tag)
15-
}
16-
}
12+
// const pathSet: Set<string> = new Set()
13+
// for(const page of results) {
14+
// for (const tag of getMultiSelect(page.properties.tags.multi_select)) {
15+
// pathSet.add(tag)
16+
// }
17+
// }
1718

18-
const paths = Array.from(pathSet).map(tag => {
19-
return {
20-
params: { tag }
21-
}
22-
})
19+
// const paths = Array.from(pathSet).map(tag => {
20+
// return {
21+
// params: { tag }
22+
// }
23+
// })
2324

24-
return {
25-
paths: paths,
26-
fallback: 'blocking' // Notionからのデータ取得が完了してからレンダリングするようブロッキングする
27-
}
28-
}
25+
// return {
26+
// paths: paths,
27+
// fallback: 'blocking' // Notionからのデータ取得が完了してからレンダリングするようブロッキングする
28+
// }
29+
// }
2930

30-
export const getStaticProps: GetStaticProps = async (ctx) => {
31+
export const getServerSideProps: GetServerSideProps = async (ctx) => {
3132
const { tag } = ctx.params as Params
3233
const { results } = await fetchPages({ tag })
3334
return {
3435
props: {
3536
pages: results ? results : [],
3637
tag: tag
37-
},
38-
revalidate: 10 // ISRを実行するために必要な設定。指定した秒数が経過したらfetchが走り、記事に差分があれば再ビルド
38+
}
39+
// revalidate: 10 // ISRを実行するために必要な設定。指定した秒数が経過したらfetchが走り、記事に差分があれば再ビルド
3940
}
4041
}
4142

0 commit comments

Comments
 (0)