Skip to content

Commit

Permalink
Remove --gaId option
Browse files Browse the repository at this point in the history
Closes #2600
  • Loading branch information
Gerrit0 committed Jun 21, 2024
1 parent 2dde2e9 commit 1b55285
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 70 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Removed `--includes` option, use the `@document` tag instead.
- Removed `--stripYamlFrontmatter` option, TypeDoc will always do this now.
- Renamed the `--htmlLang` option to `--lang`.
- Removed the `--gaId` option for Google Analytics integration and corresponding `analytics` theme member, #2600.
- All function-likes may now have comments directly attached to them. This is a change from previous versions of TypeDoc where functions comments
were always moved down to the signature level. This mostly worked, but caused problems with type aliases, so was partially changed in 0.25.13.
This change was extended to apply not only to type aliases, but also other function-likes declared with variables and callable properties.
Expand Down
42 changes: 17 additions & 25 deletions internal-docs/custom-themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,28 @@ export function load(app: Application) {
}
```

This isn't very interesting since it exactly duplicates the default theme. Most themes need to adjust the templates
in some way. This can be done by providing them class which returns a different context class. Say we wanted to replace
TypeDoc's default analytics helper with one that uses [Open Web Analytics](https://www.openwebanalytics.com/) instead of
Google Analytics. This could be done with the following theme:
This isn't very interesting since it exactly duplicates the default theme.
Most themes need to adjust the templates in some way. This can be done by
providing them class which returns a different context class. Say we wanted
to replace TypeDoc's default footer with one that mentioned your copyright.
This could be done with the following theme.

In this case, it would probably be better to add this content using a render
hook for `footer.begin` or `footer.end`, but it can be done in this way as well.

```tsx
import { Application, DefaultTheme, PageEvent, JSX, Reflection } from "typedoc";

const script = `
(function() {
var _owa = document.createElement('script'); _owa.type = 'text/javascript';
_owa.async = true; _owa.src = '${site}' + '/modules/base/js/owa.tracker-combined-min.js';
var _owa_s = document.getElementsByTagName('script')[0]; _owa_s.parentNode.insertBefore(_owa,
_owa_s);
}());
`.trim();

