Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add link formatter plugin #168

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/plugins/typedoc-plugin-link-formatter.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @ts-check
import { MarkdownPageEvent } from 'typedoc-plugin-markdown';

/**
* This plugin adds a title and description to the frontmatter of each markdown page for compliance with Mintlify.
*
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
*/
export function load(app) {
app.renderer.on(
MarkdownPageEvent.END,
/**
* @param {import('typedoc-plugin-markdown').MarkdownPageEvent} page
*/
(page) => {
if (page.contents) {
if (page.contents.includes('.mdx')) {
const regex = /(\.mdx)/g;
page.contents = page.contents.replace(regex, '');
}
}
},
);
}
33 changes: 14 additions & 19 deletions docs/plugins/typedoc-plugin-mintlify-frontmatter.mjs
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
// @ts-check
import { MarkdownPageEvent } from 'typedoc-plugin-markdown'
import { MarkdownPageEvent } from 'typedoc-plugin-markdown';

/**
* This plugin adds a title and description to the frontmatter of
* each markdown page for compliance with Mintlify.
* This plugin adds a title and description to the frontmatter of each markdown page for compliance with Mintlify.
*
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
*/
export function load(app) {
app.renderer.on(
MarkdownPageEvent.BEGIN,
/** @param {import('typedoc-plugin-markdown').MarkdownPageEvent} page */
(page) => {
let summary = ''
if (page.model?.comment?.summary) {
summary = page.model.comment.summary[0].text + '...'
summary = summary.replace(/\n/g, ' ')
}
page.frontmatter = {
title: page.model?.name,
description: summary,
...page.frontmatter,
}
}
)
app.renderer.on(
MarkdownPageEvent.BEGIN,
/**
* @param {import('typedoc-plugin-markdown').MarkdownPageEvent} page
*/
(page) => {
page.frontmatter = {
title: page.model?.name,
...page.frontmatter,
};
},
);
}
30 changes: 15 additions & 15 deletions docs/plugins/typedoc-plugin-navigation-output.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// @ts-check
import fs from 'fs'
import fs from 'fs';

/**
* This plugin parses and generates a navigation file for the documentation
* that complies with Mintlify's navigation format.
* This plugin parses and generates a navigation file for the documentation that complies with Mintlify's navigation
* format.
*
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
*/
export function load(app) {
app.renderer.postRenderAsyncJobs.push(async (renderer) => {
const navigation = renderer.navigation
if (!navigation) {
return
}
const formattedNavigation = navigation.map((group) => ({
group: group.title,
pages: (group.children || []).map((child) => `content/${child.url.replace('.mdx', '')}`),
}))
fs.writeFileSync('./docs/content/navigation.json', JSON.stringify(formattedNavigation, null, 2))
})
app.renderer.postRenderAsyncJobs.push(async (renderer) => {
const navigation = renderer.navigation;
if (!navigation) {
return;
}
const formattedNavigation = navigation.map((group) => ({
group: group.title,
pages: (group.children || []).map((child) => `content/${child.url.replace('.mdx', '')}`),
}));
fs.writeFileSync('./docs/content/navigation.json', JSON.stringify(formattedNavigation, null, 2));
});
}
65 changes: 33 additions & 32 deletions typedoc.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
{
// base config
"out": "docs/content",
"tsconfig": "tsconfig.base.json",
"entryPoints": ["./src/quais.ts"],
// base config
"out": "docs/content",
"tsconfig": "tsconfig.base.json",
"entryPoints": ["./src/quais.ts"],

// specific inclusions and exclusions
"excludeProtected": true,
"excludeNotDocumented": true,
"exclude": ["./src/_admin/**/*", "./src/_tests/**/*", "./src/testcases/**/*"],
// specific inclusions and exclusions
"excludeProtected": true,
"excludeNotDocumented": true,
"exclude": ["./src/_admin/**/*", "./src/_tests/**/*", "./src/testcases/**/*"],

// plugins
"plugin": [
"typedoc-plugin-remove-references", // remove additional references that clutter documentation
"typedoc-plugin-markdown", // generate markdown files
"typedoc-plugin-frontmatter", // add frontmatter to markdown files, prereq for the below custom plugin
"./docs/plugins/typedoc-plugin-mintlify-frontmatter.mjs", // formats frontmatter to match mintlify
"./docs/plugins/typedoc-plugin-navigation-output.mjs" // formats navigation to match mintlify
],
// plugins
"plugin": [
"typedoc-plugin-remove-references", // remove additional references that clutter documentation
"typedoc-plugin-markdown", // generate markdown files
"typedoc-plugin-frontmatter", // add frontmatter to markdown files, prereq for the below custom plugin
"./docs/plugins/typedoc-plugin-mintlify-frontmatter.mjs", // formats frontmatter to match mintlify
"./docs/plugins/typedoc-plugin-navigation-output.mjs", // formats navigation to match mintlify
"./docs/plugins/typedoc-plugin-link-formatter.mjs" // removes ".mdx" from links
],

// formatting + mintlify compatibility
"fileExtension": ".mdx", // use mdx files for mintlfiy compatibility
"entryFileName": "index.mdx", // rename entry from "README.md" to "index.mdx"
"mergeReadme": true, // merge README.md into index.mdx
"hidePageHeader": true, // hide page header, conflicts with mintlify
"hidePageTitle": true, // hide page title, conflicts with mintlify
"hideBreadcrumbs": true, // hide breadcrumbs, conflicts with mintlify
"useCodeBlocks": true, // makes API definitions more readable
"expandObjects": true,
"parametersFormat": "table", // readability
"propertiesFormat": "table", // readability
"publicPath": "/content/", // format links for mintlify
"navigation": {
"includeCategories": true,
"includeGroups": false
}
// formatting + mintlify compatibility
"fileExtension": ".mdx", // use mdx files for mintlfiy compatibility
"entryFileName": "index.mdx", // rename entry from "README.md" to "index.mdx"
"mergeReadme": true, // merge README.md into index.mdx
"hidePageHeader": true, // hide page header, conflicts with mintlify
"hidePageTitle": true, // hide page title, conflicts with mintlify
"hideBreadcrumbs": true, // hide breadcrumbs, conflicts with mintlify
"useCodeBlocks": true, // makes API definitions more readable
"expandObjects": true,
"parametersFormat": "table", // readability
"propertiesFormat": "table", // readability
"publicPath": "/content/", // format links for mintlify
"navigation": {
"includeCategories": true,
"includeGroups": false
}
}
Loading