Skip to content

Commit e4c4e77

Browse files
feat: add getPageTweets util
1 parent eb8b4ec commit e4c4e77

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

examples/full/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default {
55
'www.notion.so',
66
'notion.so',
77
'images.unsplash.com',
8+
'abs.twimg.com',
89
'pbs.twimg.com',
910
's3.us-west-2.amazonaws.com'
1011
],
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type * as types from 'notion-types'
2+
3+
/**
4+
* Gets the IDs of all tweets embedded on a page.
5+
*/
6+
export const getPageTweets = (recordMap: types.ExtendedRecordMap): string[] => {
7+
const blockIds = Object.keys(recordMap.block)
8+
const tweetIds: string[] = blockIds
9+
.map((blockId) => {
10+
const block = recordMap.block[blockId]?.value
11+
12+
if (block?.type === 'tweet') {
13+
const tweetId = block.properties?.source?.[0]?.[0]
14+
15+
if (tweetId) {
16+
return tweetId
17+
}
18+
}
19+
})
20+
.filter(Boolean)
21+
22+
return Array.from(new Set(tweetIds))
23+
}

packages/notion-utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export * from './get-page-image-urls'
1414
export * from './get-page-property'
1515
export * from './get-page-table-of-contents'
1616
export * from './get-page-title'
17+
export * from './get-page-tweets'
1718
export * from './get-text-content'
1819
export * from './id-to-uuid'
1920
export * from './is-url'

0 commit comments

Comments
 (0)