Skip to content

Commit

Permalink
feat: Added ability to pass in additional global Frontmatter options
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Feb 18, 2022
1 parent bd1a3cd commit 55cc7e0
Show file tree
Hide file tree
Showing 8 changed files with 1,636 additions and 1,353 deletions.
22 changes: 22 additions & 0 deletions packages/docusaurus-plugin-typedoc/README.md
Expand Up @@ -99,6 +99,7 @@ Options specific to the plugin should also be declared in the same object.
| :---------------------- | :------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `out` | `"api"` | Output dir relative to docs dir (use `.` for no subdir). |
| `includeExtension` | `true` | Determines whether to preserve the `.md` extension in relative links. `true` is recommended as per [Docusaurus documentation](https://docusaurus.io/docs/docs-markdown-features#referencing-other-documents) |
| `frontmatter` | `null` | Additional frontmatter options object. See [Frontmatter](#frontmatter). |
| `sidebar.categoryLabel` | `API` | The sidebar parent category label. |
| `sidebar.fullNames` | `false` | Display full names with module path. |
| `sidebar.position` | `auto` | The position of the sidebar in the tree. |
Expand Down Expand Up @@ -192,6 +193,27 @@ A navbar item can be configured in `themeConfig` options in `docusaurus.config.j

Please see https://docusaurus.io/docs/api/themes/configuration#navbar-items for navbar documentation.

### Frontmatter

By default the plugin will configure minimal required [Frontmatter](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs#markdown-front-matter) configuration.
Additionally required global Frontmatter options can be passed in using the `frontmatter` options object

`docusaurus.config.js`:

```js
plugins: [
[
'docusaurus-plugin-typedoc',
{
// .... other plugin option
frontmatter: {
pagination_prev: null,
pagination_next: null
}
]
]
```
### Multi instance
It is possible to build multi TypeDoc instances by passing in multiple configs with unique ids:
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-typedoc/src/options.ts
Expand Up @@ -20,6 +20,7 @@ const DEFAULT_PLUGIN_OPTIONS: PluginOptions = {
includeExtension: true,
indexSlug: undefined,
theme: 'docusaurus',
frontmatter: undefined,
};

export const getPluginOptions = (
Expand Down
5 changes: 5 additions & 0 deletions packages/docusaurus-plugin-typedoc/src/render.ts
Expand Up @@ -81,6 +81,11 @@ const addTypedocDeclarations = (app: Application) => {
name: 'sidebar',
type: ParameterType.Mixed,
} as MixedDeclarationOption);

app.options.addDeclaration({
name: 'frontmatter',
type: ParameterType.Mixed,
} as MixedDeclarationOption);
};

export function removeDir(path: string) {
Expand Down
16 changes: 13 additions & 3 deletions packages/docusaurus-plugin-typedoc/src/theme.ts
Expand Up @@ -14,6 +14,7 @@ import * as path from 'path';

import { FrontMatter, SidebarOptions } from './types';
import {
FrontMatterVars,
getPageTitle,
prependYAML,
} from 'typedoc-plugin-markdown/dist/utils/front-matter';
Expand Down Expand Up @@ -43,6 +44,9 @@ export class DocusaurusTheme extends MarkdownTheme {
@BindOption('includeExtension')
includeExtension!: string;

@BindOption('frontmatter')
frontmatter!: FrontMatter;

constructor(renderer: Renderer) {
super(renderer);

Expand All @@ -64,7 +68,10 @@ export class DocusaurusTheme extends MarkdownTheme {

onPageEnd(page: PageEvent<DeclarationReflection>) {
if (page.contents) {
page.contents = prependYAML(page.contents, this.getYamlItems(page));
page.contents = prependYAML(
page.contents,
this.getYamlItems(page) as FrontMatterVars,
);
}
}

Expand Down Expand Up @@ -92,7 +99,7 @@ export class DocusaurusTheme extends MarkdownTheme {
);
}

getYamlItems(page: PageEvent<DeclarationReflection>): any {
getYamlItems(page: PageEvent<DeclarationReflection>): FrontMatter {
const pageId = this.getId(page);
const pageTitle = this.getTitle(page);
const sidebarLabel = this.getSidebarLabel(page);
Expand All @@ -113,9 +120,12 @@ export class DocusaurusTheme extends MarkdownTheme {
if (page.url === page.project.url && this.entryPoints.length > 1) {
items = { ...items, hide_table_of_contents: true };
}
items = { ...items, custom_edit_url: null };
if (this.frontmatter) {
items = { ...items, ...this.frontmatter };
}
return {
...items,
custom_edit_url: null,
};
}

Expand Down
13 changes: 4 additions & 9 deletions packages/docusaurus-plugin-typedoc/src/types.ts
Expand Up @@ -17,17 +17,12 @@ export interface PluginOptions {
includeExtension?: boolean;
indexSlug?: string;
theme?: string;
frontmatter: FrontMatter;
}

export interface FrontMatter {
id: string;
title: string;
slug?: string;
sidebar_label?: string;
sidebar_position?: number;
hide_title?: boolean;
hide_table_of_contents?: boolean;
}
export type FrontMatter =
| Record<string, string | boolean | number | null>
| undefined;

export interface SidebarOptions {
fullNames?: boolean;
Expand Down
Expand Up @@ -31,7 +31,7 @@ module.exports = {
src: 'img/logo.svg',
},
items: [
{
{
to: 'docs/api/',
activeBasePath: 'docs',
label: 'API',
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-typedoc/test/site/package.json
Expand Up @@ -12,8 +12,8 @@
"clear": "docusaurus clear"
},
"dependencies": {
"@docusaurus/core": "^2.0.0-beta.9",
"@docusaurus/preset-classic": "^2.0.0-beta.9",
"@docusaurus/core": "^2.0.0-beta.15",
"@docusaurus/preset-classic": "^2.0.0-beta.15",
"@mdx-js/react": "^1.6.22",
"clsx": "^1.1.1",
"react": "^17.0.2",
Expand Down

0 comments on commit 55cc7e0

Please sign in to comment.