diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b7583b75..6e2c711e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +### Features + +- If `hostedBaseUrl` is set to the root page on a website, TypeDoc will now include `WebSite` structured data, #2760. + ### Bug Fixes - Fix support for ESM config files with Node 23, #2752. diff --git a/src/lib/output/themes/default/layouts/default.tsx b/src/lib/output/themes/default/layouts/default.tsx index ac8219ebb..268aa7d9b 100644 --- a/src/lib/output/themes/default/layouts/default.tsx +++ b/src/lib/output/themes/default/layouts/default.tsx @@ -5,6 +5,34 @@ import type { PageEvent } from "../../../events"; import { getDisplayName } from "../../lib"; import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext"; +// See #2760 +function buildSiteMetadata(context: DefaultThemeRenderContext) { + try { + // We have to know where we are hosted in order to generate this block + const url = new URL(context.options.getValue("hostedBaseUrl")); + + // No point in generating this if we aren't the root page on the site + if (url.pathname !== "/") { + return null; + } + + return ( + + ); + } catch { + return null; + } +} + export const defaultLayout = ( context: DefaultThemeRenderContext, template: RenderTemplate>, @@ -20,6 +48,7 @@ export const defaultLayout = ( ? getDisplayName(props.model) : `${getDisplayName(props.model)} | ${getDisplayName(props.project)}`} + {props.url === "index.html" && buildSiteMetadata(context)}