webstudio 0.197.0 → 0.199.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli.js +1070 -1188
- package/package.json +16 -10
- package/templates/defaults/app/constants.mjs +0 -1
- package/templates/defaults/app/route-templates/html.tsx +15 -61
- package/templates/defaults/package.json +8 -7
- package/templates/internal/package.json +5 -4
- package/templates/netlify-edge-functions/app/constants.mjs +0 -1
- package/templates/netlify-functions/app/constants.mjs +0 -1
- package/templates/react-router-docker/.dockerignore +4 -0
- package/templates/react-router-docker/Dockerfile +23 -0
- package/templates/react-router-docker/app/constants.mjs +18 -0
- package/templates/react-router-docker/app/extension.ts +13 -0
- package/templates/react-router-docker/app/root.tsx +35 -0
- package/templates/react-router-docker/app/route-templates/default-sitemap.tsx +34 -0
- package/templates/react-router-docker/app/route-templates/html.tsx +295 -0
- package/templates/react-router-docker/app/route-templates/redirect.tsx +6 -0
- package/templates/react-router-docker/app/route-templates/xml.tsx +85 -0
- package/templates/react-router-docker/app/routes/[_image].$.ts +24 -0
- package/templates/react-router-docker/app/routes/[robots.txt].tsx +24 -0
- package/templates/react-router-docker/package.json +36 -0
- package/templates/react-router-docker/public/favicon.ico +0 -0
- package/templates/react-router-docker/tsconfig.json +18 -0
- package/templates/react-router-docker/vite.config.ts +6 -0
- package/templates/ssg/app/constants.mjs +0 -1
- package/templates/ssg/package.json +7 -6
- package/templates/ssg/vike.d.ts +0 -1
- package/templates/ssg-netlify/app/constants.mjs +0 -6
- package/templates/ssg-vercel/app/constants.mjs +0 -6
- package/templates/ssg-vercel/public/vercel.json +2 -2
- package/templates/vercel/app/constants.mjs +0 -1
- package/templates/vercel/vercel.json +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webstudio",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.199.0",
|
|
4
4
|
"description": "Webstudio CLI",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@netlify/remix-adapter": "^2.5.1",
|
|
49
49
|
"@netlify/remix-edge-adapter": "3.4.2",
|
|
50
|
+
"@react-router/dev": "^7.1.1",
|
|
50
51
|
"@remix-run/cloudflare": "^2.15.2",
|
|
51
52
|
"@remix-run/cloudflare-pages": "^2.15.2",
|
|
52
53
|
"@remix-run/dev": "^2.15.2",
|
|
@@ -57,21 +58,26 @@
|
|
|
57
58
|
"@types/react-dom": "^18.2.25",
|
|
58
59
|
"@types/yargs": "^17.0.33",
|
|
59
60
|
"@vitejs/plugin-react": "^4.3.4",
|
|
61
|
+
"h3": "^1.13.1",
|
|
62
|
+
"ipx": "^3.0.1",
|
|
60
63
|
"prettier": "3.4.2",
|
|
61
64
|
"react-dom": "18.3.0-canary-14898b6a9-20240318",
|
|
65
|
+
"react-router": "^7.1.1",
|
|
62
66
|
"ts-expect": "^1.3.0",
|
|
63
67
|
"vike": "^0.4.210",
|
|
64
68
|
"vite": "^5.4.11",
|
|
65
|
-
"vitest": "^
|
|
69
|
+
"vitest": "^3.0.2",
|
|
66
70
|
"wrangler": "^3.63.2",
|
|
67
|
-
"@webstudio-is/http-client": "0.
|
|
68
|
-
"@webstudio-is/
|
|
69
|
-
"@webstudio-is/
|
|
70
|
-
"@webstudio-is/sdk": "0.
|
|
71
|
-
"@webstudio-is/sdk
|
|
72
|
-
"@webstudio-is/sdk-components-react
|
|
73
|
-
"@webstudio-is/sdk-components-react-radix": "0.
|
|
74
|
-
"@webstudio-is/tsconfig": "1.0.7"
|
|
71
|
+
"@webstudio-is/http-client": "0.199.0",
|
|
72
|
+
"@webstudio-is/sdk": "0.199.0",
|
|
73
|
+
"@webstudio-is/image": "0.199.0",
|
|
74
|
+
"@webstudio-is/sdk-components-animation": "0.199.0",
|
|
75
|
+
"@webstudio-is/react-sdk": "0.199.0",
|
|
76
|
+
"@webstudio-is/sdk-components-react": "0.199.0",
|
|
77
|
+
"@webstudio-is/sdk-components-react-radix": "0.199.0",
|
|
78
|
+
"@webstudio-is/tsconfig": "1.0.7",
|
|
79
|
+
"@webstudio-is/sdk-components-react-router": "0.199.0",
|
|
80
|
+
"@webstudio-is/sdk-components-react-remix": "0.199.0"
|
|
75
81
|
},
|
|
76
82
|
"scripts": {
|
|
77
83
|
"typecheck": "tsc",
|
|
@@ -16,7 +16,11 @@ import {
|
|
|
16
16
|
formIdFieldName,
|
|
17
17
|
formBotFieldName,
|
|
18
18
|
} from "@webstudio-is/sdk/runtime";
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
ReactSdkContext,
|
|
21
|
+
PageSettingsMeta,
|
|
22
|
+
PageSettingsTitle,
|
|
23
|
+
} from "@webstudio-is/react-sdk/runtime";
|
|
20
24
|
import {
|
|
21
25
|
Page,
|
|
22
26
|
siteName,
|
|
@@ -117,33 +121,10 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
|
|
117
121
|
if (data === undefined) {
|
|
118
122
|
return metas;
|
|
119
123
|
}
|
|
120
|
-
const { pageMeta } = data;
|
|
121
|
-
|
|
122
|
-
if (data.url) {
|
|
123
|
-
metas.push({
|
|
124
|
-
property: "og:url",
|
|
125
|
-
content: data.url,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (pageMeta.title) {
|
|
130
|
-
metas.push({ title: pageMeta.title });
|
|
131
|
-
|
|
132
|
-
metas.push({
|
|
133
|
-
property: "og:title",
|
|
134
|
-
content: pageMeta.title,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
metas.push({ property: "og:type", content: "website" });
|
|
139
124
|
|
|
140
125
|
const origin = `https://${data.host}`;
|
|
141
126
|
|
|
142
127
|
if (siteName) {
|
|
143
|
-
metas.push({
|
|
144
|
-
property: "og:site_name",
|
|
145
|
-
content: siteName,
|
|
146
|
-
});
|
|
147
128
|
metas.push({
|
|
148
129
|
"script:ld+json": {
|
|
149
130
|
"@context": "https://schema.org",
|
|
@@ -154,42 +135,6 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
|
|
154
135
|
});
|
|
155
136
|
}
|
|
156
137
|
|
|
157
|
-
if (pageMeta.excludePageFromSearch) {
|
|
158
|
-
metas.push({
|
|
159
|
-
name: "robots",
|
|
160
|
-
content: "noindex, nofollow",
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (pageMeta.description) {
|
|
165
|
-
metas.push({
|
|
166
|
-
name: "description",
|
|
167
|
-
content: pageMeta.description,
|
|
168
|
-
});
|
|
169
|
-
metas.push({
|
|
170
|
-
property: "og:description",
|
|
171
|
-
content: pageMeta.description,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (pageMeta.socialImageAssetName) {
|
|
176
|
-
metas.push({
|
|
177
|
-
property: "og:image",
|
|
178
|
-
content: `https://${data.host}${imageLoader({
|
|
179
|
-
src: pageMeta.socialImageAssetName,
|
|
180
|
-
// Do not transform social image (not enough information do we need to do this)
|
|
181
|
-
format: "raw",
|
|
182
|
-
})}`,
|
|
183
|
-
});
|
|
184
|
-
} else if (pageMeta.socialImageUrl) {
|
|
185
|
-
metas.push({
|
|
186
|
-
property: "og:image",
|
|
187
|
-
content: pageMeta.socialImageUrl,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
metas.push(...pageMeta.custom);
|
|
192
|
-
|
|
193
138
|
return metas;
|
|
194
139
|
};
|
|
195
140
|
|
|
@@ -323,7 +268,8 @@ export const action = async ({
|
|
|
323
268
|
};
|
|
324
269
|
|
|
325
270
|
const Outlet = () => {
|
|
326
|
-
const { system, resources, url } =
|
|
271
|
+
const { system, resources, url, pageMeta, host } =
|
|
272
|
+
useLoaderData<typeof loader>();
|
|
327
273
|
return (
|
|
328
274
|
<ReactSdkContext.Provider
|
|
329
275
|
value={{
|
|
@@ -334,6 +280,14 @@ const Outlet = () => {
|
|
|
334
280
|
>
|
|
335
281
|
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}
|
|
336
282
|
<Page key={url} system={system} />
|
|
283
|
+
<PageSettingsMeta
|
|
284
|
+
url={url}
|
|
285
|
+
pageMeta={pageMeta}
|
|
286
|
+
host={host}
|
|
287
|
+
siteName={siteName}
|
|
288
|
+
imageLoader={imageLoader}
|
|
289
|
+
/>
|
|
290
|
+
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
|
337
291
|
</ReactSdkContext.Provider>
|
|
338
292
|
);
|
|
339
293
|
};
|
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
"@remix-run/node": "2.15.2",
|
|
12
12
|
"@remix-run/react": "2.15.2",
|
|
13
13
|
"@remix-run/server-runtime": "2.15.2",
|
|
14
|
-
"@webstudio-is/
|
|
15
|
-
"@webstudio-is/
|
|
16
|
-
"@webstudio-is/sdk
|
|
17
|
-
"@webstudio-is/sdk-components-react": "0.
|
|
18
|
-
"@webstudio-is/
|
|
19
|
-
"@webstudio-is/sdk": "0.
|
|
14
|
+
"@webstudio-is/image": "0.199.0",
|
|
15
|
+
"@webstudio-is/react-sdk": "0.199.0",
|
|
16
|
+
"@webstudio-is/sdk": "0.199.0",
|
|
17
|
+
"@webstudio-is/sdk-components-react": "0.199.0",
|
|
18
|
+
"@webstudio-is/sdk-components-animation": "0.199.0",
|
|
19
|
+
"@webstudio-is/sdk-components-react-radix": "0.199.0",
|
|
20
|
+
"@webstudio-is/sdk-components-react-remix": "0.199.0",
|
|
20
21
|
"isbot": "^5.1.19",
|
|
21
22
|
"react": "18.3.0-canary-14898b6a9-20240318",
|
|
22
23
|
"react-dom": "18.3.0-canary-14898b6a9-20240318"
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"@remix-run/dev": "2.15.2",
|
|
26
27
|
"@types/react": "^18.2.70",
|
|
27
28
|
"@types/react-dom": "^18.2.25",
|
|
28
|
-
"typescript": "5.7.
|
|
29
|
+
"typescript": "5.7.3",
|
|
29
30
|
"vite": "^5.4.11"
|
|
30
31
|
},
|
|
31
32
|
"engines": {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
+
"@webstudio-is/image": "workspace:*",
|
|
3
4
|
"@webstudio-is/react-sdk": "workspace:*",
|
|
4
|
-
"@webstudio-is/sdk
|
|
5
|
-
"@webstudio-is/sdk-components-
|
|
5
|
+
"@webstudio-is/sdk": "workspace:*",
|
|
6
|
+
"@webstudio-is/sdk-components-animation": "workspace:*",
|
|
6
7
|
"@webstudio-is/sdk-components-react": "workspace:*",
|
|
7
|
-
"@webstudio-is/
|
|
8
|
-
"@webstudio-is/sdk": "workspace:*"
|
|
8
|
+
"@webstudio-is/sdk-components-react-radix": "workspace:*",
|
|
9
|
+
"@webstudio-is/sdk-components-react-remix": "workspace:*"
|
|
9
10
|
}
|
|
10
11
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
FROM node:22-alpine AS development-dependencies-env
|
|
2
|
+
COPY . /app
|
|
3
|
+
WORKDIR /app
|
|
4
|
+
RUN npm install
|
|
5
|
+
|
|
6
|
+
FROM node:22-alpine AS production-dependencies-env
|
|
7
|
+
COPY ./package.json package-lock.json /app/
|
|
8
|
+
WORKDIR /app
|
|
9
|
+
RUN npm install --omit=dev
|
|
10
|
+
|
|
11
|
+
FROM node:22-alpine AS build-env
|
|
12
|
+
COPY . /app/
|
|
13
|
+
COPY --from=development-dependencies-env /app/node_modules /app/node_modules
|
|
14
|
+
WORKDIR /app
|
|
15
|
+
RUN npm run build
|
|
16
|
+
|
|
17
|
+
FROM node:22-alpine
|
|
18
|
+
COPY ./package.json package-lock.json /app/
|
|
19
|
+
COPY --from=production-dependencies-env /app/node_modules /app/node_modules
|
|
20
|
+
COPY --from=build-env /app/build /app/build
|
|
21
|
+
WORKDIR /app
|
|
22
|
+
# there is a DOMAINS env with comma separated allowed domains for image processing
|
|
23
|
+
CMD ["npm", "run", "start"]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We use mjs extension as constants in this file is shared with the build script
|
|
3
|
+
* and we use `node --eval` to extract the constants.
|
|
4
|
+
*/
|
|
5
|
+
export const assetBaseUrl = "/assets/";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type {import("@webstudio-is/image").ImageLoader}
|
|
9
|
+
*/
|
|
10
|
+
export const imageLoader = (props) => {
|
|
11
|
+
if (props.format === "raw") {
|
|
12
|
+
return props.src;
|
|
13
|
+
}
|
|
14
|
+
// handle absolute urls
|
|
15
|
+
const path = URL.canParse(props.src) ? `/${props.src}` : props.src;
|
|
16
|
+
// https://github.com/unjs/ipx?tab=readme-ov-file#modifiers
|
|
17
|
+
return `/_image/w_${props.width},q_${props.quality}${path}`;
|
|
18
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ResourceRequest } from "@webstudio-is/sdk";
|
|
2
|
+
|
|
3
|
+
declare module "react-router" {
|
|
4
|
+
interface AppLoadContext {
|
|
5
|
+
EXCLUDE_FROM_SEARCH: boolean;
|
|
6
|
+
getDefaultActionResource?: (options: {
|
|
7
|
+
url: URL;
|
|
8
|
+
projectId: string;
|
|
9
|
+
contactEmail: string;
|
|
10
|
+
formData: FormData;
|
|
11
|
+
}) => ResourceRequest;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
|
|
3
|
+
import { Links, Meta, Outlet, useMatches } from "react-router";
|
|
4
|
+
// @todo think about how to make __generated__ typeable
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { CustomCode } from "./__generated__/_index";
|
|
7
|
+
|
|
8
|
+
const Root = () => {
|
|
9
|
+
// Get language from matches
|
|
10
|
+
const matches = useMatches();
|
|
11
|
+
|
|
12
|
+
const lastMatchWithLanguage = matches.findLast((match) => {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
const language = match?.data?.pageMeta?.language;
|
|
15
|
+
return language != null;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
const lang = lastMatchWithLanguage?.data?.pageMeta?.language ?? "en";
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<html lang={lang}>
|
|
23
|
+
<head>
|
|
24
|
+
<meta charSet="utf-8" />
|
|
25
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
26
|
+
<Meta />
|
|
27
|
+
<Links />
|
|
28
|
+
<CustomCode />
|
|
29
|
+
</head>
|
|
30
|
+
<Outlet />
|
|
31
|
+
</html>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default Root;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { LoaderFunctionArgs } from "react-router";
|
|
2
|
+
import { sitemap } from "__SITEMAP__";
|
|
3
|
+
|
|
4
|
+
export const loader = (arg: LoaderFunctionArgs) => {
|
|
5
|
+
const host =
|
|
6
|
+
arg.request.headers.get("x-forwarded-host") ||
|
|
7
|
+
arg.request.headers.get("host") ||
|
|
8
|
+
"";
|
|
9
|
+
|
|
10
|
+
const urls = sitemap.map((page) => {
|
|
11
|
+
const url = new URL(`https://${host}${page.path}`);
|
|
12
|
+
|
|
13
|
+
return `
|
|
14
|
+
<url>
|
|
15
|
+
<loc>${url.href}</loc>
|
|
16
|
+
<lastmod>${page.lastModified.split("T")[0]}</lastmod>
|
|
17
|
+
</url>
|
|
18
|
+
`;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return new Response(
|
|
22
|
+
`<?xml version="1.0" encoding="UTF-8"?>
|
|
23
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
24
|
+
${urls.join("")}
|
|
25
|
+
</urlset>
|
|
26
|
+
`,
|
|
27
|
+
{
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/xml",
|
|
30
|
+
},
|
|
31
|
+
status: 200,
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
};
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type MetaFunction,
|
|
3
|
+
type LinksFunction,
|
|
4
|
+
type LinkDescriptor,
|
|
5
|
+
type ActionFunctionArgs,
|
|
6
|
+
type LoaderFunctionArgs,
|
|
7
|
+
type HeadersFunction,
|
|
8
|
+
data,
|
|
9
|
+
redirect,
|
|
10
|
+
useLoaderData,
|
|
11
|
+
} from "react-router";
|
|
12
|
+
import {
|
|
13
|
+
isLocalResource,
|
|
14
|
+
loadResource,
|
|
15
|
+
loadResources,
|
|
16
|
+
formIdFieldName,
|
|
17
|
+
formBotFieldName,
|
|
18
|
+
} from "@webstudio-is/sdk/runtime";
|
|
19
|
+
import {
|
|
20
|
+
ReactSdkContext,
|
|
21
|
+
PageSettingsMeta,
|
|
22
|
+
PageSettingsTitle,
|
|
23
|
+
} from "@webstudio-is/react-sdk/runtime";
|
|
24
|
+
import {
|
|
25
|
+
Page,
|
|
26
|
+
siteName,
|
|
27
|
+
favIconAsset,
|
|
28
|
+
pageFontAssets,
|
|
29
|
+
pageBackgroundImageAssets,
|
|
30
|
+
} from "__CLIENT__";
|
|
31
|
+
import {
|
|
32
|
+
getResources,
|
|
33
|
+
getPageMeta,
|
|
34
|
+
getRemixParams,
|
|
35
|
+
projectId,
|
|
36
|
+
contactEmail,
|
|
37
|
+
} from "__SERVER__";
|
|
38
|
+
import { assetBaseUrl, imageLoader } from "__CONSTANTS__";
|
|
39
|
+
import css from "__CSS__?url";
|
|
40
|
+
import { sitemap } from "__SITEMAP__";
|
|
41
|
+
|
|
42
|
+
const customFetch: typeof fetch = (input, init) => {
|
|
43
|
+
if (typeof input !== "string") {
|
|
44
|
+
return fetch(input, init);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isLocalResource(input, "sitemap.xml")) {
|
|
48
|
+
// @todo: dynamic import sitemap ???
|
|
49
|
+
const response = new Response(JSON.stringify(sitemap));
|
|
50
|
+
response.headers.set("content-type", "application/json; charset=utf-8");
|
|
51
|
+
return Promise.resolve(response);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return fetch(input, init);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const loader = async (arg: LoaderFunctionArgs) => {
|
|
58
|
+
const url = new URL(arg.request.url);
|
|
59
|
+
const host =
|
|
60
|
+
arg.request.headers.get("x-forwarded-host") ||
|
|
61
|
+
arg.request.headers.get("host") ||
|
|
62
|
+
"";
|
|
63
|
+
url.host = host;
|
|
64
|
+
url.protocol = "https";
|
|
65
|
+
|
|
66
|
+
const params = getRemixParams(arg.params);
|
|
67
|
+
const system = {
|
|
68
|
+
params,
|
|
69
|
+
search: Object.fromEntries(url.searchParams),
|
|
70
|
+
origin: url.origin,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const resources = await loadResources(
|
|
74
|
+
customFetch,
|
|
75
|
+
getResources({ system }).data
|
|
76
|
+
);
|
|
77
|
+
const pageMeta = getPageMeta({ system, resources });
|
|
78
|
+
|
|
79
|
+
if (pageMeta.redirect) {
|
|
80
|
+
const status =
|
|
81
|
+
pageMeta.status === 301 || pageMeta.status === 302
|
|
82
|
+
? pageMeta.status
|
|
83
|
+
: 302;
|
|
84
|
+
throw redirect(pageMeta.redirect, status);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// typecheck
|
|
88
|
+
arg.context.EXCLUDE_FROM_SEARCH satisfies boolean;
|
|
89
|
+
|
|
90
|
+
if (arg.context.EXCLUDE_FROM_SEARCH) {
|
|
91
|
+
pageMeta.excludePageFromSearch = arg.context.EXCLUDE_FROM_SEARCH;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return data(
|
|
95
|
+
{
|
|
96
|
+
host,
|
|
97
|
+
url: url.href,
|
|
98
|
+
system,
|
|
99
|
+
resources,
|
|
100
|
+
pageMeta,
|
|
101
|
+
},
|
|
102
|
+
// No way for current information to change, so add cache for 10 minutes
|
|
103
|
+
// In case of CRM Data, this should be set to 0
|
|
104
|
+
{
|
|
105
|
+
status: pageMeta.status,
|
|
106
|
+
headers: {
|
|
107
|
+
"Cache-Control": "public, max-age=600",
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const headers: HeadersFunction = () => {
|
|
114
|
+
return {
|
|
115
|
+
"Cache-Control": "public, max-age=0, must-revalidate",
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
|
120
|
+
const metas: ReturnType<MetaFunction> = [];
|
|
121
|
+
if (data === undefined) {
|
|
122
|
+
return metas;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const origin = `https://${data.host}`;
|
|
126
|
+
|
|
127
|
+
if (siteName) {
|
|
128
|
+
metas.push({
|
|
129
|
+
"script:ld+json": {
|
|
130
|
+
"@context": "https://schema.org",
|
|
131
|
+
"@type": "WebSite",
|
|
132
|
+
name: siteName,
|
|
133
|
+
url: origin,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return metas;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const links: LinksFunction = () => {
|
|
142
|
+
const result: LinkDescriptor[] = [];
|
|
143
|
+
|
|
144
|
+
result.push({
|
|
145
|
+
rel: "stylesheet",
|
|
146
|
+
href: css,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
if (favIconAsset) {
|
|
150
|
+
result.push({
|
|
151
|
+
rel: "icon",
|
|
152
|
+
href: imageLoader({
|
|
153
|
+
src: `${assetBaseUrl}${favIconAsset.name}`,
|
|
154
|
+
// width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
|
|
155
|
+
width: 144,
|
|
156
|
+
height: 144,
|
|
157
|
+
fit: "pad",
|
|
158
|
+
quality: 100,
|
|
159
|
+
format: "auto",
|
|
160
|
+
}),
|
|
161
|
+
type: undefined,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
for (const asset of pageFontAssets) {
|
|
166
|
+
result.push({
|
|
167
|
+
rel: "preload",
|
|
168
|
+
href: `${assetBaseUrl}${asset.name}`,
|
|
169
|
+
as: "font",
|
|
170
|
+
crossOrigin: "anonymous",
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
for (const backgroundImageAsset of pageBackgroundImageAssets) {
|
|
175
|
+
result.push({
|
|
176
|
+
rel: "preload",
|
|
177
|
+
href: `${assetBaseUrl}${backgroundImageAsset.name}`,
|
|
178
|
+
as: "image",
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return result;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const getRequestHost = (request: Request): string =>
|
|
186
|
+
request.headers.get("x-forwarded-host") || request.headers.get("host") || "";
|
|
187
|
+
|
|
188
|
+
export const action = async ({
|
|
189
|
+
request,
|
|
190
|
+
context,
|
|
191
|
+
}: ActionFunctionArgs): Promise<
|
|
192
|
+
{ success: true } | { success: false; errors: string[] }
|
|
193
|
+
> => {
|
|
194
|
+
try {
|
|
195
|
+
const url = new URL(request.url);
|
|
196
|
+
url.host = getRequestHost(request);
|
|
197
|
+
|
|
198
|
+
const formData = await request.formData();
|
|
199
|
+
|
|
200
|
+
const system = {
|
|
201
|
+
params: {},
|
|
202
|
+
search: {},
|
|
203
|
+
origin: url.origin,
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const resourceName = formData.get(formIdFieldName);
|
|
207
|
+
let resource =
|
|
208
|
+
typeof resourceName === "string"
|
|
209
|
+
? getResources({ system }).action.get(resourceName)
|
|
210
|
+
: undefined;
|
|
211
|
+
|
|
212
|
+
const formBotValue = formData.get(formBotFieldName);
|
|
213
|
+
|
|
214
|
+
if (formBotValue == null || typeof formBotValue !== "string") {
|
|
215
|
+
throw new Error("Form bot field not found");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const submitTime = parseInt(formBotValue, 16);
|
|
219
|
+
// Assumes that the difference between the server time and the form submission time,
|
|
220
|
+
// including any client-server time drift, is within a 5-minute range.
|
|
221
|
+
// Note: submitTime might be NaN because formBotValue can be any string used for logging purposes.
|
|
222
|
+
// Example: `formBotValue: jsdom`, or `formBotValue: headless-env`
|
|
223
|
+
if (
|
|
224
|
+
Number.isNaN(submitTime) ||
|
|
225
|
+
Math.abs(Date.now() - submitTime) > 1000 * 60 * 5
|
|
226
|
+
) {
|
|
227
|
+
throw new Error(`Form bot value invalid ${formBotValue}`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
formData.delete(formIdFieldName);
|
|
231
|
+
formData.delete(formBotFieldName);
|
|
232
|
+
|
|
233
|
+
if (resource) {
|
|
234
|
+
resource.headers.push({
|
|
235
|
+
name: "Content-Type",
|
|
236
|
+
value: "application/json",
|
|
237
|
+
});
|
|
238
|
+
resource.body = Object.fromEntries(formData);
|
|
239
|
+
} else {
|
|
240
|
+
if (contactEmail === undefined) {
|
|
241
|
+
throw new Error("Contact email not found");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
resource = context.getDefaultActionResource?.({
|
|
245
|
+
url,
|
|
246
|
+
projectId,
|
|
247
|
+
contactEmail,
|
|
248
|
+
formData,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (resource === undefined) {
|
|
253
|
+
throw Error("Resource not found");
|
|
254
|
+
}
|
|
255
|
+
const { ok, statusText } = await loadResource(fetch, resource);
|
|
256
|
+
if (ok) {
|
|
257
|
+
return { success: true };
|
|
258
|
+
}
|
|
259
|
+
return { success: false, errors: [statusText] };
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.error(error);
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
success: false,
|
|
265
|
+
errors: [error instanceof Error ? error.message : "Unknown error"],
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const Outlet = () => {
|
|
271
|
+
const { system, resources, url, pageMeta, host } =
|
|
272
|
+
useLoaderData<typeof loader>();
|
|
273
|
+
return (
|
|
274
|
+
<ReactSdkContext.Provider
|
|
275
|
+
value={{
|
|
276
|
+
imageLoader,
|
|
277
|
+
assetBaseUrl,
|
|
278
|
+
resources,
|
|
279
|
+
}}
|
|
280
|
+
>
|
|
281
|
+
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}
|
|
282
|
+
<Page key={url} system={system} />
|
|
283
|
+
<PageSettingsMeta
|
|
284
|
+
url={url}
|
|
285
|
+
pageMeta={pageMeta}
|
|
286
|
+
host={host}
|
|
287
|
+
siteName={siteName}
|
|
288
|
+
imageLoader={imageLoader}
|
|
289
|
+
/>
|
|
290
|
+
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
|
291
|
+
</ReactSdkContext.Provider>
|
|
292
|
+
);
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
export default Outlet;
|