From 067c8e7315119da852cca6f6f42c8b60872ef993 Mon Sep 17 00:00:00 2001 From: Kian Date: Fri, 29 Nov 2024 12:06:11 +0000 Subject: [PATCH] [Docs Site] Append product meta suffix to custom titles (#18445) --- src/components/overrides/Head.astro | 30 ++++++++++++++++++----- src/content/docs/aegis/index.mdx | 2 +- src/content/docs/china-network/index.mdx | 2 +- src/content/docs/page-shield/index.mdx | 2 +- src/content/docs/rules/index.mdx | 2 +- src/content/docs/ruleset-engine/index.mdx | 2 +- src/content/docs/ssl/index.mdx | 2 +- src/content/docs/waf/index.mdx | 2 +- 8 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/components/overrides/Head.astro b/src/components/overrides/Head.astro index 25358931646d7e..6cf38da774a94a 100644 --- a/src/components/overrides/Head.astro +++ b/src/components/overrides/Head.astro @@ -14,12 +14,30 @@ if (currentSection) { if (product) { if (product.data.meta.title) { - const title = `${Astro.props.entry.data.title} | ${product.data.meta.title}`; - Astro.props.entry.data.head.push({ - tag: "title", - attrs: {}, - content: title, - }); + const titleIdx = Astro.props.entry.data.head.findIndex( + (x) => x.tag === "title", + ); + + let title: string; + + if (titleIdx !== -1) { + const existingTitle = Astro.props.entry.data.head[titleIdx].content; + title = `${existingTitle} · ${product.data.meta.title}`; + + Astro.props.entry.data.head[titleIdx] = { + tag: "title", + attrs: {}, + content: title, + }; + } else { + title = `${Astro.props.entry.data.title} · ${product.data.meta.title}`; + Astro.props.entry.data.head.push({ + tag: "title", + attrs: {}, + content: title, + }); + } + Astro.props.entry.data.head.push({ tag: "meta", attrs: { property: "og:title", content: title }, diff --git a/src/content/docs/aegis/index.mdx b/src/content/docs/aegis/index.mdx index b813c60a247185..2b3f7649083b37 100644 --- a/src/content/docs/aegis/index.mdx +++ b/src/content/docs/aegis/index.mdx @@ -5,7 +5,7 @@ sidebar: order: 1 head: - tag: title - content: Overview | Cloudflare Aegis docs + content: Overview --- import { CardGrid, Description, GlossaryTooltip, LinkTitleCard, Plan, RelatedProduct } from "~/components" diff --git a/src/content/docs/china-network/index.mdx b/src/content/docs/china-network/index.mdx index 6f8ca9042375e7..068bfb790e6df3 100644 --- a/src/content/docs/china-network/index.mdx +++ b/src/content/docs/china-network/index.mdx @@ -5,7 +5,7 @@ sidebar: order: 1 head: - tag: title - content: Overview | Cloudflare China Network + content: Overview --- import { Stream } from "~/components" diff --git a/src/content/docs/page-shield/index.mdx b/src/content/docs/page-shield/index.mdx index a0e6743dba3d08..4913a83348b2bb 100644 --- a/src/content/docs/page-shield/index.mdx +++ b/src/content/docs/page-shield/index.mdx @@ -5,7 +5,7 @@ sidebar: order: 1 head: - tag: title - content: Overview | Cloudflare Page Shield + content: Overview description: Page Shield is a comprehensive client-side security and privacy solution that allows you to ensure the safety of your website visitors' browsing environment. diff --git a/src/content/docs/rules/index.mdx b/src/content/docs/rules/index.mdx index 7db2a1cbcb8005..8bed9dd2a34799 100644 --- a/src/content/docs/rules/index.mdx +++ b/src/content/docs/rules/index.mdx @@ -5,7 +5,7 @@ sidebar: order: 1 head: - tag: title - content: Overview | Cloudflare Rules + content: Overview --- import { diff --git a/src/content/docs/ruleset-engine/index.mdx b/src/content/docs/ruleset-engine/index.mdx index 6f7f55670fd69f..9fb994eb86f433 100644 --- a/src/content/docs/ruleset-engine/index.mdx +++ b/src/content/docs/ruleset-engine/index.mdx @@ -5,7 +5,7 @@ sidebar: order: 2 head: - tag: title - content: Overview | Cloudflare Ruleset Engine + content: Overview --- import { LinkButton } from "~/components"; diff --git a/src/content/docs/ssl/index.mdx b/src/content/docs/ssl/index.mdx index 2e0e63706ed929..565ffab2c8d902 100644 --- a/src/content/docs/ssl/index.mdx +++ b/src/content/docs/ssl/index.mdx @@ -5,7 +5,7 @@ sidebar: order: 1 head: - tag: title - content: Overview | Cloudflare SSL/TLS docs + content: Overview description: Cloudflare SSL/TLS offers free Universal SSL alongside advanced and enterprise features to meet your encryption and certificate management needs. --- diff --git a/src/content/docs/waf/index.mdx b/src/content/docs/waf/index.mdx index 11c3ae6209ea5c..ae81d18a375f8b 100644 --- a/src/content/docs/waf/index.mdx +++ b/src/content/docs/waf/index.mdx @@ -5,7 +5,7 @@ sidebar: order: 1 head: - tag: title - content: Overview | Cloudflare Web Application Firewall + content: Overview description: The Cloudflare Web Application Firewall (WAF) provides automatic protection from vulnerabilities and the flexibility to create custom rules. ---