Skip to content

Commit

Permalink
feat: Added navigationModel option.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Apr 20, 2024
1 parent 2a90082 commit bde45bd
Show file tree
Hide file tree
Showing 21 changed files with 365 additions and 374 deletions.
2 changes: 1 addition & 1 deletion .changeset/nice-goats-dress.md
Expand Up @@ -3,4 +3,4 @@
---

- Fix broken links in packages index.
- Updates to respect TypeDocs `navigationLinks`, `sidebarLinks` and `navigationLeaves` options.
- Added `navigationModel` option.
1 change: 0 additions & 1 deletion devtools/packages/fixtures/cli.ts
Expand Up @@ -154,7 +154,6 @@ function objectToOptions(obj: any) {
}, []),
];
}

if (typeof curr[1] === 'object') {
return [
...prev,
Expand Down
16 changes: 10 additions & 6 deletions devtools/packages/prebuild-options/tasks/generate-docs.ts
@@ -1,6 +1,7 @@
import { DocsConfig } from '@devtools/helpers';
import * as fs from 'fs';
import * as path from 'path';
import * as prettier from 'prettier';
import { Project, VariableStatement } from 'ts-morph';
import { ParameterType } from 'typedoc';

Expand All @@ -17,13 +18,11 @@ export async function generateOptionsDocs(docsConfig: DocsConfig) {
out.push('# Options');
if (docsConfig.docsPath === '/docs') {
out.push(
`These options can be used in addition to the core TypeDoc options.`,
`<Callout type="info">These options should be used in conjunction with the core [TypeDoc options](/docs/using-typedoc).</Callout>`,
);
} else {
out.push(
`<Callout type="info">
Please view options exposed by [typedoc-plugin-markdown](/docs/options) in addition to those listed here.
</Callout>`,
`<Callout type="info">Please view options exposed by [typedoc-plugin-markdown](/docs/options) in addition to those listed here.</Callout>`,
);
}

Expand Down Expand Up @@ -150,13 +149,14 @@ ${presetsJson}
}

if (!option.omitExample) {
//out.push('**Example**');
if (
!option.example &&
option.type === ParameterType.Mixed &&
Object.keys(option.defaultValue).length &&
(!Array.isArray(option.defaultValue) || option.defaultValue?.length)
) {
out.push('Below is the full list of keys and default values:');
//out.push('Below is the full list of keys and default values:');
}

out.push(`
Expand All @@ -181,7 +181,11 @@ ${JSON.stringify(
'options.mdx',
);

fs.writeFileSync(optionDocPath, out.join('\n\n'));
const formattedOut = await prettier.format(out.join('\n\n'), {
parser: 'mdx',
});

fs.writeFileSync(optionDocPath, formattedOut);
}

function getEmoji(categoryName: string) {
Expand Down
6 changes: 4 additions & 2 deletions devtools/packages/prebuild-options/tasks/generate-models.ts
Expand Up @@ -139,8 +139,10 @@ function getType(
if (option.type === ParameterType.Array) {
return 'any[]';
}
if (option.type === ParameterType.Flags) {
return 'Record<string, boolean>';
if (option.type === ParameterType.Flags && option.defaults) {
return `{${Object.keys(option.defaults)
.map((key) => `'${key}': boolean`)
.join(';')}}`;
}
if (option.type === ParameterType.Mixed && option.defaultValue) {
const usePartial = name === 'textContentMappings';
Expand Down
22 changes: 5 additions & 17 deletions docs/pages/docs/navigation.mdx
@@ -1,14 +1,16 @@
# Navigation

If required, a navigation structure can be provided to the output. This is useful if you want to provide a custom sidebar or navigation bar.
If required, a navigation model can be provided to the output. This is useful if you want to provide a custom sidebar/navigation implementation (if relevant to your environment).

## Usage

The navigation structure is available on the [MarkdownRendererEvent](/api-docs/Class.MarkdownRendererEvent#navigation) and can be accessed by utilizing the `postRenderAsyncJobs` on the renderer.
The navigation model can be accessed by utilizing the `postRenderAsyncJobs` on the renderer.

The navigation is returned as `JSON` and can be mapped to a custom structure and written to a file.

```ts
The model can be configured by the [`--navigationModel`](/docs/options#navigationmodel) option.

```ts filename="custom-plugin.ts"
export function load(app: MarkdownApplication) {
app.renderer.postRenderAsyncJobs.push(
async (renderer: MarkdownRendererEvent) => {
Expand All @@ -21,17 +23,3 @@ export function load(app: MarkdownApplication) {
);
}
```

## Options

The navigation implementation utilizes the [`navigation`](https://typedoc.org/options/output/#navigation) core TypeDoc option.

```json
{
"navigation": {
"includeFolders": true,
"includeGroups": false,
"includeCategories": false
}
}
```

0 comments on commit bde45bd

Please sign in to comment.