feat: revert to using official twitter embedding sdk; bump deps

This commit is contained in:
Travis Fischer
2022-04-19 21:24:55 -04:00
parent aed9b2037d
commit 8163ce123d
8 changed files with 27 additions and 852 deletions

View File

@@ -77,12 +77,6 @@ export const isPreviewImageSupportEnabled: boolean = getSiteConfig(
false
)
// Optional whether or not to enable support for LQIP preview images
export const isTweetEmbedSupportEnabled: boolean = getSiteConfig(
'isTweetEmbedSupportEnabled',
true
)
// Optional whether or not to include the Notion ID in page URLs or just use slugs
export const includeNotionIdInUrls: boolean = getSiteConfig(
'includeNotionIdInUrls',

View File

@@ -5,10 +5,8 @@ import { mergeRecordMaps } from 'notion-utils'
import { notion } from './notion-api'
import { getPreviewImageMap } from './preview-images'
import { getTweetAstMap } from './tweet-embeds'
import {
isPreviewImageSupportEnabled,
isTweetEmbedSupportEnabled,
navigationStyle,
navigationLinks
} from './config'
@@ -62,11 +60,6 @@ export async function getPage(pageId: string): Promise<ExtendedRecordMap> {
;(recordMap as any).preview_images = previewImageMap
}
if (isTweetEmbedSupportEnabled) {
const tweetAstMap = await getTweetAstMap(recordMap)
;(recordMap as any).tweetAstMap = tweetAstMap
}
return recordMap
}

View File

@@ -1,55 +0,0 @@
import { ExtendedRecordMap } from 'notion-types'
import { fetchTweetAst } from 'static-tweets'
import pMap from 'p-map'
export async function getTweetAstMap(recordMap: ExtendedRecordMap) {
const blockIds = Object.keys(recordMap.block)
const tweetIds: string[] = blockIds
.map((blockId) => {
const block = recordMap.block[blockId]?.value
if (block) {
if (block.type === 'tweet') {
const src = block.properties?.source?.[0]?.[0]
if (src) {
const id = src.split('?')[0].split('/').pop()
if (id) return id
}
}
}
return null
})
.filter(Boolean)
const tweetAsts = await pMap(
tweetIds,
async (tweetId) => {
try {
return {
tweetId,
tweetAst: await fetchTweetAst(tweetId)
}
} catch (err) {
console.error('error fetching tweet info', tweetId, err)
}
},
{
concurrency: 4
}
)
const tweetAstMap = tweetAsts.reduce((acc, { tweetId, tweetAst }) => {
if (tweetAst) {
return {
...acc,
[tweetId]: tweetAst
}
} else {
return acc
}
}, {})
return tweetAstMap
}