Skip to content

Commit b5ed2af

Browse files
Merge pull request transitive-bullshit#383 from transitive-bullshit/feature/update-deps
2 parents 238e4bb + 2cbef94 commit b5ed2af

File tree

12 files changed

+3910
-4429
lines changed

12 files changed

+3910
-4429
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ jobs:
66
Build:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
9+
- uses: actions/checkout@v3
1010

11-
- uses: actions/setup-node@v2
11+
- uses: actions/setup-node@v3
1212
with:
1313
node-version: 16
1414
cache: yarn
1515

1616
- run: yarn install --frozen-lockfile
1717
- name: build
18-
# TODO Enable those lines below if you use a Redis cache, you'll also need to configure GitHub Repository Secrets
19-
# env:
20-
# REDIS_HOST: ${{ secrets.REDIS_HOST }}
21-
# REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}
18+
# TODO Enable those lines below if you use a Redis cache, you'll also need to configure GitHub Repository Secrets
19+
# env:
20+
# REDIS_HOST: ${{ secrets.REDIS_HOST }}
21+
# REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}
2222
run: yarn build

lib/config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { parsePageId } from 'notion-utils'
9-
import posthog from 'posthog-js'
9+
import type posthog from 'posthog-js'
1010
import { getEnv, getSiteConfig } from './get-config-value'
1111
import { NavigationLink } from './site-config'
1212
import {
@@ -125,12 +125,15 @@ export const redisNamespace: string | null = getEnv(
125125
export const isServer = typeof window === 'undefined'
126126

127127
export const port = getEnv('PORT', '3000')
128-
export const host = isDev ? `http://localhost:${port}` : `https://${domain}`
128+
export const host = isDev
129+
? `http://localhost:${port}`
130+
: `https://${process.env.VERCEL_URL || domain}`
129131

130132
export const apiBaseUrl = `/api`
131133

132134
export const api = {
133135
searchNotion: `${apiBaseUrl}/search-notion`,
136+
getNotionPageInfo: `${apiBaseUrl}/notion-page-info`,
134137
getSocialImage: `${apiBaseUrl}/social-image`
135138
}
136139

lib/fonts.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,13 @@ export interface PageUrlOverridesInverseMap {
6060
// (this overrides the built-in URL path generation for these pages)
6161
[pageId: string]: string
6262
}
63+
64+
export interface NotionPageInfo {
65+
pageId: string
66+
title: string
67+
image: string
68+
imageObjectPosition: string
69+
author: string
70+
authorImage: string
71+
detail: string
72+
}

package.json

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"repository": "transitive-bullshit/nextjs-notion-starter-kit",
88
"license": "MIT",
99
"engines": {
10-
"node": ">=14.17"
10+
"node": ">=16"
1111
},
1212
"scripts": {
1313
"dev": "next dev",
@@ -29,55 +29,45 @@
2929
"@keyvhq/core": "^1.6.9",
3030
"@keyvhq/redis": "^1.6.10",
3131
"@react-icons/all-files": "^4.1.0",
32+
"@vercel/og": "^0.0.18",
3233
"classnames": "^2.3.1",
3334
"date-fns": "^2.28.0",
3435
"expiry-map": "^2.0.0",
3536
"fathom-client": "^3.4.1",
3637
"got": "^12.0.3",
3738
"isomorphic-unfetch": "^3.1.0",
3839
"lqip-modern": "^1.2.0",
39-
"next": "^12.2.3",
40-
"next-api-og-image": "^2.2.1",
41-
"node-fetch": "^2.6.1",
42-
"notion-client": "^6.12.6",
43-
"notion-types": "^6.12.6",
44-
"notion-utils": "^6.12.6",
40+
"next": "^12.3.1",
41+
"notion-client": "^6.13.11",
42+
"notion-types": "^6.13.4",
43+
"notion-utils": "^6.13.4",
4544
"p-map": "^5.3.0",
4645
"p-memoize": "^6.0.1",
4746
"posthog-js": "^1.20.2",
48-
"react": "^17.0.2",
47+
"react": "^18.2.0",
4948
"react-body-classname": "^1.3.1",
50-
"react-dom": "^17.0.2",
51-
"react-notion-x": "^6.12.7",
49+
"react-dom": "^18.2.0",
50+
"react-notion-x": "^6.15.3",
5251
"react-tweet-embed": "^2.0.0",
5352
"react-use": "^17.3.2",
5453
"rss": "^1.2.2"
5554
},
5655
"devDependencies": {
57-
"@next/bundle-analyzer": "^12.1.0",
58-
"@types/node": "^17.0.23",
59-
"@types/node-fetch": "^3.0.3",
60-
"@types/react": "^17.0.31",
61-
"@typescript-eslint/eslint-plugin": "^5.15.0",
62-
"@typescript-eslint/parser": "^5.15.0",
56+
"@next/bundle-analyzer": "^12.3.1",
57+
"@types/node": "^18.8.5",
58+
"@types/react": "^18.0.21",
59+
"@typescript-eslint/eslint-plugin": "^5.40.0",
60+
"@typescript-eslint/parser": "^5.40.0",
6361
"cross-env": "^7.0.2",
64-
"eslint": "^8.11.0",
62+
"eslint": "^8.25.0",
6563
"eslint-config-prettier": "^8.5.0",
66-
"eslint-plugin-react": "^7.29.4",
67-
"eslint-plugin-react-hooks": "^4.3.0",
64+
"eslint-plugin-react": "^7.31.10",
65+
"eslint-plugin-react-hooks": "^4.6.0",
6866
"npm-run-all": "^4.1.5",
69-
"prettier": "^2.4.1",
70-
"typescript": "^4.4.4"
71-
},
72-
"resolutions": {
73-
"next-api-og-image/chrome-aws-lambda": "6.0.0",
74-
"next-api-og-image/puppeteer-core": "6.0.0"
67+
"prettier": "^2.7.1",
68+
"typescript": "^4.8.4"
7569
},
7670
"overrides": {
77-
"next-api-og-image": {
78-
"chrome-aws-lambda": "6.0.0",
79-
"puppeteer-core": "6.0.0"
80-
},
8171
"cacheable-request": {
8272
"keyv": "npm:@keyvhq/core@~1.6.6"
8373
}

pages/[pageId].tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { resolveNotionPage } from 'lib/resolve-notion-page'
66
import { PageProps, Params } from 'lib/types'
77
import { NotionPage } from 'components'
88

9-
export const getStaticProps: GetStaticProps<PageProps, Params> = async (context) => {
9+
export const getStaticProps: GetStaticProps<PageProps, Params> = async (
10+
context
11+
) => {
1012
const rawPageId = context.params.pageId as string
1113

1214
try {

pages/api/notion-page-info.tsx

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { NextApiRequest, NextApiResponse } from 'next'
2+
3+
import {
4+
getBlockTitle,
5+
getBlockIcon,
6+
getPageProperty,
7+
isUrl,
8+
parsePageId
9+
} from 'notion-utils'
10+
import { PageBlock } from 'notion-types'
11+
12+
import { notion } from 'lib/notion-api'
13+
import { mapImageUrl } from 'lib/map-image-url'
14+
import { NotionPageInfo } from 'lib/types'
15+
import * as libConfig from 'lib/config'
16+
17+
export default async (req: NextApiRequest, res: NextApiResponse) => {
18+
if (req.method !== 'POST') {
19+
return res.status(405).send({ error: 'method not allowed' })
20+
}
21+
22+
const pageId: string = parsePageId(req.body.pageId)
23+
if (!pageId) {
24+
throw new Error('Invalid notion page id')
25+
}
26+
27+
const recordMap = await notion.getPage(pageId)
28+
29+
const keys = Object.keys(recordMap?.block || {})
30+
const block = recordMap?.block?.[keys[0]]?.value
31+
32+
if (!block) {
33+
throw new Error('Invalid recordMap for page')
34+
}
35+
36+
const blockSpaceId = block.space_id
37+
38+
if (
39+
blockSpaceId &&
40+
libConfig.rootNotionSpaceId &&
41+
blockSpaceId !== libConfig.rootNotionSpaceId
42+
) {
43+
return res.status(400).send({
44+
error: `Notion page "${pageId}" belongs to a different workspace.`
45+
})
46+
}
47+
48+
const isBlogPost =
49+
block.type === 'page' && block.parent_table === 'collection'
50+
const title = getBlockTitle(block, recordMap) || libConfig.name
51+
const image = mapImageUrl(
52+
getPageProperty<string>('Social Image', block, recordMap) ||
53+
(block as PageBlock).format?.page_cover ||
54+
libConfig.defaultPageCover,
55+
block
56+
)
57+
58+
const imageCoverPosition =
59+
(block as PageBlock).format?.page_cover_position ??
60+
libConfig.defaultPageCoverPosition
61+
const imageObjectPosition = imageCoverPosition
62+
? `center ${(1 - imageCoverPosition) * 100}%`
63+
: null
64+
65+
const blockIcon = getBlockIcon(block, recordMap)
66+
const authorImage = mapImageUrl(
67+
blockIcon && isUrl(blockIcon) ? blockIcon : libConfig.defaultPageIcon,
68+
block
69+
)
70+
71+
const author =
72+
getPageProperty<string>('Author', block, recordMap) || libConfig.author
73+
74+
// const socialDescription =
75+
// getPageProperty<string>('Description', block, recordMap) ||
76+
// libConfig.description
77+
78+
// const lastUpdatedTime = getPageProperty<number>(
79+
// 'Last Updated',
80+
// block,
81+
// recordMap
82+
// )
83+
const publishedTime = getPageProperty<number>('Published', block, recordMap)
84+
const datePublished = publishedTime ? new Date(publishedTime) : undefined
85+
// const dateUpdated = lastUpdatedTime
86+
// ? new Date(lastUpdatedTime)
87+
// : publishedTime
88+
// ? new Date(publishedTime)
89+
// : undefined
90+
const date =
91+
isBlogPost && datePublished
92+
? `${datePublished.toLocaleString('en-US', {
93+
month: 'long'
94+
})} ${datePublished.getFullYear()}`
95+
: undefined
96+
const detail = date || author || libConfig.domain
97+
98+
const pageInfo: NotionPageInfo = {
99+
pageId,
100+
title,
101+
image,
102+
imageObjectPosition,
103+
author,
104+
authorImage,
105+
detail
106+
}
107+
108+
res.setHeader(
109+
'Cache-Control',
110+
'public, s-maxage=30, max-age=30, stale-while-revalidate=30'
111+
)
112+
res.status(200).json(pageInfo)
113+
}

0 commit comments

Comments
 (0)