Skip to content

Commit 620e37e

Browse files
devin-ai-integration[bot]Alek99carlosabadia
authored
Fix blog post preview images for LinkedIn sharing (#1465)
* Fix blog post preview images for LinkedIn sharing - Update create_meta_tags() to accept URL parameter for specific page URLs - Convert relative image paths to absolute URLs for better social media compatibility - Pass blog post URL to create_meta_tags() instead of using homepage URL - Fixes issue where LinkedIn shows homepage preview instead of blog-specific images Co-Authored-By: Alek <[email protected]> * Refactor image URL handling to consolidate branches - Consolidate if/else branches for image URL construction as suggested by Greptile - Use ternary expression to handle both cases (with/without leading slash) more concisely - Maintains same functionality while improving code readability Co-Authored-By: Alek <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Alek <[email protected]> Co-authored-by: Carlos <[email protected]>
1 parent f84d331 commit 620e37e

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

pcweb/meta/meta.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ def favicons_links() -> list[rx.Component]:
8585
]
8686

8787

88-
def create_meta_tags(title: str, description: str, image: str) -> list[rx.Component]:
88+
def create_meta_tags(title: str, description: str, image: str, url: str = None) -> list[rx.Component]:
89+
page_url = url if url else REFLEX_DOMAIN_URL
90+
91+
if image and not image.startswith(('http://', 'https://')):
92+
image_url = f"https://reflex.dev{'' if image.startswith('/') else '/'}{image}"
93+
else:
94+
image_url = image
95+
8996
return [
9097
# HTML Meta Tags
9198
{"name": "application-name", "content": "Reflex"},
@@ -98,23 +105,23 @@ def create_meta_tags(title: str, description: str, image: str) -> list[rx.Compon
98105
"content": description,
99106
},
100107
# Facebook Meta Tags
101-
{"property": "og:url", "content": REFLEX_DOMAIN_URL},
108+
{"property": "og:url", "content": page_url},
102109
{"property": "og:type", "content": "website"},
103110
{"property": "og:title", "content": title},
104111
{
105112
"property": "og:description",
106113
"content": description,
107114
},
108-
{"property": "og:image", "content": image},
115+
{"property": "og:image", "content": image_url},
109116
# Twitter Meta Tags
110117
{"name": "twitter:card", "content": "summary_large_image"},
111118
{"property": "twitter:domain", "content": REFLEX_DOMAIN},
112-
{"property": "twitter:url", "content": REFLEX_DOMAIN_URL},
119+
{"property": "twitter:url", "content": page_url},
113120
{"name": "twitter:title", "content": title},
114121
{
115122
"name": "twitter:description",
116123
"content": description,
117124
},
118-
{"name": "twitter:image", "content": image},
125+
{"name": "twitter:image", "content": image_url},
119126
{"name": "twitter:creator", "content": TWITTER_CREATOR},
120127
]

pcweb/pages/blog/blog.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def blogs():
165165
title=document.metadata["title"],
166166
description=document.metadata["description"],
167167
image=document.metadata["image"],
168+
url=f"https://reflex.dev{route}",
168169
),
169170
)(lambda doc=document: page(doc, route))
170171

0 commit comments

Comments
 (0)