Skip to content

Commit

Permalink
feat: add getPageTweets util
Browse files Browse the repository at this point in the history
  • Loading branch information
transitive-bullshit committed Nov 10, 2024
1 parent eb8b4ec commit e4c4e77
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/full/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default {
'www.notion.so',
'notion.so',
'images.unsplash.com',
'abs.twimg.com',
'pbs.twimg.com',
's3.us-west-2.amazonaws.com'
],
Expand Down
23 changes: 23 additions & 0 deletions packages/notion-utils/src/get-page-tweets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type * as types from 'notion-types'

/**
* Gets the IDs of all tweets embedded on a page.
*/
export const getPageTweets = (recordMap: types.ExtendedRecordMap): string[] => {
const blockIds = Object.keys(recordMap.block)
const tweetIds: string[] = blockIds
.map((blockId) => {
const block = recordMap.block[blockId]?.value

if (block?.type === 'tweet') {
const tweetId = block.properties?.source?.[0]?.[0]

if (tweetId) {
return tweetId
}
}
})
.filter(Boolean)

return Array.from(new Set(tweetIds))
}
1 change: 1 addition & 0 deletions packages/notion-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from './get-page-image-urls'
export * from './get-page-property'
export * from './get-page-table-of-contents'
export * from './get-page-title'
export * from './get-page-tweets'
export * from './get-text-content'
export * from './id-to-uuid'
export * from './is-url'
Expand Down

0 comments on commit e4c4e77

Please sign in to comment.