import { urlGenerator } from './urlGenerator' ; export const getParentTitle = ( slug , allMdx ? ) => { const allContent = allMdx && allMdx . edges && allMdx . edges . map ( ( mdx ) => ( { ... mdx . node . fields , title : mdx . node . frontmatter . title , staticLink : mdx . node . frontmatter . staticLink , } ) ) ; allContent ?. map ( ( content ) => { content . parentTitle = [ ] ; const parts = content . slug . split ( '/' ) ; const slicedParts = parts . slice ( 1 , parts [ parts . length - 1 ] === 'index' ? parts . length - 2 : parts . length - 1 ) ; slicedParts . forEach ( ( part ) => { const parent = allContent . find ( ( ac ) => { const parentParts = ac . slug . split ( '/' ) ; return ( parentParts [ parentParts . length - 1 ] === 'index' && parentParts [ parentParts . length - 2 ] === part ) ; } ) ; if ( parent ) { content . parentTitle . push ( { title : parent ?. title , link : urlGenerator ( parent . modSlug ) , } ) ; } } ) ; } ) ; const currentSlug = allContent . find ( ( mdx ) => mdx . modSlug === slug ) ; return currentSlug ? currentSlug . parentTitle : [ ] ; } ;