Skip to content

Commit

Permalink
fix: Support `includeVersion' option
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Apr 21, 2023
1 parent 94e374c commit efc1876
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/typedoc-plugin-markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"prepublishOnly": "npm run lint && npm run build && npm run test",
"prebuild": "ts-node scripts/build-resources",
"build": "rm -rf dist && tsc",
"test": "jest --colors --updateSnapshot",
"test": "jest --colors",
"build-and-test": "npm run build && npm run test",
"docs": "npm run build && npm-run-all docs:*",
"docs:md-1": "typedoc --plugin typedoc-plugin-markdown --plugin typedoc-plugin-mdn-links --options ../../stubs/typedoc.json --enableFrontmatter --out ./out/md/md-1",
Expand Down
9 changes: 7 additions & 2 deletions packages/typedoc-plugin-markdown/src/partials/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DeclarationReflection, PageEvent, ProjectReflection } from 'typedoc';
import { link } from '../support/els';
import { getProjectDisplayName } from '../support/helpers';
import { escapeChars } from '../support/utils';
import { MarkdownThemeRenderContext } from '../theme-context';

Expand All @@ -10,11 +11,15 @@ export function breadcrumbs(
if (page.model) {
if (page.model.kind) {
const md: string[] = [];
const projectName = getProjectDisplayName(
page.project,
context.getOption('includeVersion'),
);
md.push(
page.url === context.modulesFile
? page.project.name
? projectName
: link(
page.project.name,
projectName,
context.relativeURL(
context.getOption('readme').endsWith('none')
? context.getOption('entryDocument')
Expand Down
10 changes: 8 additions & 2 deletions packages/typedoc-plugin-markdown/src/partials/page.title.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeclarationReflection, PageEvent, ProjectReflection } from 'typedoc';
import { getReflectionTitle } from '../support/helpers';
import { getProjectDisplayName, getReflectionTitle } from '../support/helpers';
import { MarkdownThemeRenderContext } from '../theme-context';

export function pageTitle(
Expand All @@ -8,7 +8,13 @@ export function pageTitle(
) {
const md: string[] = [];
if (page.model?.url === page.project.url) {
md.push(context.getOption('indexPageTitle') || page.project.name);
md.push(
context.getOption('indexPageTitle') ||
getProjectDisplayName(
page.project,
context.getOption('includeVersion'),
),
);
} else {
md.push(getReflectionTitle(page.model as DeclarationReflection, true));
}
Expand Down
9 changes: 0 additions & 9 deletions packages/typedoc-plugin-markdown/src/support/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import { ReflectionKind } from 'typedoc';

export const URL_PREFIX = /^(http|ftp)s?:\/\//;

export const PLURALS = {
[ReflectionKind.Class]: 'Classes',
[ReflectionKind.Property]: 'Properties',
[ReflectionKind.Enum]: 'Enumerations',
[ReflectionKind.EnumMember]: 'Enumeration members',
[ReflectionKind.Namespace]: 'Namespaces',
[ReflectionKind.TypeAlias]: 'Type aliases',
};

export const SYMBOLS_WITH_DOCUMENTS = [
ReflectionKind.Class,
ReflectionKind.Interface,
Expand Down
8 changes: 8 additions & 0 deletions packages/typedoc-plugin-markdown/src/support/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,11 @@ export function getDeclarationType(declaration: DeclarationReflection) {
}
return declaration.type;
}

export function getProjectDisplayName(
project: ProjectReflection,
includeVersion: boolean,
): string {
const version = includeVersion ? ` - v${project.packageVersion}` : '';
return `${project.name}${version}`;
}
17 changes: 0 additions & 17 deletions packages/typedoc-plugin-markdown/src/support/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { ReflectionKind } from 'typedoc';
import { PLURALS } from './constants';

export function escapeChars(str: string) {
return str
.replace(/>/g, '\\>')
Expand Down Expand Up @@ -51,20 +48,6 @@ export function camelToTitleCase(text: string) {
);
}

export function getKindPlural(kind: ReflectionKind): string {
if (kind in PLURALS) {
return PLURALS[kind as keyof typeof PLURALS];
} else {
return getKindString(kind) + 's';
}
}

export function getKindString(kind: ReflectionKind): string {
let str = ReflectionKind[kind];
str = str.replace(/(.)([A-Z])/g, (_m, a, b) => a + ' ' + b.toLowerCase());
return str;
}

export function slugify(str: string) {
return str
.toLowerCase()
Expand Down
3 changes: 2 additions & 1 deletion stubs/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"cleanOutputDir": true,
"githubPages": false,
"modifierTags": ["@navOrder"],
"logLevel": "Verbose"
"logLevel": "Verbose",
"includeVersion": true
}

0 comments on commit efc1876

Please sign in to comment.