feat: fix tweet build

This commit is contained in:
Travis Fischer
2021-02-14 23:37:27 -05:00
parent 0add28665a
commit a51b8a48af
4 changed files with 18 additions and 13 deletions

View File

@@ -163,7 +163,7 @@ export const NotionPage: React.FC<types.PageProps> = ({
return (
<Twitter.Provider
value={{
tweetAstMap: recordMap.tweetAstMap || {},
tweetAstMap: (recordMap as any).tweetAstMap || {},
swrOptions: {
fetcher: (id) =>
fetch(`/api/get-tweet-ast/${id}`).then((r) => r.json())

View File

@@ -3,7 +3,7 @@ import { getAllPagesInSpace } from 'notion-utils'
import * as types from './types'
import { includeNotionIdInUrls } from './config'
import { getPage } from './notion'
import { notion } from './notion'
import { getCanonicalPageId } from './get-canonical-page-id'
const uuid = !!includeNotionIdInUrls
@@ -17,7 +17,7 @@ export async function getAllPagesImpl(
const pageMap = await getAllPagesInSpace(
rootNotionPageId,
rootNotionSpaceId,
getPage
notion.getPage.bind(notion)
)
const canonicalPageMap = Object.keys(pageMap).reduce(

View File

@@ -2,10 +2,10 @@ import { NotionAPI } from 'notion-client'
import { ExtendedRecordMap, SearchParams, SearchResults } from 'notion-types'
import { getPreviewImages } from './get-preview-images'
import { mapNotionImageUrl } from './map-image-url'
import { fetchTweetAst, getTweetAst } from 'static-tweets'
import { fetchTweetAst } from 'static-tweets'
import pMap from 'p-map'
const notion = new NotionAPI({
export const notion = new NotionAPI({
apiBaseUrl: process.env.NOTION_API_BASE_URL
})
@@ -63,6 +63,8 @@ export async function getPage(pageId: string): Promise<ExtendedRecordMap> {
}
}
}
return null
})
.filter(Boolean)
@@ -83,13 +85,16 @@ export async function getPage(pageId: string): Promise<ExtendedRecordMap> {
}
)
const tweetAstMap = tweetAsts.filter(Boolean).reduce(
(acc, t) => ({
...acc,
[t.tweetId]: t.tweetAst
}),
{}
)
const tweetAstMap = tweetAsts.reduce((acc, { tweetId, tweetAst }) => {
if (tweetAst) {
return {
...acc,
[tweetId]: tweetAst
}
} else {
return acc
}
}, {})
;(recordMap as any).tweetAstMap = tweetAstMap

View File

@@ -44,7 +44,7 @@ export async function resolveNotionPage(domain: string, rawPageId?: string) {
if (pageId) {
// TODO: we're not re-using the site from siteMaps because it is
// cachd aggressively
// cached aggressively
// site = await getSiteForDomain(domain)
// recordMap = siteMap.pageMap[pageId]