import type { Metadata , backlinks } from 'src/interfaces' ; self . onmessage = function ( e ) { const metadataCache = e . data [ 0 ] ; let backlinkObj = e . data [ 1 ] ; const newMetadataCache = metadataCache ; metadataCache . forEach ( ( file ) => { const fileName = file . fileName ; const relativeFilePath = file . relativePath ; newMetadataCache . forEach ( ( otherFile ) => { if ( fileName !== otherFile . fileName ) { if ( otherFile . links ) { otherFile . links . forEach ( ( links ) => { const currentBacklinkObject = { } ; if ( links . relativePath === relativeFilePath ) { currentBacklinkObject . fileName = otherFile . fileName ; currentBacklinkObject . link = links . link ; currentBacklinkObject . relativePath = otherFile . relativePath ; if ( links . cleanLink ) { currentBacklinkObject . cleanLink = links . cleanLink ; } if ( links . displayText ) { currentBacklinkObject . displayText = links . displayText ; } backlinkObj . push ( currentBacklinkObject ) ; } } ) ; } } } ) ; if ( backlinkObj . length > 0 ) { file . backlinks = backlinkObj ; } backlinkObj = [ ] ; } ) ; self . postMessage ( metadataCache ) ; } ;