Skip to content

Commit 1933d65

Browse files
Merge pull request transitive-bullshit#273 from transitive-bullshit/feature/rss
2 parents facc4e3 + 69b631e commit 1933d65

14 files changed

+162
-114
lines changed

lib/config.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { NavigationLink } from './site-config'
1212
import {
1313
PageUrlOverridesInverseMap,
1414
PageUrlOverridesMap,
15-
NavigationStyle
15+
NavigationStyle,
16+
Site
1617
} from './types'
1718

1819
export const rootNotionPageId: string = parsePageId(
@@ -132,6 +133,14 @@ export const api = {
132133

133134
// ----------------------------------------------------------------------------
134135

136+
export const site: Site = {
137+
domain,
138+
name,
139+
rootNotionPageId,
140+
rootNotionSpaceId,
141+
description
142+
}
143+
135144
export const fathomId = isDev ? null : process.env.NEXT_PUBLIC_FATHOM_ID
136145
export const fathomConfig = fathomId
137146
? {

lib/get-site-for-domain.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

lib/get-all-pages.ts renamed to lib/get-site-map.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
import pMemoize from 'p-memoize'
22
import { getAllPagesInSpace, uuidToId } from 'notion-utils'
33

4-
import * as types from './types'
54
import { includeNotionIdInUrls } from './config'
65
import { notion } from './notion-api'
76
import { getCanonicalPageId } from './get-canonical-page-id'
7+
import * as config from './config'
8+
import * as types from './types'
89

910
const uuid = !!includeNotionIdInUrls
1011

11-
export const getAllPages = pMemoize(getAllPagesImpl, {
12+
export async function getSiteMap(): Promise<types.SiteMap> {
13+
const partialSiteMap = await getAllPages(
14+
config.rootNotionPageId,
15+
config.rootNotionSpaceId
16+
)
17+
18+
return {
19+
site: config.site,
20+
...partialSiteMap
21+
} as types.SiteMap
22+
}
23+
24+
const getAllPages = pMemoize(getAllPagesImpl, {
1225
cacheKey: (...args) => JSON.stringify(args)
1326
})
1427

15-
export async function getAllPagesImpl(
28+
async function getAllPagesImpl(
1629
rootNotionPageId: string,
1730
rootNotionSpaceId: string
1831
): Promise<Partial<types.SiteMap>> {

lib/get-site-maps.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

lib/get-sites.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

lib/resolve-notion-page.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ import { parsePageId } from 'notion-utils'
22
import { ExtendedRecordMap } from 'notion-types'
33

44
import * as acl from './acl'
5-
import * as types from './types'
6-
import { pageUrlOverrides, pageUrlAdditions, environment } from './config'
5+
import { pageUrlOverrides, pageUrlAdditions, environment, site } from './config'
76
import { db } from './db'
87
import { getPage } from './notion'
9-
import { getSiteMaps } from './get-site-maps'
10-
import { getSiteForDomain } from './get-site-for-domain'
8+
import { getSiteMap } from './get-site-map'
119

1210
export async function resolveNotionPage(domain: string, rawPageId?: string) {
13-
let site: types.Site
1411
let pageId: string
1512
let recordMap: ExtendedRecordMap
1613

@@ -47,27 +44,19 @@ export async function resolveNotionPage(domain: string, rawPageId?: string) {
4744
}
4845

4946
if (pageId) {
50-
;[site, recordMap] = await Promise.all([
51-
getSiteForDomain(domain),
52-
getPage(pageId)
53-
])
47+
recordMap = await getPage(pageId)
5448
} else {
5549
// handle mapping of user-friendly canonical page paths to Notion page IDs
5650
// e.g., /developer-x-entrepreneur versus /71201624b204481f862630ea25ce62fe
57-
const siteMaps = await getSiteMaps()
58-
const siteMap = siteMaps[0]
51+
const siteMap = await getSiteMap()
5952
pageId = siteMap?.canonicalPageMap[rawPageId]
6053

6154
if (pageId) {
6255
// TODO: we're not re-using the page recordMap from siteMaps because it is
6356
// cached aggressively
64-
// site = await getSiteForDomain(domain)
6557
// recordMap = siteMap.pageMap[pageId]
6658

67-
;[site, recordMap] = await Promise.all([
68-
getSiteForDomain(domain),
69-
getPage(pageId)
70-
])
59+
recordMap = await getPage(pageId)
7160

7261
if (useUriToPageIdCache) {
7362
try {
@@ -91,7 +80,6 @@ export async function resolveNotionPage(domain: string, rawPageId?: string) {
9180
}
9281
}
9382
} else {
94-
site = await getSiteForDomain(domain)
9583
pageId = site.rootNotionPageId
9684

9785
console.log(site)

lib/types.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@ export interface PageProps {
1616
error?: PageError
1717
}
1818

19-
export interface Model {
20-
id: string
21-
userId: string
22-
23-
createdAt: number
24-
updatedAt: number
25-
}
26-
27-
export interface Site extends Model {
19+
export interface Site {
2820
name: string
2921
domain: string
3022

@@ -40,10 +32,6 @@ export interface Site extends Model {
4032
// opengraph metadata
4133
description?: string
4234
image?: string
43-
44-
timestamp: Date
45-
46-
isDisabled: boolean
4735
}
4836

4937
export interface SiteMap {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"react-dom": "^17.0.2",
5151
"react-notion-x": "^6.12.3",
5252
"react-tweet-embed": "^2.0.0",
53-
"react-use": "^17.3.2"
53+
"react-use": "^17.3.2",
54+
"rss": "^1.2.2"
5455
},
5556
"devDependencies": {
5657
"@next/bundle-analyzer": "^12.1.0",

pages/[pageId].tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react'
22
import { isDev, domain } from 'lib/config'
3-
import { getSiteMaps } from 'lib/get-site-maps'
3+
import { getSiteMap } from 'lib/get-site-map'
44
import { resolveNotionPage } from 'lib/resolve-notion-page'
55
import { NotionPage } from 'components'
66

@@ -28,22 +28,20 @@ export async function getStaticPaths() {
2828
}
2929
}
3030

31-
const siteMaps = await getSiteMaps()
31+
const siteMap = await getSiteMap()
3232

33-
const ret = {
34-
paths: siteMaps.flatMap((siteMap) =>
35-
Object.keys(siteMap.canonicalPageMap).map((pageId) => ({
36-
params: {
37-
pageId
38-
}
39-
}))
40-
),
33+
const staticPaths = {
34+
paths: Object.keys(siteMap.canonicalPageMap).map((pageId) => ({
35+
params: {
36+
pageId
37+
}
38+
})),
4139
// paths: [],
4240
fallback: true
4341
}
4442

45-
console.log(ret.paths)
46-
return ret
43+
console.log(staticPaths.paths)
44+
return staticPaths
4745
}
4846

4947
export default function NotionDomainDynamicPage(props) {

pages/api/social-image.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import {
1111
import { PageBlock } from 'notion-types'
1212

1313
import { notion } from 'lib/notion-api'
14-
import { getSiteForDomain } from 'lib/get-site-for-domain'
1514
import { mapImageUrl } from 'lib/map-image-url'
16-
import * as config from 'lib/config'
1715
import { interRegular } from 'lib/fonts'
16+
import * as config from 'lib/config'
1817

1918
/**
2019
* Social image generation via headless chrome.
@@ -35,7 +34,6 @@ export default withOGImage<'query', 'id'>({
3534
throw new Error('Invalid notion page id')
3635
}
3736

38-
const site = await getSiteForDomain(config.domain)
3937
const recordMap = await notion.getPage(pageId)
4038

4139
const keys = Object.keys(recordMap?.block || {})
@@ -47,7 +45,7 @@ export default withOGImage<'query', 'id'>({
4745

4846
const isBlogPost =
4947
block.type === 'page' && block.parent_table === 'collection'
50-
const title = getBlockTitle(block, recordMap) || site.name
48+
const title = getBlockTitle(block, recordMap) || config.name
5149
const image = mapImageUrl(
5250
getPageProperty<string>('Social Image', block, recordMap) ||
5351
(block as PageBlock).format?.page_cover ||
@@ -96,7 +94,7 @@ export default withOGImage<'query', 'id'>({
9694
month: 'long'
9795
})} ${dateUpdated.getFullYear()}`
9896
: undefined
99-
const detail = date || site.domain
97+
const detail = date || config.domain
10098

10199
return (
102100
<html>

0 commit comments

Comments
 (0)