Skip to content

Commit 6327f4c

Browse files
committed
Refactor logic
1 parent 7245275 commit 6327f4c

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

src/components/overrides/Head.astro

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ if (currentSection) {
6464
});
6565
}
6666
67+
let ogImage = "https://developers.cloudflare.com/cf-twitter-card.png";
68+
let changelogImage =
69+
"https://developers.cloudflare.com/changelog-preview.png";
70+
6771
if (product.data.product.group) {
6872
const group = product.data.product.group.toLowerCase();
6973
70-
let ogImage = "https://developers.cloudflare.com/cf-twitter-card.png";
71-
let changelogImage =
72-
"https://developers.cloudflare.com/changelog-preview.png";
7374
const images: Record<string, string> = {
7475
"cloudflare essentials":
7576
"https://developers.cloudflare.com/core-services-preview.png",
@@ -88,39 +89,6 @@ if (currentSection) {
8889
ogImage = images[group];
8990
}
9091
91-
if (Astro.url.pathname.startsWith("/changelog/")) {
92-
ogImage = changelogImage;
93-
}
94-
95-
const tags = [
96-
{
97-
tag: "meta",
98-
attrs: {
99-
name: "image",
100-
content: ogImage,
101-
},
102-
content: "",
103-
},
104-
{
105-
tag: "meta",
106-
attrs: {
107-
name: "og:image",
108-
content: ogImage,
109-
},
110-
content: "",
111-
},
112-
{
113-
tag: "meta",
114-
attrs: {
115-
name: "twitter:image",
116-
content: ogImage,
117-
},
118-
content: "",
119-
},
120-
] as const;
121-
122-
Astro.props.entry.data.head.push(...tags);
123-
12492
Astro.props.entry.data.head.push({
12593
tag: "meta",
12694
attrs: {
@@ -130,6 +98,39 @@ if (currentSection) {
13098
content: "",
13199
});
132100
}
101+
102+
if (currentSection === "changelog") {
103+
ogImage = changelogImage;
104+
}
105+
106+
const tags = [
107+
{
108+
tag: "meta",
109+
attrs: {
110+
name: "image",
111+
content: ogImage,
112+
},
113+
content: "",
114+
},
115+
{
116+
tag: "meta",
117+
attrs: {
118+
name: "og:image",
119+
content: ogImage,
120+
},
121+
content: "",
122+
},
123+
{
124+
tag: "meta",
125+
attrs: {
126+
name: "twitter:image",
127+
content: ogImage,
128+
},
129+
content: "",
130+
},
131+
] as const;
132+
133+
Astro.props.entry.data.head.push(...tags);
133134
}
134135
135136
if (currentSection === "style-guide") {

0 commit comments

Comments
 (0)