Skip to content

Commit afd77e6

Browse files
committed
Finish customJs feature
1 parent 12ba3d5 commit afd77e6

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Features
44

5+
- Added `customJs` option to include a script tag in generated HTML output, #2650.
56
- Added `markdownLinkExternal` option to treat `http[s]://` links in markdown documents and comments as external to be opened in a new tab, #2679.
67
- Added `navigation.excludeReferences` option to prevent re-exports from appearing in the left hand navigation, #2685.
78

@@ -13,6 +14,10 @@
1314
- The `alphabetical` and `alphabetical-ignoring-documents` sort options now use `localeCompare` to sort, #2684.
1415
- Fixed incorrect placement of parameter default values in some signatures with a `this` parameter, #2698.
1516

17+
### Thanks!
18+
19+
- @Aryakoste
20+
1621
## v0.26.6 (2024-08-18)
1722

1823
### Features

src/lib/internationalization/translatable.ts

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export const translatable = {
131131

132132
// output plugins
133133
custom_css_file_0_does_not_exist: `Custom CSS file at {0} does not exist`,
134+
custom_js_file_0_does_not_exist: `Custom JavaScript file at {0} does not exist`,
134135
unsupported_highlight_language_0_not_highlighted_in_comment_for_1: `Unsupported highlight language {0} will not be highlighted in comment for {1}`,
135136
unloaded_language_0_not_highlighted_in_comment_for_1: `Code block with language {0} will not be highlighted in comment for {1} as it was not included in the highlightLanguages option`,
136137
yaml_frontmatter_not_an_object: `Expected YAML frontmatter to be an object`,

src/lib/output/plugins/AssetsPlugin.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import { join } from "path";
1313
*/
1414
@Component({ name: "assets" })
1515
export class AssetsPlugin extends RendererComponent {
16-
/** @internal */
1716
@Option("customCss")
18-
accessor customCss!: string;
17+
private accessor customCss!: string;
18+
19+
@Option("customJs")
20+
private accessor customJs!: string;
1921

2022
getTranslatedStrings() {
2123
return {
@@ -47,6 +49,18 @@ export class AssetsPlugin extends RendererComponent {
4749
);
4850
}
4951
}
52+
53+
if (this.customJs) {
54+
if (existsSync(this.customJs)) {
55+
copySync(this.customJs, join(dest, "custom.js"));
56+
} else {
57+
this.application.logger.error(
58+
this.application.i18n.custom_js_file_0_does_not_exist(
59+
this.customJs,
60+
),
61+
);
62+
}
63+
}
5064
}
5165

5266
/**

src/lib/output/themes/default/layouts/default.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ export const defaultLayout = (
2828
{context.options.getValue("customCss") && (
2929
<link rel="stylesheet" href={context.relativeURL("assets/custom.css", true)} />
3030
)}
31+
<script defer src={context.relativeURL("assets/main.js", true)}></script>
3132
{context.options.getValue("customJs") && (
3233
<script defer src={context.relativeURL("assets/custom.js", true)}></script>
3334
)}
34-
<script defer src={context.relativeURL("assets/main.js", true)}></script>
3535
<script async src={context.relativeURL("assets/icons.js", true)} id="tsd-icons-script"></script>
3636
<script async src={context.relativeURL("assets/search.js", true)} id="tsd-search-script"></script>
3737
<script async src={context.relativeURL("assets/navigation.js", true)} id="tsd-nav-script"></script>

0 commit comments

Comments
 (0)