@@ -155,20 +155,35 @@ export const getJsonLdData = async ({
155155 error : `Unknown node type "${ type as string } " for page "${ text } "` ,
156156 } ) ;
157157 }
158- const backlinks = (
158+ const directBacklinks = (
159+ await ( window . roamAlphaAPI . data . backend . q (
160+ `[:find ?uid
161+ :where
162+ [?page :block/uid "${ uid } "]
163+ [?refBlock :block/refs ?page]
164+ [?refBlock :block/page ?refPage]
165+ [?refPage :block/uid ?uid]
166+ ]` ,
167+ ) as Promise < Array < [ string ] > > )
168+ )
169+ . map ( ( x ) => x [ 0 ] )
170+ . filter ( ( x ) => nodeSet . has ( x ) ) ;
171+ const indirectBacklinks = (
159172 await ( window . roamAlphaAPI . data . backend . q (
160173 `[:find ?uid
161174 :where
162175 [?page :block/uid "${ uid } "]
163176 [?block :block/page ?page]
164- [or [ ?refBlock :block/refs ?block] [?refBlock :block/refs ?page] ]
177+ [?refBlock :block/refs ?block]
165178 [?refBlock :block/page ?refPage]
166179 [?refPage :block/uid ?uid]
167180 ]` ,
168181 ) as Promise < Array < [ string ] > > )
169182 )
170183 . map ( ( x ) => x [ 0 ] )
171184 . filter ( ( x ) => nodeSet . has ( x ) ) ;
185+ directBacklinks . push ( ...indirectBacklinks ) ;
186+ const backlinks = [ ...new Set ( directBacklinks ) ] ;
172187 const r : Record < string , string | string [ ] > = {
173188 "@id" : `pages:${ uid } ` , // eslint-disable-line @typescript-eslint/naming-convention
174189 "@type" : nodeType , // eslint-disable-line @typescript-eslint/naming-convention
@@ -179,7 +194,7 @@ export const getJsonLdData = async ({
179194 creator : displayName ,
180195 } ;
181196 if ( backlinks . length > 0 ) {
182- r [ "backlinks " ] = backlinks . map ( ( x ) => `pages:${ x } ` ) ;
197+ r [ "backlink " ] = backlinks . map ( ( x ) => `pages:${ x } ` ) ;
183198 }
184199 numTreatedPages += 1 ;
185200 await updateExportProgress ( 0.1 + ( numTreatedPages / numPages ) * 0.75 ) ;
0 commit comments