File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
src/lib/output/themes/default/layouts Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1
1
# Unreleased
2
2
3
+ ### Features
4
+
5
+ - If ` hostedBaseUrl ` is set to the root page on a website, TypeDoc will now include ` WebSite ` structured data, #2760 .
6
+
3
7
### Bug Fixes
4
8
5
9
- Fix support for ESM config files with Node 23, #2752 .
Original file line number Diff line number Diff line change @@ -5,6 +5,34 @@ import type { PageEvent } from "../../../events";
5
5
import { getDisplayName } from "../../lib" ;
6
6
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext" ;
7
7
8
+ // See #2760
9
+ function buildSiteMetadata ( context : DefaultThemeRenderContext ) {
10
+ try {
11
+ // We have to know where we are hosted in order to generate this block
12
+ const url = new URL ( context . options . getValue ( "hostedBaseUrl" ) ) ;
13
+
14
+ // No point in generating this if we aren't the root page on the site
15
+ if ( url . pathname !== "/" ) {
16
+ return null ;
17
+ }
18
+
19
+ return (
20
+ < script type = "application/ld+json" >
21
+ < Raw
22
+ html = { JSON . stringify ( {
23
+ "@context" : "https://schema.org" ,
24
+ "@type" : "WebSite" ,
25
+ name : context . page . project . name ,
26
+ url : url . toString ( ) ,
27
+ } ) }
28
+ />
29
+ </ script >
30
+ ) ;
31
+ } catch {
32
+ return null ;
33
+ }
34
+ }
35
+
8
36
export const defaultLayout = (
9
37
context : DefaultThemeRenderContext ,
10
38
template : RenderTemplate < PageEvent < Reflection > > ,
@@ -20,6 +48,7 @@ export const defaultLayout = (
20
48
? getDisplayName ( props . model )
21
49
: `${ getDisplayName ( props . model ) } | ${ getDisplayName ( props . project ) } ` }
22
50
</ title >
51
+ { props . url === "index.html" && buildSiteMetadata ( context ) }
23
52
< meta name = "description" content = { "Documentation for " + props . project . name } />
24
53
< meta name = "viewport" content = "width=device-width, initial-scale=1" />
25
54
You can’t perform that action at this time.
0 commit comments