Skip to content

Commit

Permalink
Finish customJs feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Sep 6, 2024
1 parent 12ba3d5 commit afd77e6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Features

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

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

### Thanks!

- @Aryakoste

## v0.26.6 (2024-08-18)

### Features
Expand Down
1 change: 1 addition & 0 deletions src/lib/internationalization/translatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const translatable = {

// output plugins
custom_css_file_0_does_not_exist: `Custom CSS file at {0} does not exist`,
custom_js_file_0_does_not_exist: `Custom JavaScript file at {0} does not exist`,
unsupported_highlight_language_0_not_highlighted_in_comment_for_1: `Unsupported highlight language {0} will not be highlighted in comment for {1}`,
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`,
yaml_frontmatter_not_an_object: `Expected YAML frontmatter to be an object`,
Expand Down
18 changes: 16 additions & 2 deletions src/lib/output/plugins/AssetsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { join } from "path";
*/
@Component({ name: "assets" })
export class AssetsPlugin extends RendererComponent {
/** @internal */
@Option("customCss")
accessor customCss!: string;
private accessor customCss!: string;

@Option("customJs")
private accessor customJs!: string;

getTranslatedStrings() {
return {
Expand Down Expand Up @@ -47,6 +49,18 @@ export class AssetsPlugin extends RendererComponent {
);
}
}

if (this.customJs) {
if (existsSync(this.customJs)) {
copySync(this.customJs, join(dest, "custom.js"));
} else {
this.application.logger.error(
this.application.i18n.custom_js_file_0_does_not_exist(
this.customJs,
),
);
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lib/output/themes/default/layouts/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export const defaultLayout = (
{context.options.getValue("customCss") && (
<link rel="stylesheet" href={context.relativeURL("assets/custom.css", true)} />
)}
<script defer src={context.relativeURL("assets/main.js", true)}></script>
{context.options.getValue("customJs") && (
<script defer src={context.relativeURL("assets/custom.js", true)}></script>
)}
<script defer src={context.relativeURL("assets/main.js", true)}></script>
<script async src={context.relativeURL("assets/icons.js", true)} id="tsd-icons-script"></script>
<script async src={context.relativeURL("assets/search.js", true)} id="tsd-search-script"></script>
<script async src={context.relativeURL("assets/navigation.js", true)} id="tsd-nav-script"></script>
Expand Down

0 comments on commit afd77e6

Please sign in to comment.