Skip to content

Commit 5ebe335

Browse files
committed
fix title and desc
1 parent 7b7ce74 commit 5ebe335

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/components/overrides/Head.astro

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getEntry } from "astro:content";
77
import { getOgImage } from "~/util/og";
88
import type { CollectionEntry } from "astro:content";
99
10+
const DEFAULT_TITLE_DELIMITER = "|";
1011
const NOINDEX_PRODUCTS = ["email-security", "style-guide", "security"];
1112
1213
const currentSection = Astro.url.pathname.split("/")[1].replaceAll(".", "");
@@ -31,7 +32,9 @@ if (currentSection) {
3132
let title: string;
3233
3334
if (titleIdx !== -1) {
34-
const existingTitle = head[titleIdx].content;
35+
const existingTitle = head[titleIdx].content?.split(
36+
` ${DEFAULT_TITLE_DELIMITER} `,
37+
)[0];
3538
title = `${existingTitle} · ${product.data.meta.title}`;
3639
3740
head[titleIdx] = {
@@ -80,6 +83,26 @@ if (shouldNoIndex) {
8083
});
8184
}
8285
86+
if (
87+
frontmatter.description &&
88+
head.findIndex(
89+
({ tag, attrs }) => tag === "meta" && attrs?.name === "description",
90+
) === -1
91+
) {
92+
const existingOpenGraphTag = head.findIndex(
93+
({ tag, attrs }) => tag === "meta" && attrs?.property === "og:description",
94+
);
95+
96+
if (existingOpenGraphTag !== -1) {
97+
head[existingOpenGraphTag].attrs!.content = frontmatter.description;
98+
}
99+
100+
metaTags.push({
101+
name: "description",
102+
content: frontmatter.description as string,
103+
});
104+
}
105+
83106
if (frontmatter.pcx_content_type) {
84107
["pcx_content_type", "algolia_content_type"].map((name) => {
85108
metaTags.push({

0 commit comments

Comments
 (0)