From a51b8a48af30f758cadae18f0950e830c17db928 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Sun, 14 Feb 2021 23:37:27 -0500 Subject: [PATCH] feat: fix tweet build --- components/NotionPage.tsx | 2 +- lib/get-all-pages.ts | 4 ++-- lib/notion.ts | 23 ++++++++++++++--------- lib/resolve-notion-page.ts | 2 +- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/components/NotionPage.tsx b/components/NotionPage.tsx index b238149..266717b 100644 --- a/components/NotionPage.tsx +++ b/components/NotionPage.tsx @@ -163,7 +163,7 @@ export const NotionPage: React.FC = ({ return ( fetch(`/api/get-tweet-ast/${id}`).then((r) => r.json()) diff --git a/lib/get-all-pages.ts b/lib/get-all-pages.ts index eaa5190..44a4c30 100644 --- a/lib/get-all-pages.ts +++ b/lib/get-all-pages.ts @@ -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( diff --git a/lib/notion.ts b/lib/notion.ts index 84eca26..1429fc3 100644 --- a/lib/notion.ts +++ b/lib/notion.ts @@ -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 { } } } + + return null }) .filter(Boolean) @@ -83,13 +85,16 @@ export async function getPage(pageId: string): Promise { } ) - 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 diff --git a/lib/resolve-notion-page.ts b/lib/resolve-notion-page.ts index fd84576..a048cf5 100644 --- a/lib/resolve-notion-page.ts +++ b/lib/resolve-notion-page.ts @@ -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]