forked from reflex-dev/reflex-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcweb.py
114 lines (99 loc) · 4.41 KB
/
pcweb.py
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
"""The main Reflex website."""
import os
import sys
import reflex as rx
from pcweb import styles
from pcweb.pages import page404, routes
from pcweb.pages.docs import outblocks, exec_blocks
from pcweb.whitelist import _check_whitelisted_path
from pcweb.telemetry import get_pixel_website_trackers
from pcweb.meta.meta import favicons_links
# 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 = 125
# Execute all the exec blocks in the documents.
for doc, href in outblocks:
exec_blocks(doc, href)
# Create the app.
app = rx.App(
style=styles.BASE_STYLE,
stylesheets=styles.STYLESHEETS,
theme=rx.theme(
has_background=True,
radius="large",
accent_color="violet",
),
head_components=get_pixel_website_trackers() + favicons_links(),
)
# 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.png" 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", "/docs/getting-started/introduction"),
("/docs/getting-started", "/docs/getting-started/introduction"),
("/docs/components", "/docs/components/overview"),
("/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/tutorial", "/docs/tutorial/intro"),
("/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/substates", "/docs/substates/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"),
# Recipes
("/docs/recipes/auth", "/docs/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/[...component]", "https://chakra.reflex.run/introduction/"),
("/gallery", "/templates"),
]
for source, target in redirects:
app.add_page(lambda: rx.fragment(), route=source, on_load=rx.redirect(target))
app.add_custom_404_page(page404.component)