Skip to content

Commit

Permalink
fix(core): remove header readme label
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Apr 28, 2024
1 parent 4439f93 commit 45781b8
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 74 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-worms-provide.md
@@ -0,0 +1,5 @@
---
"typedoc-plugin-markdown": patch
---

- remove header readme labell
1 change: 0 additions & 1 deletion docs/pages/docs/options.mdx
Expand Up @@ -513,7 +513,6 @@ Only keys that require translation need to be added to the object.
{
"textContentMappings": {
"header.title": "{projectName} {version}",
"header.readme": "Readme",
"header.docs": "Docs",
"breadcrumbs.home": "{projectName} {version}",
"title.indexPage": "{projectName} {version}",
Expand Down
Expand Up @@ -205,7 +205,6 @@ export interface PluginOptions {
*/
export interface TextContentMappings {
'header.title': string;
'header.readme': string;
'header.docs': string;
'breadcrumbs.home': string;
'title.indexPage': string;
Expand Down
Expand Up @@ -2,7 +2,6 @@ import { KIND_DEFAULTS } from './kind-defaults';

export const TEXT_MAPPING_DEFAULTS = {
'header.title': '{projectName} {version}',
'header.readme': 'Readme',
'header.docs': 'Docs',
'breadcrumbs.home': '{projectName} {version}',
'title.indexPage': '{projectName} {version}',
Expand Down
Expand Up @@ -39,15 +39,13 @@ export function header(this: MarkdownThemeContext): string {
.replace(/\s+/g, ' ')
.trim();

const readmeLabel = this.getText('header.readme');
const indexLabel = this.getText('header.docs');

if (this.page.url === entryFileName) {
md.push(title);
} else {
md.push(link(title, this.getRelativeUrl(entryFileName)));
}
md.push('•');

const preserveReadme =
Boolean(this.page.project.readme) &&
Expand All @@ -63,33 +61,24 @@ export function header(this: MarkdownThemeContext): string {
false;

if (preserveReadme) {
const links: string[] = [];
const readMeUrl = useEntryModule
? `readme_${fileExtension}`
: entryFileName;

if (this.page.url === readMeUrl) {
links.push(readmeLabel);
} else {
links.push(link(readmeLabel, this.getRelativeUrl(readMeUrl)));
}

links.push('\\|');

const indexUrl = useEntryModule ? entryFileName : this.page.project.url;

if (this.page.url === readMeUrl) {
links.push(link(indexLabel, this.getRelativeUrl(indexUrl || '')));
} else {
links.push(indexLabel);
if (indexLabel) {
if (this.page.url === readMeUrl) {
md.push(link(indexLabel, this.getRelativeUrl(indexUrl || '')));
} else {
md.push(indexLabel);
}
}

md.push(`${links.join(' ')}`);
} else {
md.push(indexLabel);
}

return `${md.join(' ')}\n\n***\n`;
return `${md.join(' ')}\n\n***\n`;
};

const getPackageHeader = () => {
Expand All @@ -103,7 +92,6 @@ export function header(this: MarkdownThemeContext): string {

const md: string[] = [];

const readmeLabel = this.getText('header.readme');
const indexLabel = this.getText('header.docs');

const fileExtension = this.options.getValue('fileExtension');
Expand All @@ -121,36 +109,22 @@ export function header(this: MarkdownThemeContext): string {
md.push(link(packageItemName, this.getRelativeUrl(packageEntryFile)));
}

md.push('•');

const preservePackageReadme =
Boolean(packageItem.readme) && !this.options.getValue('mergeReadme');

if (preservePackageReadme) {
const links: string[] = [];

if (this.page.url === packageEntryFile) {
links.push(readmeLabel);
} else {
links.push(link(readmeLabel, this.getRelativeUrl(packageEntryFile)));
if (indexLabel) {
if (this.page.url === packageEntryFile) {
md.push(link(indexLabel, this.getRelativeUrl(packageItem.url || '')));
} else {
md.push(indexLabel);
}
}

links.push('\\|');

if (this.page.url === packageEntryFile) {
links.push(
link(indexLabel, this.getRelativeUrl(packageItem.url || '')),
);
} else {
links.push(indexLabel);
}

md.push(`${links.join(' ')}`);
} else {
md.push(indexLabel);
}

return `${md.join(' ')}\n\n***\n`;
return `${md.join(' ')}\n\n***\n`;
};

function findPackage(model: DeclarationReflection | ProjectReflection) {
Expand Down
Expand Up @@ -3,8 +3,7 @@ module.exports = {
...baseOptions,
textContentMappings: {
'header.title': 'My API - {version}',
'header.readme': 'My Readme',
'header.docs': 'Docs',
'header.docs': 'API',
'title.indexPage': ':tada: Custom Index Title',
'title.memberPage': '{name}',
'title.modulePage': '{kind} - {name}',
Expand Down
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EntryFiles should get entry module: (Output File Strategy "members") (Option Group "1") 1`] = `
"@scope/entryfile • [Readme](readme_.mdx) \\| Docs
"@scope/entryfile • Docs
***
Expand Down Expand Up @@ -31,7 +31,7 @@ exports[`EntryFiles should get entry module: (Output File Strategy "members") (O
`;

exports[`EntryFiles should get module member for members: (Output File Strategy "members") (Option Group "1") 1`] = `
"[@scope/entryfile](../../README.mdx) • [Readme](../../readme_.mdx) \\| Docs
"[@scope/entryfile](../../README.mdx) • Docs
***
Expand Down Expand Up @@ -73,7 +73,7 @@ exports[`EntryFiles should get module member for members: (Output File Strategy
`;

exports[`EntryFiles should get readme file: (Output File Strategy "members") (Option Group "1") 1`] = `
"[@scope/entryfile](README.mdx) • Readme \\| [Docs](README.mdx)
"[@scope/entryfile](README.mdx) • [Docs](README.mdx)
***
Expand Down
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Groups should compile basic module index page: (Output File Strategy "members") (Option Group "1") 1`] = `
"[typedoc-stubs](../index.md) • [Readme](../index.md) \\| Docs
"[typedoc-stubs](../index.md) • Docs
***
Expand Down Expand Up @@ -74,7 +74,7 @@ A basic module
`;

exports[`Groups should compile basic module index page: (Output File Strategy "modules") (Option Group "1") 1`] = `
"[typedoc-stubs](index.md) • [Readme](index.md) \\| Docs
"[typedoc-stubs](index.md) • Docs
***
Expand Down Expand Up @@ -254,7 +254,7 @@ A basic module
`;

exports[`Groups should compile categories group page: (Output File Strategy "modules") (Option Group "1") 1`] = `
"[typedoc-stubs](index.md) • [Readme](index.md) \\| Docs
"[typedoc-stubs](index.md) • Docs
***
Expand Down Expand Up @@ -384,7 +384,7 @@ A module that contains categories
`;

exports[`Groups should compile categories index page: (Output File Strategy "members") (Option Group "1") 1`] = `
"[typedoc-stubs](../index.md) • [Readme](../index.md) \\| Docs
"[typedoc-stubs](../index.md) • Docs
***
Expand Down Expand Up @@ -471,7 +471,7 @@ A module that contains categories
`;

exports[`Groups should compile custom groups index page: (Output File Strategy "members") (Option Group "1") 1`] = `
"[typedoc-stubs](../index.md) • [Readme](../index.md) \\| Docs
"[typedoc-stubs](../index.md) • Docs
***
Expand Down Expand Up @@ -544,7 +544,7 @@ Default grouping
`;

exports[`Groups should compile index page for project: (Output File Strategy "members") (Option Group "1") 1`] = `
"[typedoc-stubs](index.md) • [Readme](index.md) \\| Docs
"[typedoc-stubs](index.md) • Docs
***
Expand Down Expand Up @@ -586,7 +586,7 @@ exports[`Groups should compile index page for project: (Output File Strategy "me
`;

exports[`Groups should compile index page for project: (Output File Strategy "modules") (Option Group "1") 1`] = `
"[typedoc-stubs](index.md) • [Readme](index.md) \\| Docs
"[typedoc-stubs](index.md) • Docs
***
Expand Down Expand Up @@ -628,7 +628,7 @@ exports[`Groups should compile index page for project: (Output File Strategy "mo
`;

exports[`Groups should compile module index for a namespace: (Output File Strategy "members") (Option Group "1") 1`] = `
"[typedoc-stubs](../../../index.md) • [Readme](../../../index.md) \\| Docs
"[typedoc-stubs](../../../index.md) • Docs
***
Expand Down Expand Up @@ -667,7 +667,7 @@ exports[`Groups should compile module index for a namespace: (Output File Strate
`;

exports[`Groups should compile module index for a namespace: (Output File Strategy "modules") (Option Group "1") 1`] = `
"[typedoc-stubs](../../../index.md) • [Readme](../../../index.md) \\| Docs
"[typedoc-stubs](../../../index.md) • Docs
***
Expand Down Expand Up @@ -709,7 +709,7 @@ exports[`Groups should compile module index for a namespace: (Output File Strate
`;

exports[`Groups should compile module index with namespaces index page: (Output File Strategy "members") (Option Group "1") 1`] = `
"[typedoc-stubs](../index.md) • [Readme](../index.md) \\| Docs
"[typedoc-stubs](../index.md) • Docs
***
Expand Down Expand Up @@ -839,7 +839,7 @@ A module that contains namespaces
`;

exports[`Groups should compile module index with namespaces index page: (Output File Strategy "modules") (Option Group "1") 1`] = `
"[typedoc-stubs](../index.md) • [Readme](../index.md) \\| Docs
"[typedoc-stubs](../index.md) • Docs
***
Expand Down Expand Up @@ -1081,7 +1081,7 @@ A module that contains namespaces
`;

exports[`Groups should compile readme for a project: (Output File Strategy "modules") (Option Group "1") 1`] = `
"typedoc-stubs • Readme \\| [Docs](modules.md)
"typedoc-stubs • [Docs](modules.md)
***
Expand All @@ -1098,7 +1098,7 @@ Some text.
`;

exports[`Groups should compile references group page: (Output File Strategy "modules") (Option Group "1") 1`] = `
"[typedoc-stubs](index.md) • [Readme](index.md) \\| Docs
"[typedoc-stubs](index.md) • Docs
***
Expand Down Expand Up @@ -1176,7 +1176,7 @@ Renames and re-exports [defaultFunction](has-references.md#defaultfunction)
`;

exports[`Groups should compile references index page: (Output File Strategy "members") (Option Group "1") 1`] = `
"[typedoc-stubs](../index.md) • [Readme](../index.md) \\| Docs
"[typedoc-stubs](../index.md) • Docs
***
Expand Down
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Packages should compile index for a single package: (Output File Strategy "members") (Option Group "1") 1`] = `
"@scope/package-1 v1.0.0 • Readme \\| [Docs](packages.md)
"@scope/package-1 v1.0.0 • [Docs](packages.md)
***
Expand All @@ -12,7 +12,7 @@ Readme content
`;

exports[`Packages should compile index page for packages: (Output File Strategy "members") (Option Group "1") 1`] = `
"[packages-example](index.md) • [Readme](index.md) \\| Docs
"[packages-example](index.md) • Docs
***
Expand All @@ -32,7 +32,7 @@ exports[`Packages should compile index page for packages: (Output File Strategy
`;

exports[`Packages should compile index page for packages: (Output File Strategy "members") (Option Group "1") 2`] = `
"[@scope/package-1 v1.0.0](index.md) • [Readme](index.md) \\| Docs
"[@scope/package-1 v1.0.0](index.md) • Docs
***
Expand All @@ -51,7 +51,7 @@ Some more comments for package-1
`;

exports[`Packages should compile index page for packages: (Output File Strategy "members") (Option Group "1") 3`] = `
"[package-2 v1.0.0](index.md) • [Readme](index.md) \\| Docs
"[package-2 v1.0.0](index.md) • Docs
***
Expand All @@ -78,7 +78,7 @@ exports[`Packages should compile member for relative entry module package: (Outp
`;

exports[`Packages should compile member page for a single package: (Output File Strategy "members") (Option Group "1") 1`] = `
"[@scope/package-1 v1.0.0](../README.md) • [Readme](../README.md) \\| Docs
"[@scope/package-1 v1.0.0](../README.md) • Docs
***
Expand All @@ -95,7 +95,7 @@ exports[`Packages should compile member page for a single package: (Output File
`;

exports[`Packages should compile member page for packages: (Output File Strategy "members") (Option Group "1") 1`] = `
"[@scope/package-1 v1.0.0](../index.md) • [Readme](../index.md) \\| Docs
"[@scope/package-1 v1.0.0](../index.md) • Docs
***
Expand Down Expand Up @@ -129,7 +129,7 @@ exports[`Packages should compile member page for packages: (Output File Strategy
`;

exports[`Packages should compile readmes for a packages: (Output File Strategy "members") (Option Group "1") 1`] = `
"packages-example • Readme \\| [Docs](packages.md)
"packages-example • [Docs](packages.md)
***
Expand All @@ -146,7 +146,7 @@ Some text.
`;

exports[`Packages should compile readmes for a packages: (Output File Strategy "members") (Option Group "1") 2`] = `
"@scope/package-1 v1.0.0 • Readme \\| [Docs](globals.md)
"@scope/package-1 v1.0.0 • [Docs](globals.md)
***
Expand Down

0 comments on commit 45781b8

Please sign in to comment.