onRendererEnd(renderer: RendererEvent) { if (!this.application.options.getValue('skipSidebar')) { const docusarusRoot = this.findDocusaurusRoot(renderer.outputDirectory); if (docusarusRoot === null) { this.application.logger.warn( `[typedoc-markdown-plugin] sidebars.json not written as could not locate docusaurus root directory. In order to to implemnent sidebars.json functionality, the output directory must be a child of a 'docs' directory.`, ); return; } this.writeSideBar(renderer, docusarusRoot); } }
onRendererEnd(renderer: RendererEvent) { const root = this.findRoot(renderer.outputDirectory); if (root === null) { this.application.logger.warn( `[typedoc-markdown-plugin] sidebars.json not written as could not locate VuePress root directory. In order to to implemnent sidebars.json functionality, the output directory must be a child of a 'docs' directory.`, ); return; } this.writeSideBar(renderer, root); }
initialize() { super.initialize(); this.listenTo(this.application.renderer, { [PageEvent.END]: this.onPageEnd, }); }
writeSummary(renderer: RendererEvent) { const outputDirectory = renderer.outputDirectory; const summaryMarkdown = this.getSummaryMarkdown(renderer); try { fs.writeFileSync(`${outputDirectory}/SUMMARY.md`, summaryMarkdown); this.application.logger.write(`[typedoc-plugin-markdown] SUMMARY.md written to ${outputDirectory}`); } catch (e) { this.application.logger.write(`[typedoc-plugin-markdown] failed to write SUMMARY at ${outputDirectory}`); } }
inputFiles.forEach(file => { const result = app.convert(app.expandInputFiles([file])); fs.writeFileSync(`${fixturesDir}/${path.basename(file)}.json`, JSON.stringify(result, replacer)); console.log(`[typedoc-plugin-markdown(task:fixtures)] writing ${path.basename(file)}.json fixture`); });
constructor(renderer: Renderer, basePath: string) { super(renderer, basePath); this.listenTo(renderer, PageEvent.END, this.onPageEnd, 1024); // cleanup html specific components renderer.removeComponent('assets'); renderer.removeComponent('javascript-index'); renderer.removeComponent('toc'); renderer.removeComponent('pretty-print'); // add markdown related componenets renderer.addComponent('helpers', new ContextAwareHelpersComponent(renderer)); renderer.addComponent('options', new OptionsComponent(renderer)); this.indexName = this.application.options.getValue('name'); if (!this.indexName) { throw new Error('`--name` must be provided') } }
/** * Read the theme option and load the paths of any recognised built in themes * Otherwise pass the path through to the Renderer */ onResolveBegin() { const options = this.application.options; const theme = (options.getValue('platform') as string) || (options.getValue('theme') as string); // if the theme is 'default' or 'markdown' load the base markdown theme if (theme === 'default' || theme === 'markdown') { options.setValue('theme', path.join(__dirname)); } // load any built in sub themes const subThemes = ['docusaurus', 'docusaurus2', 'vuepress', 'gitbook', 'bitbucket']; if (subThemes.includes(theme)) { options.setValue('theme', path.join(__dirname, 'subthemes', theme)); } }
public breadcrumb(model: Reflection, project: ProjectReflection, md: string[]) { const theme = this.application.renderer.theme as MarkdownTheme; if (model && model.parent) { this.breadcrumb(model.parent, project, md); if (model.url) { md.push(`[${model.name}](${this.getRelativeUrl(model.url)})`); } else { md.push(model.url); } } else { if (!!project.readme) { md.push(`[${project.name}](${this.getRelativeUrl(theme.indexName + theme.fileExt)})`); } md.push(`[${project.readme ? 'Globals' : project.name}](${this.getRelativeUrl(project.url)})`); } return md.join(' › '); }
initialize() { super.initialize(); const namedAnchors = this.application.options.getValue('namedAnchors'); const hideBreadcrumbs = this.application.options.getValue('hideBreadcrumbs'); const hideIndexes = this.application.options.getValue('hideIndexes'); const hideSourceFiles = this.application.options.getValue('hideSources'); MarkdownTheme.handlebars.registerHelper('ifNamedAnchors', function(options) { return namedAnchors ? options.fn(this) : options.inverse(this); }); MarkdownTheme.handlebars.registerHelper('ifBreadcrumbs', function(options) { return hideBreadcrumbs ? options.inverse(this) : options.fn(this); }); MarkdownTheme.handlebars.registerHelper('ifIndexes', function(options) { return hideIndexes ? options.inverse(this) : options.fn(this); }); MarkdownTheme.handlebars.registerHelper('ifSources', function(options) { return hideSourceFiles ? options.inverse(this) : options.fn(this); }); }
projects.forEach(({ name, docsPath, outputDir }) => { const tmpDir = path.join(outputDir, 'tmp'); const project = app.convert(app.expandInputFiles([docsPath])); if (project) { app.generateDocs(project, tmpDir); if (fs.existsSync(tmpDir)) { const [tmpFileName] = fs.readdirSync(tmpDir); const pathArr = tmpDir.split('/'); pathArr.splice(-1, 1); const out = path.join(...pathArr); const currentPath = path.join(out, `${name}.md`); fs.copyFileSync(path.join(tmpDir, tmpFileName), currentPath); fs.removeSync(tmpDir); } } else { console.error(`Error while generating '${name}' docs`); } });
writeSideBar(renderer: RendererEvent, root: string) { const childDirectory = renderer.outputDirectory.split(root + 'docs/')[1]; const docsRoot = childDirectory ? childDirectory + '/' : ''; const vuePressRoot = root + 'docs/.vuepress'; const navObject = this.getNavObject(renderer, docsRoot); const sidebarPath = vuePressRoot + '/api-sidebar.json'; const relativeNavObject = this.getNavObject(renderer); const relativeSidebarPath = vuePressRoot + '/api-sidebar-relative.json'; if (!fs.existsSync(vuePressRoot)) { fs.mkdirSync(vuePressRoot); } try { fs.writeFileSync(sidebarPath, JSON.stringify(navObject, null, 2)); fs.writeFileSync(relativeSidebarPath, JSON.stringify(relativeNavObject, null, 2)); this.application.logger.write(`[typedoc-plugin-markdown] sidebars.json updated at ${sidebarPath}`); } catch (e) { this.application.logger.write(`[typedoc-plugin-markdown] failed to update sidebars.json at ${sidebarPath}`); } }
/** * Triggered when [[Renderer]] is finished */ onEndRenderer(event: RendererEvent) { if (this.listInvalidSymbolLinks && this.warnings.length > 0) { this.application.logger.write(''); this.application.logger.warn( 'Found invalid symbol reference(s) in JSDocs, ' + 'they will not render as links in the generated documentation.', ); for (const warning of this.warnings) { this.application.logger.write(' ' + warning); } } }
writeSideBar(renderer: RendererEvent, docusarusRoot: string) { const childDirectory = renderer.outputDirectory.split(docusarusRoot + 'docs/')[1]; const docsRoot = childDirectory ? childDirectory + '/' : ''; const websitePath = docusarusRoot; const navObject = this.getNavObject(renderer, docsRoot); const sidebarPath = websitePath + this.sidebarName; let jsonContent: any; if (!fs.existsSync(sidebarPath)) { if (!fs.existsSync(websitePath)) { fs.mkdirSync(websitePath); } jsonContent = JSON.parse('{}'); } else { jsonContent = require(sidebarPath); } let firstKey = Object.keys(jsonContent)[0]; if (!firstKey) { firstKey = 'docs'; } jsonContent[firstKey] = Object.assign({}, jsonContent[firstKey], navObject); try { fs.writeFileSync(sidebarPath, 'module.exports = ' + JSON.stringify(jsonContent, null, 2) + ';'); this.application.logger.write(`[typedoc-plugin-markdown] ${this.sidebarName} updated at ${sidebarPath}`); } catch (e) { this.application.logger.write(`[typedoc-plugin-markdown] failed to update ${this.sidebarName} at ${sidebarPath}`); } }
initialize() { super.initialize(); this.includes = this.application.options.getValue('includes'); this.mediaDirectory = this.application.options.getValue('media'); this.listInvalidSymbolLinks = this.application.options.getValue('listInvalidSymbolLinks'); this.listenTo( this.owner, { [RendererEvent.END]: this.onEndRenderer, }, undefined, 100, ); const component = this; MarkdownTheme.handlebars.registerHelper('comment', function(this: string) { return component.parseComments(this); }); MarkdownTheme.handlebars.registerHelper('breadcrumbs', function(this: PageEvent) { return component.breadcrumb(this.model, this.project, []); }); MarkdownTheme.handlebars.registerHelper('relativeURL', (url: string) => { return url ? this.getRelativeUrl(url) : url; }); }
onRendererEnd(renderer: RendererEvent) { if (!this.application.options.getValue('skipSidebar')) { const docusarusRoot = this.findDocusaurus2Root(renderer.outputDirectory); if (docusarusRoot === null) { this.application.logger.warn( `[typedoc-markdown-plugin] ${this.sidebarName} not written as could not locate docusaurus root directory. In order to to implemnent ${this.sidebarName} functionality, the output directory must be a child of a 'docs' directory.`, ); return; } this.writeSideBar(renderer, docusarusRoot); } }