import * as fs from 'fs' ; import { Renderer , DeclarationReflection , RendererEvent } from 'typedoc' ; import { MarkdownTheme } from 'typedoc-plugin-markdown' ; export class GitlabWikiTheme extends MarkdownTheme { constructor ( renderer ) { super ( renderer ) ; this . entryDocument = 'home.md' ; this . hideBreadcrumbs = true ; this . hidePageTitle = true ; this . listenTo ( this . owner , { [ RendererEvent . END ] : this . onGitLabRendererEnd , } ) ; } getRelativeUrl ( url ) { const relativeUrl = super . getRelativeUrl ( url ) . replace ( /(.*).md/ , '$1' ) . replace ( / /g , '-' ) ; return relativeUrl . startsWith ( '..' ) ? relativeUrl : './' + relativeUrl ; } toUrl ( mapping , reflection ) { return `${ mapping . directory }/${ reflection . getFullName ( ) }.md` ; } onGitLabRendererEnd ( renderer ) { const parseUrl = ( url ) => url . replace ( /(.*).md/ , '$1' ) ; const navigation = this . getNavigation ( renderer . project ) ; const navJson = [ `## ${ renderer . project . name }\n` ] ; navigation . children ?. forEach ( ( navItem ) => { if ( navItem . isLabel ) { navJson . push ( `\n### ${ navItem . title }\n` ) ; navItem . children ?. forEach ( ( navItemChild ) => { const longTitle = navItemChild . title . split ( '.' ) ; const shortTitle = longTitle [ longTitle . length - 1 ] ; navJson . push ( `- [${ shortTitle }](${ parseUrl ( encodeURI ( navItemChild . url ) ) })` ) ; } ) ; } else { const title = navItem . url === this . entryDocument ? 'Home' : navItem . title ; navJson . push ( `- [${ title }](${ parseUrl ( navItem . url ) })` ) ; } } ) ; fs . writeFileSync ( renderer . outputDirectory + '/_sidebar.md' , navJson . join ( '\n' ) ) ; } get globalsFile ( ) { return this . entryPoints . length > 1 ? 'Modules.md' : 'Exports.md' ; } }