feat: improve styling, update deps, fixes

This commit is contained in:
Travis Fischer
2022-03-25 23:07:37 -04:00
parent 29704773e6
commit dc230a1b94
6 changed files with 41 additions and 54 deletions

View File

@@ -1,3 +1,12 @@
import { Block } from 'notion-types'
import { defaultMapImageUrl } from 'react-notion-x'
export const mapImageUrl = defaultMapImageUrl
import { defaultPageIcon, defaultPageCover } from './config'
export const mapImageUrl = (url: string, block: Block) => {
if (url === defaultPageCover || url === defaultPageIcon) {
return url
}
return defaultMapImageUrl(url, block)
}

View File

@@ -3,7 +3,9 @@ import lqip from 'lqip-modern'
import pMap from 'p-map'
import pMemoize from 'p-memoize'
import { ExtendedRecordMap, PreviewImage, PreviewImageMap } from 'notion-types'
import { getPageImageUrls } from 'notion-utils'
import { defaultPageIcon, defaultPageCover } from './config'
import { db } from './db'
import { mapImageUrl } from './map-image-url'
@@ -16,41 +18,10 @@ import { mapImageUrl } from './map-image-url'
export async function getPreviewImageMap(
recordMap: ExtendedRecordMap
): Promise<PreviewImageMap> {
const blockIds = Object.keys(recordMap.block)
const imageUrls: string[] = blockIds
.map((blockId) => {
const block = recordMap.block[blockId]?.value
if (block) {
if (block.type === 'image') {
const signedUrl = recordMap.signed_urls?.[block.id]
const source = signedUrl || block.properties?.source?.[0]?.[0]
if (source) {
return {
block,
url: source
}
}
}
if ((block.format as any)?.page_cover) {
const source = (block.format as any).page_cover
return {
block,
url: source
}
}
}
return null
})
.filter(Boolean)
.map(({ block, url }) => mapImageUrl(url, block))
const urls: string[] = getPageImageUrls(recordMap, { mapImageUrl })
.concat([defaultPageIcon, defaultPageCover])
.filter(Boolean)
const urls = Array.from(new Set(imageUrls))
const previewImagesMap = Object.fromEntries(
await pMap(urls, async (url) => [url, await getPreviewImage(url)], {
concurrency: 8