From 2e5959cc8009bb38832d2108fb1994c14e81b5d9 Mon Sep 17 00:00:00 2001 From: tgreyuk Date: Mon, 29 Apr 2024 21:39:16 +0100 Subject: [PATCH] feat(core): added footer partial and footer.text mappings --- .changeset/fluffy-teachers-search.md | 5 +++++ .../src/options/declarations.ts | 9 ++++----- .../src/options/option-types.ts | 1 + .../text-mappings/text-mapping-defaults.ts | 1 + .../src/theme/resources/index.ts | 9 ++++++++- .../src/theme/resources/partials/page.footer.ts | 9 +++++++++ .../src/theme/resources/templates/project.ts | 2 ++ .../src/theme/resources/templates/read-me.ts | 2 ++ .../src/theme/resources/templates/reflection.ts | 2 ++ .../test/fixtures/typedoc.text-options.cjs | 1 + .../test/specs/__snapshots__/text.spec.ts.snap | 16 ++++++++++++++++ 11 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 .changeset/fluffy-teachers-search.md create mode 100644 packages/typedoc-plugin-markdown/src/theme/resources/partials/page.footer.ts diff --git a/.changeset/fluffy-teachers-search.md b/.changeset/fluffy-teachers-search.md new file mode 100644 index 000000000..a0dad7f83 --- /dev/null +++ b/.changeset/fluffy-teachers-search.md @@ -0,0 +1,5 @@ +--- +"typedoc-plugin-markdown": patch +--- + +- Added footer partial and footer.text mappings diff --git a/packages/typedoc-plugin-markdown/src/options/declarations.ts b/packages/typedoc-plugin-markdown/src/options/declarations.ts index d3ec1cdef..daa197b29 100644 --- a/packages/typedoc-plugin-markdown/src/options/declarations.ts +++ b/packages/typedoc-plugin-markdown/src/options/declarations.ts @@ -398,11 +398,10 @@ export const indexFormat: Partial = { * * Keys are categorised with the following namespace conventions: * - * - `header.*` defines text in the page header (if displayed). - * - `breadcrumbs.*` defines breadcrumbs in page header (if displayed). - * - `title.*` defines text in main page titles. - * - `label.*` other text in page content, including content headings and table headers. - * - `kind.*` defines text mappings to TypeDoc's `ReflectionKind` definitions. + * - `header.*`, `breadcrumbs.*`,`footer.*`: Text in main page elements (if displayed). + * - `title.*`: Text in main page titles. + * - `label.*` Text in page content, including content headings and table headers. + * - `kind.*` Text mappings to TypeDoc's `ReflectionKind` definitions. * * Only keys that require translation need to be added to the object. * diff --git a/packages/typedoc-plugin-markdown/src/options/option-types.ts b/packages/typedoc-plugin-markdown/src/options/option-types.ts index 49e654f58..340617d07 100644 --- a/packages/typedoc-plugin-markdown/src/options/option-types.ts +++ b/packages/typedoc-plugin-markdown/src/options/option-types.ts @@ -207,6 +207,7 @@ export interface TextContentMappings { 'header.title': string; 'header.docs': string; 'breadcrumbs.home': string; + 'footer.text': string; 'title.indexPage': string; 'title.modulePage': string; 'title.memberPage': string; diff --git a/packages/typedoc-plugin-markdown/src/options/text-mappings/text-mapping-defaults.ts b/packages/typedoc-plugin-markdown/src/options/text-mappings/text-mapping-defaults.ts index 4d4b0c796..837467577 100644 --- a/packages/typedoc-plugin-markdown/src/options/text-mappings/text-mapping-defaults.ts +++ b/packages/typedoc-plugin-markdown/src/options/text-mappings/text-mapping-defaults.ts @@ -4,6 +4,7 @@ export const TEXT_MAPPING_DEFAULTS = { 'header.title': '{projectName} {version}', 'header.docs': 'Docs', 'breadcrumbs.home': '{projectName} {version}', + 'footer.text': '', 'title.indexPage': '{projectName} {version}', 'title.modulePage': '{name}', 'title.memberPage': '{kind}: {name}', diff --git a/packages/typedoc-plugin-markdown/src/theme/resources/index.ts b/packages/typedoc-plugin-markdown/src/theme/resources/index.ts index bbb2a2d71..0404ba779 100644 --- a/packages/typedoc-plugin-markdown/src/theme/resources/index.ts +++ b/packages/typedoc-plugin-markdown/src/theme/resources/index.ts @@ -73,9 +73,10 @@ import { typeDeclarationTable } from './partials/member.typeDeclarationTable'; import { typeParametersList } from './partials/member.typeParametersList'; import { typeParametersTable } from './partials/member.typeParametersTable'; import { breadcrumbs } from './partials/page.breadcrumbs'; +import { footer } from './partials/page.footer'; import { header } from './partials/page.header'; import { packagesIndex } from './partials/page.packagesIndex'; -import { pageTitle } from './partials/page.pageTtitle'; +import { pageTitle } from './partials/page.pageTitle'; import { arrayType } from './partials/type.array'; import { conditionalType } from './partials/type.conditional'; import { indexAccessType } from './partials/type.index-access'; @@ -434,6 +435,12 @@ There is no association list partial for properties as these are handled as a st * @category Page Partials */ breadcrumbs: () => breadcrumbs.apply(context, []) as string, + /** + * + * + * @category Page Partials + */ + footer: () => footer.apply(context, []) as string, /** * * diff --git a/packages/typedoc-plugin-markdown/src/theme/resources/partials/page.footer.ts b/packages/typedoc-plugin-markdown/src/theme/resources/partials/page.footer.ts new file mode 100644 index 000000000..1bf38cff5 --- /dev/null +++ b/packages/typedoc-plugin-markdown/src/theme/resources/partials/page.footer.ts @@ -0,0 +1,9 @@ +import { MarkdownThemeContext } from '@plugin/theme'; + +/** + * @category Page Partials + */ +export function footer(this: MarkdownThemeContext): string { + const text = this.getText('footer.text'); + return text ? `***\n\n${text}` : ``; +} diff --git a/packages/typedoc-plugin-markdown/src/theme/resources/templates/project.ts b/packages/typedoc-plugin-markdown/src/theme/resources/templates/project.ts index da39ea9c9..43f2ec6e9 100644 --- a/packages/typedoc-plugin-markdown/src/theme/resources/templates/project.ts +++ b/packages/typedoc-plugin-markdown/src/theme/resources/templates/project.ts @@ -58,6 +58,8 @@ export function project(this: MarkdownThemeContext) { md.push(this.partials.body(model, { headingLevel: 2 })); } + md.push(this.partials.footer()); + md.push(this.hook('index.page.end').join('\n')); return md.join('\n\n'); diff --git a/packages/typedoc-plugin-markdown/src/theme/resources/templates/read-me.ts b/packages/typedoc-plugin-markdown/src/theme/resources/templates/read-me.ts index 43b065939..0f1813449 100644 --- a/packages/typedoc-plugin-markdown/src/theme/resources/templates/read-me.ts +++ b/packages/typedoc-plugin-markdown/src/theme/resources/templates/read-me.ts @@ -21,5 +21,7 @@ export function readme(this: MarkdownThemeContext) { md.push(this.partials.commentParts(model.readme as CommentDisplayPart[])); } + md.push(this.partials.footer()); + return md.join('\n\n'); } diff --git a/packages/typedoc-plugin-markdown/src/theme/resources/templates/reflection.ts b/packages/typedoc-plugin-markdown/src/theme/resources/templates/reflection.ts index 787c0d484..4d5462744 100644 --- a/packages/typedoc-plugin-markdown/src/theme/resources/templates/reflection.ts +++ b/packages/typedoc-plugin-markdown/src/theme/resources/templates/reflection.ts @@ -40,6 +40,8 @@ export function reflection(this: MarkdownThemeContext) { md.push(this.partials.member(model, { headingLevel: 1 })); } + md.push(this.partials.footer()); + md.push(this.hook('page.end').join('\n')); return md.join('\n\n'); diff --git a/packages/typedoc-plugin-markdown/test/fixtures/typedoc.text-options.cjs b/packages/typedoc-plugin-markdown/test/fixtures/typedoc.text-options.cjs index f4997cef5..220f27304 100644 --- a/packages/typedoc-plugin-markdown/test/fixtures/typedoc.text-options.cjs +++ b/packages/typedoc-plugin-markdown/test/fixtures/typedoc.text-options.cjs @@ -4,6 +4,7 @@ module.exports = { textContentMappings: { 'header.title': 'My API - {version}', 'header.docs': 'API', + 'footer.text': 'Copyright Test', 'title.indexPage': ':tada: Custom Index Title', 'title.memberPage': '{name}', 'title.modulePage': '{kind} - {name}', diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/text.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/text.spec.ts.snap index 86876b616..68320b111 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/text.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/text.spec.ts.snap @@ -11,6 +11,10 @@ exports[`Text should get translations for index page: (Output File Strategy "mem - [module-1](module-1/README.md) - [module-2](module-2/README.md) + +*** + +Copyright Test " `; @@ -34,6 +38,10 @@ exports[`Text should get translations for member page: (Output File Strategy "me | Event! | Type | | :------ | :------ | | \`someEvent\` | \`MouseEvent\` | + +*** + +Copyright Test " `; @@ -51,6 +59,10 @@ exports[`Text should get translations for module page: (Output File Strategy "me ### 多变的 - [SomeInterface](interfaces/SomeInterface.md) + +*** + +Copyright Test " `; @@ -68,6 +80,10 @@ exports[`Text should get translations for modules page: (Output File Strategy "m ### constA > \`const\` **constA**: \`true\` = \`true\` + +*** + +Copyright Test " `;