@@ -17,36 +17,28 @@ export function load(app: Application) {
17
17
}
18
18
```
19
19
20
- This isn't very interesting since it exactly duplicates the default theme. Most themes need to adjust the templates
21
- in some way. This can be done by providing them class which returns a different context class. Say we wanted to replace
22
- TypeDoc's default analytics helper with one that uses [ Open Web Analytics] ( https://www.openwebanalytics.com/ ) instead of
23
- Google Analytics. This could be done with the following theme:
20
+ This isn't very interesting since it exactly duplicates the default theme.
21
+ Most themes need to adjust the templates in some way. This can be done by
22
+ providing them class which returns a different context class. Say we wanted
23
+ to replace TypeDoc's default footer with one that mentioned your copyright.
24
+ This could be done with the following theme.
25
+
26
+ In this case, it would probably be better to add this content using a render
27
+ hook for ` footer.begin ` or ` footer.end ` , but it can be done in this way as well.
24
28
25
29
``` tsx
26
30
import { Application , DefaultTheme , PageEvent , JSX , Reflection } from " typedoc" ;
27
31
28
- const script = `
29
- (function() {
30
- var _owa = document.createElement('script'); _owa.type = 'text/javascript';
31
- _owa.async = true; _owa.src = '${site }' + '/modules/base/js/owa.tracker-combined-min.js';
32
- var _owa_s = document.getElementsByTagName('script')[0]; _owa_s.parentNode.insertBefore(_owa,
33
- _owa_s);
34
- }());
35
- ` .trim ();
36
-
37
32
class MyThemeContext extends DefaultThemeRenderContext {
38
- // Important: If you use `this`, this function MUST be bound! Template functions are free
39
- // to destructure the context object to only grab what they care about.
40
- override analytics = () => {
41
- // Reusing existing option rather than declaring our own for brevity
42
- if (! this .options .isSet (" gaId" )) return ;
43
-
44
- const site = this .options .getValue (" gaId" );
45
-
33
+ // Important: If you use `this`, this function MUST be bound! Template functions
34
+ // are free to destructure the context object to only grab what they care about.
35
+ override footer = (context ) => {
46
36
return (
47
- <script >
48
- <JSX.Raw html = { script } />
49
- </script >
37
+ <footer >
38
+ { context .hook (" footer.begin" , context )}
39
+ Copyright 2024
40
+ { context .hook (" footer.end" , context )}
41
+ </footer >
50
42
);
51
43
};
52
44
}
@@ -62,7 +54,7 @@ export function load(app: Application) {
62
54
}
63
55
```
64
56
65
- ## Hooks (v0.22.8+)
57
+ ## Hooks
66
58
67
59
When rendering themes, TypeDoc's default theme will call several functions to allow plugins to inject HTML
68
60
into a page without completely overwriting a theme. Hooks live on the parent ` Renderer ` and may be called
0 commit comments