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 230
Expand file tree
/
Copy pathpcweb.py
More file actions
163 lines (150 loc) · 6.81 KB
/
pcweb.py
File metadata and controls
163 lines (150 loc) · 6.81 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
"""The main Reflex website."""
import os
import sys
import reflex as rx
import reflex_enterprise as rxe
from pcweb import styles
from pcweb.meta.meta import favicons_links
from pcweb.pages import page404, routes
from pcweb.pages.docs import exec_blocks, outblocks
from pcweb.telemetry import get_pixel_website_trackers
from pcweb.whitelist import _check_whitelisted_path
# This number discovered by trial and error on Windows 11 w/ Node 18, any
# higher and the prod build fails with EMFILE error.
WINDOWS_MAX_ROUTES = int(os.environ.get("REFLEX_WEB_WINDOWS_MAX_ROUTES", "100"))
# Execute all the exec blocks in the documents.
for doc, href in outblocks:
exec_blocks(doc, href)
# Create the app.
app = rxe.App(
style=styles.BASE_STYLE,
stylesheets=styles.STYLESHEETS,
app_wraps={},
theme=rx.theme(
has_background=True,
radius="large",
accent_color="violet",
),
head_components=get_pixel_website_trackers()
+ favicons_links()
+ [
rx.el.link(
rel="preconnect",
href="https://fonts.googleapis.com",
),
rx.el.link(
rel="preconnect",
href="https://fonts.gstatic.com",
cross_origin="",
),
rx.el.link(
href="https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400..700&family=JetBrains+Mono:wght@400..700&display=swap",
rel="stylesheet",
),
],
)
# XXX: The app is TOO BIG to build on Windows, so explicitly disallow it except for testing
if sys.platform == "win32":
if not os.environ.get("REFLEX_WEB_WINDOWS_OVERRIDE"):
raise RuntimeError(
"reflex-web cannot be built on Windows due to EMFILE error. To build a "
"subset of pages for testing, set environment variable REFLEX_WEB_WINDOWS_OVERRIDE."
)
routes = routes[:WINDOWS_MAX_ROUTES]
# Add the pages to the app.
for route in routes:
# print(f"Adding route: {route}")
if _check_whitelisted_path(route.path):
page_args = {
"component": route.component,
"route": route.path,
"title": route.title,
"image": (
"/previews/index_preview.webp" if route.image is None else route.image
),
"meta": [
{"name": "theme-color", "content": route.background_color},
],
}
# Add the description only if it is not None
if route.description is not None:
page_args["description"] = route.description
# Add the extra meta data only if it is not None
if route.meta is not None:
page_args["meta"].extend(route.meta)
# Call add_page with the dynamically constructed arguments
app.add_page(**page_args)
# Add redirects
redirects = [
("/docs/ui", "/docs/ui/overview"),
("/docs/enterprise/react-flow", "/docs/enterprise/react-flow/overview"),
("/docs/advanced-onboarding", "/docs/advanced-onboarding/code-structure"),
("/docs/hosting/cli", "/docs/hosting"),
("/docs/enterprise/ag-grid/index", "/docs/enterprise/ag-grid"),
("/docs/ai-builder/integrations", "/docs/ai-builder/integrations/overview"),
("/docs/ai-builder/app-lifecycle", "/docs/ai-builder/app-lifecycle/general"),
("/docs/ai-builder/features", "/docs/ai-builder/features/ide"),
("/docs/ai-builder", "/docs/ai-builder/overview/best-practices"),
("/docs/ai-builder/overview", "/docs/ai-builder/overview/best-practices"),
("/framework", "/open-source"),
("/docs", "/docs/getting-started/introduction"),
("/docs/getting-started", "/docs/getting-started/introduction"),
("/docs/state", "/docs/state/overview"),
("/docs/styling", "/docs/styling/overview"),
("/docs/database", "/docs/database/overview"),
("/docs/hosting", "/docs/hosting/self-hosting"),
("/docs/advanced-guide", "/docs/advanced-guide/custom-vars"),
("/docs/library/theming/theme", "/docs/library/other/theme"),
("/docs/library/theming/theme-panel", "/docs/library/other/theme"),
("/docs/library/layout/foreach", "/docs/library/dynamic-rendering/foreach"),
("/docs/library/layout/match", "/docs/library/dynamic-rendering/match"),
("/docs/library/layout/cond", "/docs/library/dynamic-rendering/cond"),
("/docs/components", "/docs/components/props"),
("/docs/pages", "/docs/pages/routes"),
("/docs/assets", "/docs/assets/referencing-assets"),
("/docs/api-reference", "/docs/api-reference/app"),
("/docs/wrapping-react", "/docs/wrapping-react/overview"),
("/docs/vars", "/docs/vars/base-vars"),
("/docs/events", "/docs/events/events-overview"),
("/docs/state-structure", "/docs/state-structure/overview"),
("/docs/api-routes", "/docs/api-routes/overview"),
("/docs/client-storage", "/docs/client-storage/overview"),
("/docs/authentication", "/docs/authentication/authentication-overview"),
("/docs/utility-methods", "/docs/utility-methods/router-attributes"),
("/docs/datatable-tutorial", "/docs/datatable-tutorial/simple-table"),
("/docs/library/graphing", "/docs/library/graphing/charts"),
("/docs/tutorial", "/docs/getting-started/chatapp-tutorial"),
("/docs/tutorial/intro", "/docs/getting-started/chatapp-tutorial"),
("/docs/tutorial/setup", "/docs/getting-started/chatapp-tutorial"),
("/docs/tutorial/frontend", "/docs/getting-started/chatapp-tutorial"),
("/docs/tutorial/adding-state", "/docs/getting-started/chatapp-tutorial"),
("/docs/tutorial/final-app", "/docs/getting-started/chatapp-tutorial"),
("/docs/getting-started/configuration", "/docs/advanced-onboarding/configuration"),
(
"/docs/getting-started/how-reflex-works",
"/docs/advanced-onboarding/how-reflex-works",
),
# Recipes
("/docs/recipes/auth", "/docs/recipes"),
("/docs/recipes/layout", "/docs/recipes"),
("/docs/recipes/others", "/docs/recipes"),
("/docs/recipes/content", "/docs/recipes"),
# redirect previous chakra links to the new chakra docs
("/docs/library/chakra/[[...splat]]", "https://chakra.reflex.run/introduction/"),
("/gallery", "/templates"),
# Redirect any removed pages to their new home.
("/docs/components/style-props", "/docs/components/props"),
("/docs/components/conditional-props", "/docs/components/conditional-rendering"),
("/docs/enterprise", "/docs/enterprise/overview"),
("/docs/pages/routes", "/docs/pages/overview"),
("/docs/assets/referencing_assets", "/docs/assets/overview"),
("/changelog", "https://github.com/reflex-dev/reflex/releases"),
(
"/blog/2025-10-27-top-10-data-visualization-libraries",
"/blog/2025-01-27-top-10-data-visualization-libraries",
),
]
for source, target in redirects:
if _check_whitelisted_path(target):
app.add_page(lambda: rx.fragment(), route=source, on_load=rx.redirect(target))
app.add_page(page404.component, route=page404.path)