Skip to content
This repository was archived by the owner on Apr 23, 2026. It is now read-only.

Commit 07562ca

Browse files
tgberkeleyTom Gotsman
andauthored
allow image to be none (#66)
Co-authored-by: Tom Gotsman <tomgotsman@Mac.localdomain>
1 parent 128f114 commit 07562ca

2 files changed

Lines changed: 28 additions & 20 deletions

File tree

shared/lib/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[dict[str, str] | 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 or 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:

shared/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[dict[str, str] | 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 or 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:

0 commit comments

Comments
 (0)