diff --git a/.changeset/quick-apes-grab.md b/.changeset/quick-apes-grab.md new file mode 100644 index 00000000000..94ab57bec1f --- /dev/null +++ b/.changeset/quick-apes-grab.md @@ -0,0 +1,7 @@ +--- +"@astrojs/starlight": patch +--- + +Fixes invalid `
` output when configuration is missing: +- Omits `` if Starlight’s `description` option is unset +- Omits `` and `` if Astro’s `site` option is unset diff --git a/packages/starlight/utils/head.ts b/packages/starlight/utils/head.ts index 0f3095e6bea..b956c3602f1 100644 --- a/packages/starlight/utils/head.ts +++ b/packages/starlight/utils/head.ts @@ -33,7 +33,9 @@ export function getHead( attrs: { name: 'viewport', content: 'width=device-width, initial-scale=1' }, }, { tag: 'title', content: `${data.title} ${config.titleDelimiter} ${siteTitle}` }, - { tag: 'link', attrs: { rel: 'canonical', href: canonicalHref } }, + ...(canonicalHref !== undefined + ? ([{ tag: 'link', attrs: { rel: 'canonical', href: canonicalHref } }] as const) + : []), { tag: 'meta', attrs: { name: 'generator', content: context.generator } }, { tag: 'meta', @@ -51,9 +53,13 @@ export function getHead( // OpenGraph Tags { tag: 'meta', attrs: { property: 'og:title', content: data.title } }, { tag: 'meta', attrs: { property: 'og:type', content: 'article' } }, - { tag: 'meta', attrs: { property: 'og:url', content: canonicalHref } }, + ...(canonicalHref !== undefined + ? ([{ tag: 'meta', attrs: { property: 'og:url', content: canonicalHref } }] as const) + : []), { tag: 'meta', attrs: { property: 'og:locale', content: lang } }, - { tag: 'meta', attrs: { property: 'og:description', content: description } }, + ...(description !== undefined + ? ([{ tag: 'meta', attrs: { property: 'og:description', content: description } }] as const) + : []), { tag: 'meta', attrs: { property: 'og:site_name', content: siteTitle } }, // Twitter Tags {