import { Injectable } from '@angular/core' ; import { ContentVersion , VersionDigest } from './content/meta' ; import { VersionLoader } from './version/version-loader' ; @ Injectable ( { providedIn : 'root' , } ) export class CrossLinkingService { constructor ( private loader ) { } async genCrossVersionsLink ( toVersionDigest , url ) { const toVersion = await this . loader . load ( toVersionDigest . url ) ; if ( toVersion && url . sectionUrl ) { const section = toVersion . sections . find ( s => s . url === url . sectionUrl ) ; if ( section ) { if ( url . pageUrl ) { const page = section . pages . find ( p => p . url === url . pageUrl ) ; if ( page ) { return [ '/' , section . url , page . url ] ; } else { return [ '/' , section . url , 'intro' ] ; } } else { return [ '/' , section . url , 'intro' ] ; } } else { return [ '/' ] ; } } else { return [ '/' , toVersionDigest . url ] ; } } }