File tree Expand file tree Collapse file tree 4 files changed +50
-24
lines changed
packages/notion-utils/src Expand file tree Collapse file tree 4 files changed +50
-24
lines changed Original file line number Diff line number Diff line change 1+ import type * as types from 'notion-types'
2+
3+ import { getPageTweetUrls } from './get-page-tweet-urls'
4+
5+ /**
6+ * Gets the IDs of all tweets embedded on a page.
7+ */
8+ export const getPageTweetIds = (
9+ recordMap : types . ExtendedRecordMap
10+ ) : string [ ] => {
11+ const tweetUrls = getPageTweetUrls ( recordMap )
12+ return tweetUrls
13+ . map ( ( url ) => {
14+ try {
15+ const u = new URL ( url )
16+ const parts = u . pathname . split ( '/' )
17+ return parts . at ( - 1 )
18+ } catch {
19+ return
20+ }
21+ } )
22+ . filter ( Boolean )
23+ }
Original file line number Diff line number Diff line change 1+ import type * as types from 'notion-types'
2+
3+ /**
4+ * Gets the URLs of all tweets embedded on a page.
5+ */
6+ export const getPageTweetUrls = (
7+ recordMap : types . ExtendedRecordMap
8+ ) : string [ ] => {
9+ const blockIds = Object . keys ( recordMap . block )
10+ const tweetUrls : string [ ] = blockIds
11+ . map ( ( blockId ) => {
12+ const block = recordMap . block [ blockId ] ?. value
13+
14+ if ( block ?. type === 'tweet' ) {
15+ const tweetUrl = block . properties ?. source ?. [ 0 ] ?. [ 0 ]
16+
17+ if ( tweetUrl ) {
18+ return tweetUrl
19+ }
20+ }
21+ } )
22+ . filter ( Boolean )
23+
24+ return Array . from ( new Set ( tweetUrls ) )
25+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ export * from './get-page-image-urls'
1414export * from './get-page-property'
1515export * from './get-page-table-of-contents'
1616export * from './get-page-title'
17- export * from './get-page-tweets'
17+ export * from './get-page-tweet-ids'
18+ export * from './get-page-tweet-urls'
1819export * from './get-text-content'
1920export * from './id-to-uuid'
2021export * from './is-url'
You can’t perform that action at this time.
0 commit comments