webstudio 0.0.0-021f2d4
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/LICENSE +661 -0
- package/README.md +145 -0
- package/bin.js +5 -0
- package/lib/cli.js +6578 -0
- package/package.json +88 -0
- package/templates/cloudflare/WS_CF_README.md +48 -0
- package/templates/cloudflare/functions/[[path]].ts +9 -0
- package/templates/cloudflare/load-context.ts +9 -0
- package/templates/cloudflare/package.json +22 -0
- package/templates/cloudflare/tsconfig.json +18 -0
- package/templates/cloudflare/vite.config.ts +21 -0
- package/templates/cloudflare/worker-configuration.d.ts +3 -0
- package/templates/cloudflare/wrangler.toml +55 -0
- package/templates/defaults/app/constants.mjs +12 -0
- package/templates/defaults/app/extension.ts +16 -0
- package/templates/defaults/app/root.tsx +35 -0
- package/templates/defaults/app/route-templates/default-sitemap.tsx +34 -0
- package/templates/defaults/app/route-templates/html.tsx +297 -0
- package/templates/defaults/app/route-templates/redirect.tsx +6 -0
- package/templates/defaults/app/route-templates/xml.tsx +85 -0
- package/templates/defaults/app/routes/[robots.txt].tsx +24 -0
- package/templates/defaults/package.json +35 -0
- package/templates/defaults/public/favicon.ico +0 -0
- package/templates/defaults/tsconfig.json +22 -0
- package/templates/defaults/vite.config.ts +16 -0
- package/templates/internal/package.json +11 -0
- package/templates/internal/tsconfig.json +5 -0
- package/templates/netlify-edge-functions/app/constants.mjs +29 -0
- package/templates/netlify-edge-functions/app/entry.server.tsx +21 -0
- package/templates/netlify-edge-functions/netlify.toml +16 -0
- package/templates/netlify-edge-functions/package.json +9 -0
- package/templates/netlify-edge-functions/vite.config.ts +18 -0
- package/templates/netlify-functions/app/constants.mjs +29 -0
- package/templates/netlify-functions/app/entry.server.tsx +1 -0
- package/templates/netlify-functions/netlify.toml +16 -0
- package/templates/netlify-functions/package.json +9 -0
- package/templates/netlify-functions/vite.config.ts +18 -0
- package/templates/react-router/app/extension.ts +13 -0
- package/templates/react-router/app/root.tsx +35 -0
- package/templates/react-router/app/route-templates/default-sitemap.tsx +34 -0
- package/templates/react-router/app/route-templates/html.tsx +295 -0
- package/templates/react-router/app/route-templates/redirect.tsx +6 -0
- package/templates/react-router/app/route-templates/xml.tsx +85 -0
- package/templates/react-router/app/routes/[robots.txt].tsx +24 -0
- package/templates/react-router/app/routes.ts +4 -0
- package/templates/react-router/package.json +36 -0
- package/templates/react-router/public/favicon.ico +0 -0
- package/templates/react-router/tsconfig.json +18 -0
- package/templates/react-router/vite.config.ts +6 -0
- package/templates/react-router-docker/.dockerignore +4 -0
- package/templates/react-router-docker/Dockerfile +19 -0
- package/templates/react-router-docker/app/constants.mjs +18 -0
- package/templates/react-router-docker/app/routes/[_image].$.ts +24 -0
- package/templates/react-router-docker/package.json +7 -0
- package/templates/react-router-netlify/app/constants.mjs +29 -0
- package/templates/react-router-netlify/netlify.toml +6 -0
- package/templates/react-router-netlify/package.json +9 -0
- package/templates/react-router-netlify/vite.config.ts +7 -0
- package/templates/saas-helpers/package.json +6 -0
- package/templates/saas-helpers/tsconfig.json +18 -0
- package/templates/ssg/app/constants.mjs +13 -0
- package/templates/ssg/app/route-templates/html/+Head.tsx +92 -0
- package/templates/ssg/app/route-templates/html/+Page.tsx +21 -0
- package/templates/ssg/app/route-templates/html/+data.ts +37 -0
- package/templates/ssg/package.json +31 -0
- package/templates/ssg/pages/+config.ts +12 -0
- package/templates/ssg/public/favicon.ico +0 -0
- package/templates/ssg/renderer/+onRenderClient.tsx +30 -0
- package/templates/ssg/renderer/+onRenderHtml.tsx +29 -0
- package/templates/ssg/tsconfig.json +22 -0
- package/templates/ssg/vike.d.ts +25 -0
- package/templates/ssg/vite.config.ts +7 -0
- package/templates/ssg-netlify/app/constants.mjs +30 -0
- package/templates/ssg-vercel/app/constants.mjs +26 -0
- package/templates/ssg-vercel/public/vercel.json +11 -0
- package/templates/vercel/.vercelignore +8 -0
- package/templates/vercel/app/constants.mjs +25 -0
- package/templates/vercel/package.json +1 -0
- package/templates/vercel/vercel.json +11 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { renderToString } from "react-dom/server";
|
|
2
|
+
import { type LoaderFunctionArgs, redirect } from "@remix-run/server-runtime";
|
|
3
|
+
import { isLocalResource, loadResources } from "@webstudio-is/sdk/runtime";
|
|
4
|
+
import {
|
|
5
|
+
ReactSdkContext,
|
|
6
|
+
xmlNodeTagSuffix,
|
|
7
|
+
} from "@webstudio-is/react-sdk/runtime";
|
|
8
|
+
import { Page } from "__CLIENT__";
|
|
9
|
+
import { getPageMeta, getRemixParams, getResources } from "__SERVER__";
|
|
10
|
+
import { assetBaseUrl, imageLoader } from "__CONSTANTS__";
|
|
11
|
+
import { sitemap } from "__SITEMAP__";
|
|
12
|
+
|
|
13
|
+
const customFetch: typeof fetch = (input, init) => {
|
|
14
|
+
if (typeof input !== "string") {
|
|
15
|
+
return fetch(input, init);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (isLocalResource(input, "sitemap.xml")) {
|
|
19
|
+
// @todo: dynamic import sitemap ???
|
|
20
|
+
const response = new Response(JSON.stringify(sitemap));
|
|
21
|
+
response.headers.set("content-type", "application/json; charset=utf-8");
|
|
22
|
+
return Promise.resolve(response);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return fetch(input, init);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const loader = async (arg: LoaderFunctionArgs) => {
|
|
29
|
+
const url = new URL(arg.request.url);
|
|
30
|
+
const host =
|
|
31
|
+
arg.request.headers.get("x-forwarded-host") ||
|
|
32
|
+
arg.request.headers.get("host") ||
|
|
33
|
+
"";
|
|
34
|
+
url.host = host;
|
|
35
|
+
url.protocol = "https";
|
|
36
|
+
|
|
37
|
+
const params = getRemixParams(arg.params);
|
|
38
|
+
|
|
39
|
+
const system = {
|
|
40
|
+
params,
|
|
41
|
+
search: Object.fromEntries(url.searchParams),
|
|
42
|
+
origin: url.origin,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const resources = await loadResources(
|
|
46
|
+
customFetch,
|
|
47
|
+
getResources({ system }).data
|
|
48
|
+
);
|
|
49
|
+
const pageMeta = getPageMeta({ system, resources });
|
|
50
|
+
|
|
51
|
+
if (pageMeta.redirect) {
|
|
52
|
+
const status =
|
|
53
|
+
pageMeta.status === 301 || pageMeta.status === 302
|
|
54
|
+
? pageMeta.status
|
|
55
|
+
: 302;
|
|
56
|
+
return redirect(pageMeta.redirect, status);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// typecheck
|
|
60
|
+
arg.context.EXCLUDE_FROM_SEARCH satisfies boolean;
|
|
61
|
+
|
|
62
|
+
let text = renderToString(
|
|
63
|
+
<ReactSdkContext.Provider
|
|
64
|
+
value={{
|
|
65
|
+
imageLoader,
|
|
66
|
+
assetBaseUrl,
|
|
67
|
+
resources,
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
<Page system={system} />
|
|
71
|
+
</ReactSdkContext.Provider>
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// Xml is wrapped with <svg> to prevent React from hoisting elements like <title>, <meta>, and <link> out of their intended scope during rendering.
|
|
75
|
+
// More details: https://github.com/facebook/react/blob/7c8e5e7ab8bb63de911637892392c5efd8ce1d0f/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js#L3083
|
|
76
|
+
text = text.replace(/^<svg>/g, "").replace(/<\/svg>$/g, "");
|
|
77
|
+
|
|
78
|
+
// React has issues rendering certain elements, such as errors when a <link> element has children.
|
|
79
|
+
// To render XML, we wrap it with an <svg> tag and add a suffix to avoid React's default behavior on these elements.
|
|
80
|
+
text = text.replaceAll(xmlNodeTagSuffix, "");
|
|
81
|
+
|
|
82
|
+
return new Response(`<?xml version="1.0" encoding="UTF-8"?>\n${text}`, {
|
|
83
|
+
headers: { "Content-Type": "application/xml" },
|
|
84
|
+
});
|
|
85
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LoaderFunctionArgs } from "@remix-run/server-runtime";
|
|
2
|
+
|
|
3
|
+
export const loader = (arg: LoaderFunctionArgs) => {
|
|
4
|
+
const host =
|
|
5
|
+
arg.request.headers.get("x-forwarded-host") ||
|
|
6
|
+
arg.request.headers.get("host") ||
|
|
7
|
+
"";
|
|
8
|
+
|
|
9
|
+
return new Response(
|
|
10
|
+
`
|
|
11
|
+
User-agent: *
|
|
12
|
+
Disallow: /api/
|
|
13
|
+
|
|
14
|
+
Sitemap: https://${host}/sitemap.xml
|
|
15
|
+
|
|
16
|
+
`,
|
|
17
|
+
{
|
|
18
|
+
headers: {
|
|
19
|
+
"Content-Type": "text/plain",
|
|
20
|
+
},
|
|
21
|
+
status: 200,
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"private": true,
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "remix vite:build",
|
|
7
|
+
"dev": "remix vite:dev",
|
|
8
|
+
"typecheck": "tsc"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@remix-run/node": "2.15.2",
|
|
12
|
+
"@remix-run/react": "2.15.2",
|
|
13
|
+
"@remix-run/server-runtime": "2.15.2",
|
|
14
|
+
"@webstudio-is/image": "0.0.0-021f2d4",
|
|
15
|
+
"@webstudio-is/react-sdk": "0.0.0-021f2d4",
|
|
16
|
+
"@webstudio-is/sdk": "0.0.0-021f2d4",
|
|
17
|
+
"@webstudio-is/sdk-components-react": "0.0.0-021f2d4",
|
|
18
|
+
"@webstudio-is/sdk-components-animation": "0.0.0-021f2d4",
|
|
19
|
+
"@webstudio-is/sdk-components-react-radix": "0.0.0-021f2d4",
|
|
20
|
+
"@webstudio-is/sdk-components-react-remix": "0.0.0-021f2d4",
|
|
21
|
+
"isbot": "^5.1.22",
|
|
22
|
+
"react": "18.3.0-canary-14898b6a9-20240318",
|
|
23
|
+
"react-dom": "18.3.0-canary-14898b6a9-20240318"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@remix-run/dev": "2.15.2",
|
|
27
|
+
"@types/react": "^18.2.70",
|
|
28
|
+
"@types/react-dom": "^18.2.25",
|
|
29
|
+
"typescript": "5.7.3",
|
|
30
|
+
"vite": "^5.4.11"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20.0.0"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": ["**/*.ts", "**/*.tsx", "**/*.mjs"],
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
5
|
+
"types": [
|
|
6
|
+
"@remix-run/node",
|
|
7
|
+
"vite/client",
|
|
8
|
+
"@webstudio-is/react-sdk/placeholder"
|
|
9
|
+
],
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"jsx": "react-jsx",
|
|
13
|
+
"module": "ESNext",
|
|
14
|
+
"moduleResolution": "bundler",
|
|
15
|
+
"target": "ES2022",
|
|
16
|
+
"strict": true,
|
|
17
|
+
"allowJs": true,
|
|
18
|
+
"forceConsistentCasingInFileNames": true,
|
|
19
|
+
"noEmit": true,
|
|
20
|
+
"skipLibCheck": true
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
import { vitePlugin as remix } from "@remix-run/dev";
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
plugins: [
|
|
6
|
+
remix({
|
|
7
|
+
future: {
|
|
8
|
+
v3_lazyRouteDiscovery: false,
|
|
9
|
+
v3_relativeSplatPath: false,
|
|
10
|
+
v3_singleFetch: false,
|
|
11
|
+
v3_fetcherPersist: false,
|
|
12
|
+
v3_throwAbortReason: false,
|
|
13
|
+
},
|
|
14
|
+
}),
|
|
15
|
+
],
|
|
16
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"@webstudio-is/image": "workspace:*",
|
|
4
|
+
"@webstudio-is/react-sdk": "workspace:*",
|
|
5
|
+
"@webstudio-is/sdk": "workspace:*",
|
|
6
|
+
"@webstudio-is/sdk-components-animation": "workspace:*",
|
|
7
|
+
"@webstudio-is/sdk-components-react": "workspace:*",
|
|
8
|
+
"@webstudio-is/sdk-components-react-radix": "workspace:*",
|
|
9
|
+
"@webstudio-is/sdk-components-react-remix": "workspace:*"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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 (process.env.NODE_ENV !== "production") {
|
|
12
|
+
return props.src;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (props.format === "raw") {
|
|
16
|
+
return props.src;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// https://docs.netlify.com/image-cdn/overview/
|
|
20
|
+
const searchParams = new URLSearchParams();
|
|
21
|
+
searchParams.set("url", props.src);
|
|
22
|
+
searchParams.set("w", props.width.toString());
|
|
23
|
+
if (props.height) {
|
|
24
|
+
searchParams.set("h", props.height.toString());
|
|
25
|
+
}
|
|
26
|
+
searchParams.set("q", props.quality.toString());
|
|
27
|
+
// fit=contain by default
|
|
28
|
+
return `/.netlify/images?${searchParams}`;
|
|
29
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EntryContext } from "@remix-run/node";
|
|
2
|
+
import { RemixServer } from "@remix-run/react";
|
|
3
|
+
import { renderToString } from "react-dom/server";
|
|
4
|
+
|
|
5
|
+
export default function handleRequest(
|
|
6
|
+
request: Request,
|
|
7
|
+
responseStatusCode: number,
|
|
8
|
+
responseHeaders: Headers,
|
|
9
|
+
remixContext: EntryContext
|
|
10
|
+
) {
|
|
11
|
+
const markup = renderToString(
|
|
12
|
+
<RemixServer context={remixContext} url={request.url} />
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
responseHeaders.set("Content-Type", "text/html");
|
|
16
|
+
|
|
17
|
+
return new Response("<!DOCTYPE html>" + markup, {
|
|
18
|
+
headers: responseHeaders,
|
|
19
|
+
status: responseStatusCode,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[build]
|
|
2
|
+
command = "npm run build"
|
|
3
|
+
publish = "build/client"
|
|
4
|
+
|
|
5
|
+
[dev]
|
|
6
|
+
command = "npm run dev"
|
|
7
|
+
framework = "vite"
|
|
8
|
+
|
|
9
|
+
# Set immutable caching for static files, because they have fingerprinted filenames
|
|
10
|
+
|
|
11
|
+
[[headers]]
|
|
12
|
+
for = "/build/*"
|
|
13
|
+
|
|
14
|
+
[headers.values]
|
|
15
|
+
|
|
16
|
+
"Cache-Control" = "public, max-age=31560000, immutable"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { vitePlugin as remix } from "@remix-run/dev";
|
|
2
|
+
import { defineConfig } from "vite";
|
|
3
|
+
import { netlifyPlugin } from "@netlify/remix-edge-adapter/plugin";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [
|
|
7
|
+
remix({
|
|
8
|
+
future: {
|
|
9
|
+
v3_lazyRouteDiscovery: false,
|
|
10
|
+
v3_relativeSplatPath: false,
|
|
11
|
+
v3_singleFetch: false,
|
|
12
|
+
v3_fetcherPersist: false,
|
|
13
|
+
v3_throwAbortReason: false,
|
|
14
|
+
},
|
|
15
|
+
}),
|
|
16
|
+
netlifyPlugin(),
|
|
17
|
+
],
|
|
18
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
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 (process.env.NODE_ENV !== "production") {
|
|
12
|
+
return props.src;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (props.format === "raw") {
|
|
16
|
+
return props.src;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// https://docs.netlify.com/image-cdn/overview/
|
|
20
|
+
const searchParams = new URLSearchParams();
|
|
21
|
+
searchParams.set("url", props.src);
|
|
22
|
+
searchParams.set("w", props.width.toString());
|
|
23
|
+
if (props.height) {
|
|
24
|
+
searchParams.set("h", props.height.toString());
|
|
25
|
+
}
|
|
26
|
+
searchParams.set("q", props.quality.toString());
|
|
27
|
+
// fit=contain by default
|
|
28
|
+
return `/.netlify/images?${searchParams}`;
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { handleRequest as default } from "@netlify/remix-adapter";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[build]
|
|
2
|
+
command = "npm run build"
|
|
3
|
+
publish = "build/client"
|
|
4
|
+
|
|
5
|
+
[dev]
|
|
6
|
+
command = "npm run dev"
|
|
7
|
+
framework = "vite"
|
|
8
|
+
|
|
9
|
+
# Set immutable caching for static files, because they have fingerprinted filenames
|
|
10
|
+
|
|
11
|
+
[[headers]]
|
|
12
|
+
for = "/build/*"
|
|
13
|
+
|
|
14
|
+
[headers.values]
|
|
15
|
+
|
|
16
|
+
"Cache-Control" = "public, max-age=31560000, immutable"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { vitePlugin as remix } from "@remix-run/dev";
|
|
2
|
+
import { defineConfig } from "vite";
|
|
3
|
+
import { netlifyPlugin } from "@netlify/remix-adapter/plugin";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [
|
|
7
|
+
remix({
|
|
8
|
+
future: {
|
|
9
|
+
v3_lazyRouteDiscovery: false,
|
|
10
|
+
v3_relativeSplatPath: false,
|
|
11
|
+
v3_singleFetch: false,
|
|
12
|
+
v3_fetcherPersist: false,
|
|
13
|
+
v3_throwAbortReason: false,
|
|
14
|
+
},
|
|
15
|
+
}),
|
|
16
|
+
netlifyPlugin(),
|
|
17
|
+
],
|
|
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
|
+
};
|