class MyThemeContext extends DefaultThemeRenderContext {
// Important: If you use `this`, this function MUST be bound! Template functions are free
// to destructure the context object to only grab what they care about.
override analytics = () => {
// Reusing existing option rather than declaring our own for brevity
if (!this.options.isSet("gaId")) return;

const site = this.options.getValue("gaId");

// Important: If you use `this`, this function MUST be bound! Template functions
// are free to destructure the context object to only grab what they care about.
override footer = (context) => {
return (
<script>
<JSX.Raw html={script} />
</script>
<footer>
{context.hook("footer.begin", context)}
Copyright 2024
{context.hook("footer.end", context)}
</footer>
);
};
}
Expand All @@ -62,7 +54,7 @@ export function load(app: Application) {
}
```

## Hooks (v0.22.8+)
## Hooks

When rendering themes, TypeDoc's default theme will call several functions to allow plugins to inject HTML
into a page without completely overwriting a theme. Hooks live on the parent `Renderer` and may be called
Expand Down
2 changes: 0 additions & 2 deletions src/lib/internationalization/locales/jp.cts
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ export = buildIncompleteTranslation({
"出力フォルダ内の sitemap.xml と正規リンクを生成する際に使用するベース URL を指定します。指定しない場合は、サイトマップは生成されません。",
help_useHostedBaseUrlForAbsoluteLinks:
"設定されている場合、TypeDocはhostedBaseUrlオプションを使用してサイト上のページへの絶対リンクを生成します。",
help_gaID:
"Google AnalyticsのトラッキングIDを設定し、トラッキングコードを有効にする",
help_hideGenerator:
"ページの最後にある TypeDoc リンクを印刷しないでください",
help_customFooterHtml: "TypeDoc リンクの後のカスタム フッター",
Expand Down
1 change: 0 additions & 1 deletion src/lib/internationalization/locales/zh.cts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ export = buildIncompleteTranslation({
"指定用于在我们的输出文件夹和规范链接中生成 sitemap.xml 的基本 URL。如果未指定,则不会生成站点地图",
help_useHostedBaseUrlForAbsoluteLinks:
"如果设置,TypeDoc 将使用 hostingBaseUrl 选项生成到您网站页面的绝对链接",
help_gaID: "设置 Google Analytics 跟踪 ID 并激活跟踪代码",
help_hideGenerator: "不要打印页面末尾的 TypeDoc 链接",
help_customFooterHtml: "TypeDoc 链接后的自定义页脚",
help_customFooterHtmlDisableWrapper:
Expand Down
2 changes: 0 additions & 2 deletions src/lib/internationalization/translatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ export const translatable = {
"Specify a base URL to be used in generating a sitemap.xml in our output folder and canonical links. If not specified, no sitemap will be generated",
help_useHostedBaseUrlForAbsoluteLinks:
"If set, TypeDoc will produce absolute links to pages on your site using the hostedBaseUrl option",
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: "Custom footer after the TypeDoc link",
help_customFooterHtmlDisableWrapper:
Expand Down
2 changes: 0 additions & 2 deletions src/lib/output/themes/default/DefaultThemeRenderContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { type NeverIfInternal, type Options } from "../../../utils";
import type { DefaultTheme } from "./DefaultTheme";
import { defaultLayout } from "./layouts/default";
import { index } from "./partials";
import { analytics } from "./partials/analytics";
import { breadcrumb } from "./partials/breadcrumb";
import {
commentSummary,
Expand Down Expand Up @@ -128,7 +127,6 @@ export class DefaultThemeRenderContext {
*/
reflectionPreview = bind(reflectionPreview, this);

analytics = bind(analytics, this);
breadcrumb = bind(breadcrumb, this);
commentSummary = bind(commentSummary, this);
commentTags = bind(commentTags, this);
Expand Down
1 change: 0 additions & 1 deletion src/lib/output/themes/default/layouts/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export const defaultLayout = (

<div class="overlay"></div>

{context.analytics()}
{context.hook("body.end", context)}
</body>
</html>
Expand Down
23 changes: 0 additions & 23 deletions src/lib/output/themes/default/partials/analytics.tsx

This file was deleted.

11 changes: 2 additions & 9 deletions src/lib/output/themes/default/partials/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
import { JSX, Raw } from "../../../../utils";
import { type Reflection, ReflectionKind } from "../../../../models";
import { anchorIcon } from "./anchor-icon";
import { join } from "../../lib";

// Note: Comment modifiers are handled in `renderFlags`

Expand Down Expand Up @@ -65,13 +66,5 @@ export function reflectionFlags(context: DefaultThemeRenderContext, props: Refle
}
}

return (
<>
{allFlags.map((item) => (
<>
<code class={"tsd-tag ts-flag" + item}>{item}</code>{" "}
</>
))}
</>
);
return join(" ", allFlags, (item) => <code class="tsd-tag">{item}</code>);
}
1 change: 0 additions & 1 deletion src/lib/utils/options/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ export interface TypeDocOptionMap {
hostedBaseUrl: string;
useHostedBaseUrlForAbsoluteLinks: boolean;
cacheBust: boolean;
gaID: string;
hideGenerator: boolean;
customFooterHtml: string;
customFooterHtmlDisableWrapper: boolean;
Expand Down
4 changes: 0 additions & 4 deletions src/lib/utils/options/sources/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,6 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
help: (i18n) => i18n.help_useHostedBaseUrlForAbsoluteLinks(),
type: ParameterType.Boolean,
});
options.addDeclaration({
name: "gaID",
help: (i18n) => i18n.help_gaID(),
});
options.addDeclaration({
name: "hideGenerator",
help: (i18n) => i18n.help_hideGenerator(),
Expand Down

0 comments on commit 1b55285

Please sign in to comment.