Skip to content

Commit

Permalink
fix: added sidebar.autoConfiguration option
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed May 10, 2022
1 parent 57c7498 commit f873b32
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-typedoc/src/options.ts
Expand Up @@ -11,6 +11,7 @@ const DEFAULT_PLUGIN_OPTIONS: PluginOptions = {
indexLabel: undefined,
readmeLabel: 'Readme',
position: null,
autoConfiguration: true,
},
hideInPageTOC: true,
hideBreadcrumbs: true,
Expand Down
66 changes: 36 additions & 30 deletions packages/docusaurus-plugin-typedoc/src/theme.ts
@@ -1,3 +1,5 @@
import * as fs from 'fs';
import * as path from 'path';
import {
BindOption,
DeclarationReflection,
Expand All @@ -7,17 +9,14 @@ import {
RendererEvent,
UrlMapping,
} from 'typedoc';
import * as fs from 'fs';
import { MarkdownTheme } from 'typedoc-plugin-markdown/dist/theme';
import { getKindPlural } from 'typedoc-plugin-markdown/dist/groups';
import * as path from 'path';

import { FrontMatter, SidebarOptions } from './types';
import { MarkdownTheme } from 'typedoc-plugin-markdown/dist/theme';
import {
FrontMatterVars,
getPageTitle,
prependYAML,
} from 'typedoc-plugin-markdown/dist/utils/front-matter';
import { FrontMatter, SidebarOptions } from './types';

const CATEGORY_POSITION = {
[ReflectionKind.Module]: 1,
Expand Down Expand Up @@ -76,27 +75,29 @@ export class DocusaurusTheme extends MarkdownTheme {
}

onRendererEnd(renderer: RendererEvent) {
writeCategoryYaml(
renderer.outputDirectory,
this.sidebar.categoryLabel,
this.sidebar.position,
);

Object.keys(groupUrlsByKind(this.getUrls(renderer.project))).forEach(
(group) => {
const kind = parseInt(group);
const mapping = this.mappings.find((mapping) =>
mapping.kind.includes(kind),
);
if (mapping) {
writeCategoryYaml(
renderer.outputDirectory + '/' + mapping.directory,
getKindPlural(kind),
CATEGORY_POSITION[kind],
if (this.sidebar.autoConfiguration) {
writeCategoryYaml(
renderer.outputDirectory,
this.sidebar.categoryLabel,
this.sidebar.position,
);

Object.keys(groupUrlsByKind(this.getUrls(renderer.project))).forEach(
(group) => {
const kind = parseInt(group);
const mapping = this.mappings.find((mapping) =>
mapping.kind.includes(kind),
);
}
},
);
if (mapping) {
writeCategoryYaml(
renderer.outputDirectory + '/' + mapping.directory,
getKindPlural(kind),
CATEGORY_POSITION[kind],
);
}
},
);
}
}

getYamlItems(page: PageEvent<DeclarationReflection>): FrontMatter {
Expand All @@ -111,12 +112,17 @@ export class DocusaurusTheme extends MarkdownTheme {
if (page.url === this.entryDocument) {
items = { ...items, slug: this.getSlug() };
}
if (sidebarLabel && sidebarLabel !== pageTitle) {
items = { ...items, sidebar_label: sidebarLabel as string };
}
if (sidebarPosition) {
items = { ...items, sidebar_position: parseFloat(sidebarPosition) };

if (this.sidebar.autoConfiguration) {
console.log('config', this.sidebar.autoConfiguration);
if (sidebarLabel && sidebarLabel !== pageTitle) {
items = { ...items, sidebar_label: sidebarLabel as string };
}
if (sidebarPosition) {
items = { ...items, sidebar_position: parseFloat(sidebarPosition) };
}
}

if (page.url === page.project.url && this.entryPoints.length > 1) {
items = { ...items, hide_table_of_contents: true };
}
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-typedoc/src/types.ts
Expand Up @@ -32,6 +32,7 @@ export interface SidebarOptions {
indexLabel?: string;
readmeLabel?: string;
position: number | null;
autoConfiguration: boolean;
}

export interface SidebarCategory {
Expand Down
Expand Up @@ -15,9 +15,10 @@ const config = {
entryPoints: '../../../typedoc-plugin-markdown/test/stubs/src/index.ts',
tsconfig: '../../../typedoc-plugin-markdown/test/stubs/tsconfig.json',
sidebar: {
sidebarFile: null,
autoConfiguration: true,
position: 0,
},
cleanOutputDir: true,
},
],
],
Expand Down

0 comments on commit f873b32

Please sign in to comment.