This repository was archived by the owner on Apr 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathmeta.py
More file actions
330 lines (296 loc) · 10.6 KB
/
meta.py
File metadata and controls
330 lines (296 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
import json
import reflex as rx
from pcweb.constants import (
DISCORD_URL,
FORUM_URL,
GITHUB_URL,
LINKEDIN_URL,
REFLEX_ASSETS_CDN,
REFLEX_DOMAIN,
REFLEX_DOMAIN_URL,
TWITTER_CREATOR,
TWITTER_URL,
)
TITLE = "The unified platform to build and scale enterprise apps."
ONE_LINE_DESCRIPTION = "Build with AI, iterate in Python, deploy to any cloud. Reflex is the platform for full-stack web apps and internal tools."
# Common constants
APPLICATION_NAME = "Reflex"
TWITTER_CARD_TYPE = "summary_large_image"
OG_TYPE = "website"
def _build_meta_tags(
title: str,
description: str,
image: str,
url: str = REFLEX_DOMAIN_URL,
) -> list[dict[str, str]]:
"""Build a list of meta tags with the given parameters.
Args:
title: The page title.
description: The page description.
image: The image path for social media previews.
url: The page URL (defaults to REFLEX_DOMAIN_URL).
Returns:
A list of meta tag dictionaries.
"""
return [
# HTML Meta Tags
{"name": "application-name", "content": APPLICATION_NAME},
{"name": "description", "content": description},
# Facebook Meta Tags
{"property": "og:url", "content": url},
{"property": "og:type", "content": OG_TYPE},
{"property": "og:title", "content": title},
{"property": "og:description", "content": description},
{"property": "og:image", "content": image},
# Twitter Meta Tags
{"name": "twitter:card", "content": TWITTER_CARD_TYPE},
{"property": "twitter:domain", "content": REFLEX_DOMAIN},
{"property": "twitter:url", "content": url},
{"name": "twitter:title", "content": title},
{"name": "twitter:description", "content": description},
{"name": "twitter:image", "content": image},
{"name": "twitter:creator", "content": TWITTER_CREATOR},
]
meta_tags = _build_meta_tags(
title=TITLE,
description=ONE_LINE_DESCRIPTION,
image=f"{REFLEX_ASSETS_CDN}previews/index_preview.webp",
)
hosting_meta_tags = _build_meta_tags(
title=TITLE,
description=ONE_LINE_DESCRIPTION,
image=f"{REFLEX_ASSETS_CDN}previews/hosting_preview.webp",
)
def favicons_links() -> list[rx.Component]:
return [
rx.el.link(
rel="apple-touch-icon", sizes="180x180", href="/meta/apple-touch-icon.png"
),
rx.el.link(
rel="icon", type="image/png", sizes="32x32", href="/meta/favicon-32x32.png"
),
rx.el.link(
rel="icon", type="image/png", sizes="16x16", href="/meta/favicon-16x16.png"
),
rx.el.link(rel="manifest", href="/meta/site.webmanifest"),
rx.el.link(rel="shortcut icon", href="/favicon.ico"),
]
def to_cdn_image_url(image: str | None) -> str:
"""Convert a relative image path to a full CDN URL.
Root-level paths (e.g. /reflex_banner.png) map to other/ on the CDN.
Paths with subfolders (e.g. /blog/on-prem.webp) map 1:1.
"""
if not image or image.startswith(("http://", "https://")):
return image or ""
path = image.lstrip("/") if image.startswith("/") else image
if "/" not in path:
path = f"other/{path}"
return f"{REFLEX_ASSETS_CDN}{path}"
def create_meta_tags(
title: str, description: str, image: str, url: str | None = None
) -> list[rx.Component]:
"""Create meta tags for a page.
Args:
title: The page title.
description: The page description.
image: The image path for social media previews.
url: The page URL (optional, defaults to REFLEX_DOMAIN_URL).
Returns:
A list of meta tag dictionaries.
"""
page_url = url if url else REFLEX_DOMAIN_URL
image_url = to_cdn_image_url(image) if image else ""
return [
*_build_meta_tags(
title=title,
description=description,
image=image_url,
url=page_url,
),
rx.el.link(rel="canonical", href=page_url),
]
def blog_jsonld(
title: str,
description: str,
author: str,
date: str,
image: str,
url: str,
faq: list[dict[str, str]] | None = None,
author_bio: str | None = None,
updated_at: str | None = None,
word_count: int | None = None,
keywords: list[str] | None = None,
) -> rx.Component:
"""Create a single JSON-LD script tag with @graph for a blog post.
Always includes a BlogPosting entry. If faq items are provided,
a FAQPage entry is also added to the graph.
"""
author_node: dict = {"@type": "Person", "name": author}
if author_bio:
author_node["description"] = author_bio
posting: dict = {
"@type": "BlogPosting",
"headline": title,
"description": description,
"image": to_cdn_image_url(image),
"datePublished": str(date),
"url": url,
"author": author_node,
}
if updated_at:
posting["dateModified"] = str(updated_at)
if word_count:
posting["wordCount"] = word_count
if keywords:
posting["keywords"] = keywords
graph: list[dict] = [
{
**posting,
"publisher": {
"@type": "Organization",
"name": "Reflex",
"url": REFLEX_DOMAIN_URL,
},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": url,
},
},
]
if faq:
graph.append(
{
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": item["question"],
"acceptedAnswer": {
"@type": "Answer",
"text": item["answer"],
},
}
for item in faq
],
}
)
data = {
"@context": "https://schema.org",
"@graph": graph,
}
return rx.el.script(json.dumps(data), type="application/ld+json")
def website_organization_jsonld(url: str = REFLEX_DOMAIN_URL) -> rx.Component:
"""Create Organization + WebSite JSON-LD for the homepage."""
org_url = REFLEX_DOMAIN_URL.rstrip("/")
data = {
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": f"{org_url}/#organization",
"name": "Reflex",
"url": REFLEX_DOMAIN_URL,
"logo": f"{org_url}/meta/apple-touch-icon.png",
"description": "Open-source Python framework for building full-stack web applications. Deploy to any cloud with AI-powered code generation.",
"sameAs": [
GITHUB_URL,
TWITTER_URL,
DISCORD_URL,
LINKEDIN_URL,
FORUM_URL,
],
},
{
"@type": "WebSite",
"name": "Reflex",
"url": url,
"description": ONE_LINE_DESCRIPTION,
"publisher": {"@id": f"{org_url}/#organization"},
},
],
}
return rx.el.script(json.dumps(data), type="application/ld+json")
def blog_index_jsonld(posts: list[tuple[str, dict]], url: str) -> rx.Component:
"""Create Blog JSON-LD with ItemList of posts for the blog index page."""
items = [
{
"@type": "ListItem",
"position": i + 1,
"url": f"{REFLEX_DOMAIN_URL.rstrip('/')}/blog/{path}",
"name": meta.get("title_tag") or meta.get("title", ""),
"datePublished": str(meta.get("date", "")),
}
for i, (path, meta) in enumerate(posts[:20])
]
blog_posts = [
{
"@type": "BlogPosting",
"headline": meta.get("title_tag") or meta.get("title", ""),
"url": f"{REFLEX_DOMAIN_URL.rstrip('/')}/blog/{path}",
"datePublished": str(meta.get("date", "")),
}
for path, meta in posts[:20]
]
data = {
"@context": "https://schema.org",
"@graph": [
{
"@type": "Blog",
"name": "Reflex Blog",
"description": "Python web app tutorials, framework comparisons, and tips for building with Reflex.",
"url": url,
"publisher": {
"@type": "Organization",
"name": "Reflex",
"url": REFLEX_DOMAIN_URL,
},
"blogPost": blog_posts,
},
{
"@type": "ItemList",
"itemListElement": items,
"numberOfItems": len(items),
},
],
}
return rx.el.script(json.dumps(data), type="application/ld+json")
def faq_jsonld(faq_schema: dict) -> rx.Component:
"""Create a FAQPage JSON-LD script tag from a pre-built schema dict."""
return rx.el.script(json.dumps(faq_schema), type="application/ld+json")
def pricing_jsonld(url: str) -> rx.Component:
"""Create SoftwareApplication + Product JSON-LD for the pricing page."""
data = {
"@context": "https://schema.org",
"@graph": [
{
"@type": "SoftwareApplication",
"name": "Reflex",
"applicationCategory": "DeveloperApplication",
"description": "The platform to build and scale enterprise apps. Python full-stack framework for web apps and internal tools.",
"url": url,
},
{
"@type": "Product",
"name": "Reflex Enterprise Platform",
"brand": {"@type": "Brand", "name": "Reflex"},
"description": "Enterprise-grade fullstack app building platform with AI-powered code generation in pure Python. Includes dedicated support, SSO, on-prem deployment, and custom SLAs.",
"offers": [
{
"@type": "Offer",
"price": "0",
"priceCurrency": "USD",
"name": "Free",
"availability": "https://schema.org/InStock",
},
{
"@type": "Offer",
"name": "Enterprise",
"description": "Custom enterprise pricing",
"availability": "https://schema.org/PreOrder",
},
],
},
],
}
return rx.el.script(json.dumps(data), type="application/ld+json")