Skip to content

Commit cd66bb8

Browse files
Tom GotsmanTom Gotsman
authored andcommitted
image fix
1 parent 8037c62 commit cd66bb8

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

pcweb/meta/meta.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@
2626
def _build_meta_tags(
2727
title: str,
2828
description: str,
29-
image: str,
29+
image: str | None,
3030
url: str = REFLEX_DOMAIN_URL,
3131
) -> list[dict[str, str]]:
3232
"""Build a list of meta tags with the given parameters.
3333
3434
Args:
3535
title: The page title.
3636
description: The page description.
37-
image: The image path for social media previews.
37+
image: The image path for social media previews (None to omit).
3838
url: The page URL (defaults to REFLEX_DOMAIN_URL).
3939
4040
Returns:
4141
A list of meta tag dictionaries.
4242
"""
43-
return [
43+
tags = [
4444
# HTML Meta Tags
4545
{"name": "application-name", "content": APPLICATION_NAME},
4646
{"name": "description", "content": description},
@@ -49,16 +49,18 @@ def _build_meta_tags(
4949
{"property": "og:type", "content": OG_TYPE},
5050
{"property": "og:title", "content": title},
5151
{"property": "og:description", "content": description},
52-
{"property": "og:image", "content": image},
5352
# Twitter Meta Tags
5453
{"name": "twitter:card", "content": TWITTER_CARD_TYPE},
5554
{"property": "twitter:domain", "content": REFLEX_DOMAIN},
5655
{"property": "twitter:url", "content": url},
5756
{"name": "twitter:title", "content": title},
5857
{"name": "twitter:description", "content": description},
59-
{"name": "twitter:image", "content": image},
6058
{"name": "twitter:creator", "content": TWITTER_CREATOR},
6159
]
60+
if image:
61+
tags.append({"property": "og:image", "content": image})
62+
tags.append({"name": "twitter:image", "content": image})
63+
return tags
6264

6365

6466
meta_tags = _build_meta_tags(
@@ -105,21 +107,21 @@ def to_cdn_image_url(image: str | None) -> str:
105107

106108

107109
def create_meta_tags(
108-
title: str, description: str, image: str, url: str | None = None
110+
title: str, description: str, image: str | None, url: str | None = None
109111
) -> list[rx.Component]:
110112
"""Create meta tags for a page.
111113
112114
Args:
113115
title: The page title.
114116
description: The page description.
115-
image: The image path for social media previews.
117+
image: The image path for social media previews (None to omit).
116118
url: The page URL (optional, defaults to REFLEX_DOMAIN_URL).
117119
118120
Returns:
119121
A list of meta tag dictionaries.
120122
"""
121123
page_url = url if url else REFLEX_DOMAIN_URL
122-
image_url = to_cdn_image_url(image) if image else ""
124+
image_url = to_cdn_image_url(image) if image else None
123125

124126
return [
125127
*_build_meta_tags(
@@ -137,7 +139,7 @@ def blog_jsonld(
137139
description: str,
138140
author: str,
139141
date: str,
140-
image: str,
142+
image: str | None,
141143
url: str,
142144
faq: list[dict[str, str]] | None = None,
143145
author_bio: str | None = None,
@@ -154,15 +156,17 @@ def blog_jsonld(
154156
if author_bio:
155157
author_node["description"] = author_bio
156158

159+
image_url = to_cdn_image_url(image) if image else None
157160
posting: dict = {
158161
"@type": "BlogPosting",
159162
"headline": title,
160163
"description": description,
161-
"image": to_cdn_image_url(image),
162164
"datePublished": str(date),
163165
"url": url,
164166
"author": author_node,
165167
}
168+
if image_url:
169+
posting["image"] = image_url
166170
if updated_at:
167171
posting["dateModified"] = str(updated_at)
168172
if word_count:

pcweb/pages/blog/blog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ def blogs():
227227
path=route,
228228
title=seo_title,
229229
description=document.metadata["description"],
230-
image=document.metadata.get("image", ""),
230+
image=document.metadata.get("image") or None,
231231
meta=create_meta_tags(
232232
title=seo_title,
233233
description=document.metadata["description"],
234-
image=document.metadata.get("image", ""),
234+
image=document.metadata.get("image") or None,
235235
url=f"https://reflex.dev{route}",
236236
),
237237
)(lambda doc=document, route=route: page(doc, route))

pcweb/pages/blog/page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def page(document, route) -> rx.Component:
206206
description=meta["description"],
207207
author=meta["author"],
208208
date=str(meta["date"]),
209-
image=meta.get("image", ""),
209+
image=meta.get("image") or None,
210210
url=page_url,
211211
faq=meta.get("faq"),
212212
author_bio=meta.get("author_bio"),

0 commit comments

Comments
 (0)