Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom footer string when hideDeclaration is true #2562

Merged
merged 3 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/internationalization/translatable.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ footer {
padding-bottom: 1rem;
max-height: 3.5rem;
}
.tsd-generator {
footer > p {
margin: 0 1em;
}

Expand Down