Skip to content

Commit

Permalink
Merge pull request #2562 from Aryakoste/custom-footer-string
Browse files Browse the repository at this point in the history
Custom footer string when hideDeclaration is true
  • Loading branch information
Gerrit0 committed May 5, 2024
2 parents c065b3f + 3c532e4 commit 7f00494
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 21 deletions.
4 changes: 4 additions & 0 deletions src/lib/internationalization/translatable.ts
Expand Up @@ -249,6 +249,10 @@ export const translatable = {
help_gaID:
"Set the Google Analytics tracking ID and activate tracking code.",
help_hideGenerator: "Do not print the TypeDoc link at the end of the page.",
help_customFooterHtml:
"Do not print the TypeDoc link at the end of the page.",
help_customFooterHtmlDisableWrapper:
"If set, disables the wrapper element for customFooterHtml.",
help_hideParameterTypesInTitle:
"Hides parameter types in signature titles for easier scanning.",
help_cacheBust: "Include the generation time in links to static assets.",
Expand Down
55 changes: 35 additions & 20 deletions src/lib/output/themes/default/partials/footer.tsx
Expand Up @@ -3,33 +3,48 @@ import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";

export function footer(context: DefaultThemeRenderContext) {
const hideGenerator = context.options.getValue("hideGenerator");
if (hideGenerator) return;
let generatorDisplay = <></>;
if (hideGenerator === false) {
const message = context.i18n.theme_generated_using_typedoc();

const message = context.i18n.theme_generated_using_typedoc();
// Only handles one occurrence, but that's all I expect...
const index = message.indexOf("TypeDoc");
if (index == -1) {
generatorDisplay = <p class="tsd-generator">{message}</p>;
} else {
const pre = message.substring(0, index);
const post = message.substring(index + "TypeDoc".length);
generatorDisplay = (
<p class="tsd-generator">
{pre}
<a href="https://typedoc.org/" target="_blank">
TypeDoc
</a>
{post}
</p>
);
}
}

// Only handles one occurrence, but that's all I expect...
const index = message.indexOf("TypeDoc");
let display: JSX.Element;
if (index == -1) {
display = <p class="tsd-generator">{message}</p>;
} else {
const pre = message.substring(0, index);
const post = message.substring(index + "TypeDoc".length);
display = (
<p class="tsd-generator">
{pre}
<a href="https://typedoc.org/" target="_blank">
TypeDoc
</a>
{post}
</p>
);
const customFooterHtml = context.options.getValue("customFooterHtml");
let customFooterDisplay = <></>;
if (customFooterHtml) {
if (context.options.getValue("customFooterHtmlDisableWrapper")) {
customFooterDisplay = <JSX.Raw html={customFooterHtml} />;
} else {
customFooterDisplay = (
<p>
<JSX.Raw html={customFooterHtml} />
</p>
);
}
}

return (
<footer>
{context.hook("footer.begin")}
{hideGenerator || display}
{generatorDisplay}
{customFooterDisplay}
{context.hook("footer.end")}
</footer>
);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/utils/options/declaration.ts
Expand Up @@ -164,6 +164,8 @@ export interface TypeDocOptionMap {
cacheBust: boolean;
gaID: string;
hideGenerator: boolean;
customFooterHtml: string;
customFooterHtmlDisableWrapper: boolean;
hideParameterTypesInTitle: boolean;
searchInComments: boolean;
searchInDocuments: boolean;
Expand Down
10 changes: 10 additions & 0 deletions src/lib/utils/options/sources/typedoc.ts
Expand Up @@ -441,6 +441,16 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
help: (i18n) => i18n.help_hideGenerator(),
type: ParameterType.Boolean,
});
options.addDeclaration({
name: "customFooterHtml",
help: (i18n) => i18n.help_customFooterHtml(),
type: ParameterType.String,
});
options.addDeclaration({
name: "customFooterHtmlDisableWrapper",
help: (i18n) => i18n.help_customFooterHtmlDisableWrapper(),
type: ParameterType.Boolean,
});
options.addDeclaration({
name: "hideParameterTypesInTitle",
help: (i18n) => i18n.help_hideParameterTypesInTitle(),
Expand Down
2 changes: 1 addition & 1 deletion static/style.css
Expand Up @@ -329,7 +329,7 @@ footer {
padding-bottom: 1rem;
max-height: 3.5rem;
}
.tsd-generator {
footer > p {
margin: 0 1em;
}

Expand Down

0 comments on commit 7f00494

Please sign in to comment.