Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

build: Cli support for meta tags (#2537)

Ivan Starkov50373db9c127
diff --git a/apps/builder/app/builder/features/seo/site-settings.tsx b/apps/builder/app/builder/features/seo/site-settings.tsx
index 8cfab74fd9..88c00aeb95 100644
--- a/apps/builder/app/builder/features/seo/site-settings.tsx
+++ b/apps/builder/app/builder/features/seo/site-settings.tsx
@@ -24,7 +24,7 @@ import { serverSyncStore } from "~/shared/sync";
import { useEffectEvent } from "../ai/hooks/effect-event";
import type { Pages } from "@webstudio-is/sdk";
-type Value = Pages["meta"];
+type Value = NonNullable<Pages["meta"]>;
type Props = {
value: Value;
diff --git a/apps/builder/app/builder/features/sidebar-left/panels/pages/settings.tsx b/apps/builder/app/builder/features/sidebar-left/panels/pages/settings.tsx
index 88ef7560d2..1c080f7aa8 100644
--- a/apps/builder/app/builder/features/sidebar-left/panels/pages/settings.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/panels/pages/settings.tsx
@@ -223,7 +223,7 @@ const FormFields = ({
const assets = useStore(assetsStore);
const pages = useStore(pagesStore);
const socialImageAsset = assets.get(values.socialImageAssetId);
- const faviconAsset = assets.get(pages?.meta.faviconAssetId ?? "");
+ const faviconAsset = assets.get(pages?.meta?.faviconAssetId ?? "");
const faviconUrl = faviconAsset?.type === "image" ? faviconAsset.name : "";
@@ -359,7 +359,7 @@ const FormFields = ({
}}
>
<SearchPreview
- siteName={pages?.meta.siteName ?? ""}
+ siteName={pages?.meta?.siteName ?? ""}
faviconUrl={faviconUrl}
pageUrl={pageUrl}
titleLink={values.title}
diff --git a/apps/builder/app/builder/shared/assets/asset-upload.tsx b/apps/builder/app/builder/shared/assets/asset-upload.tsx
index 91d5a32f14..19ecf207d7 100644
--- a/apps/builder/app/builder/shared/assets/asset-upload.tsx
+++ b/apps/builder/app/builder/shared/assets/asset-upload.tsx
@@ -52,6 +52,8 @@ const imageMimeTypes = [
"image/gif",
"image/webp",
"image/svg+xml",
+ "image/x-icon",
+ "image/ico",
];
const acceptMap = {
diff --git a/apps/builder/app/routes/asset.image.$name.ts b/apps/builder/app/routes/asset.image.$name.ts
index 1916e5db85..cc53432506 100644
--- a/apps/builder/app/routes/asset.image.$name.ts
+++ b/apps/builder/app/routes/asset.image.$name.ts
@@ -21,8 +21,6 @@ export const loader = async ({ params, request }: LoaderArgs) => {
throw Error("Options are invalid");
}
- const options = `width=${width},quality=${quality},format=${format}`;
-
// Allow direct image access, and from the same origin
const refererRawUrl = request.headers.get("referer");
const refererUrl = refererRawUrl === null ? url : new URL(refererRawUrl);
@@ -33,9 +31,10 @@ export const loader = async ({ params, request }: LoaderArgs) => {
}
if (env.RESIZE_ORIGIN !== undefined) {
- const assetUrl = `${env.ASSET_BASE_URL}${name}`;
+ const assetUrl = `${name}`;
// @todo add secret ti avoid exploiting our server
- const imageUrl = `${env.RESIZE_ORIGIN}/cdn-cgi/image/${options}/${assetUrl}`;
+ const imageUrl = `${env.RESIZE_ORIGIN}/cgi/image/${assetUrl}?${url.searchParams}`;
+
const response = await fetch(imageUrl, {
headers: {
accept: request.headers.get("accept") ?? "",
diff --git a/fixtures/webstudio-custom-template/.webstudio/data.json b/fixtures/webstudio-custom-template/.webstudio/data.json
index 15f50a52c9..400415d861 100644
--- a/fixtures/webstudio-custom-template/.webstudio/data.json
+++ b/fixtures/webstudio-custom-template/.webstudio/data.json
@@ -1,14 +1,19 @@
{
"build": {
- "id": "de63ff61-f4b6-437e-bbc6-b2d085cd35bd",
+ "id": "bed606f3-fc20-408b-9e27-afa65f293390",
"projectId": "0d856812-61d8-4014-a20a-82e01c0eb8ee",
- "version": 5,
- "createdAt": "2023-09-21T09:44:06.958Z",
+ "version": 13,
+ "createdAt": "2023-10-30T20:36:31.649Z",
"pages": {
+ "meta": {
+ "siteName": "Fixture Site",
+ "faviconAssetId": "cd1e9fad-8df1-45c6-800f-05fda2d2469f",
+ "code": ""
+ },
"homePage": {
"id": "nfzls_SkTc9jKYyxcZ8Lw",
"name": "Home",
- "title": "Home",
+ "title": "Site Title",
"meta": {
"description": "Page description f511c297-b44f-4e4b-96bd-d013da06bada"
},
@@ -123,7 +128,7 @@
"page": {
"id": "nfzls_SkTc9jKYyxcZ8Lw",
"name": "Home",
- "title": "Home",
+ "title": "Site Title",
"meta": {
"description": "Page description f511c297-b44f-4e4b-96bd-d013da06bada"
},
@@ -134,7 +139,7 @@
{
"id": "nfzls_SkTc9jKYyxcZ8Lw",
"name": "Home",
- "title": "Home",
+ "title": "Site Title",
"meta": {
"description": "Page description f511c297-b44f-4e4b-96bd-d013da06bada"
},
@@ -142,7 +147,22 @@
"path": ""
}
],
- "assets": [],
+ "assets": [
+ {
+ "id": "cd1e9fad-8df1-45c6-800f-05fda2d2469f",
+ "name": "home_wsKvRSqvkajPPBeycZ-C8.svg",
+ "description": null,
+ "projectId": "0d856812-61d8-4014-a20a-82e01c0eb8ee",
+ "size": 3350,
+ "type": "image",
+ "format": "svg",
+ "createdAt": "2023-10-30T20:35:47.113Z",
+ "meta": {
+ "width": 16,
+ "height": 16
+ }
+ }
+ ],
"user": {
"email": "[email protected]"
},
diff --git a/fixtures/webstudio-custom-template/README.md b/fixtures/webstudio-custom-template/README.md
index 5d52f15d69..a6592e1103 100644
--- a/fixtures/webstudio-custom-template/README.md
+++ b/fixtures/webstudio-custom-template/README.md
@@ -11,7 +11,7 @@ pnpm dev
```bash
# Terminal 2
pnpm webstudio link
-# add following link https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/0d856812-61d8-4014-a20a-82e01c0eb8ee?authToken=d225fafb-4f20-4340-9359-c21df7c49a3f&mode=preview
+# add following link https://webstudio-builder-git-main-getwebstudio.vercel.app/builder/0d856812-61d8-4014-a20a-82e01c0eb8ee?authToken=d225fafb-4f20-4340-9359-c21df7c49a3f&mode=preview
pnpm webstudio sync && pnpm prettier --write ./.webstudio/
# data.json generated
diff --git a/fixtures/webstudio-custom-template/app/__generated__/_index.tsx b/fixtures/webstudio-custom-template/app/__generated__/_index.tsx
index edc30d03ea..2ca0e08bbe 100644
--- a/fixtures/webstudio-custom-template/app/__generated__/_index.tsx
+++ b/fixtures/webstudio-custom-template/app/__generated__/_index.tsx
@@ -3,18 +3,36 @@
import { type ReactNode, useState } from "react";
import type { PageData } from "~/routes/_index";
-import type { Asset } from "@webstudio-is/sdk";
+import type { Asset, ImageAsset, SiteMeta } from "@webstudio-is/sdk";
import {
Body as Body,
Heading as Heading,
} from "@webstudio-is/sdk-components-react";
export const fontAssets: Asset[] = [];
+export const imageAssets: ImageAsset[] = [
+ {
+ id: "cd1e9fad-8df1-45c6-800f-05fda2d2469f",
+ name: "home_wsKvRSqvkajPPBeycZ-C8.svg",
+ description: null,
+ projectId: "0d856812-61d8-4014-a20a-82e01c0eb8ee",
+ size: 3350,
+ type: "image",
+ format: "svg",
+ createdAt: "2023-10-30T20:35:47.113Z",
+ meta: { width: 16, height: 16 },
+ },
+];
export const pageData: PageData = {
+ site: {
+ siteName: "Fixture Site",
+ faviconAssetId: "cd1e9fad-8df1-45c6-800f-05fda2d2469f",
+ code: "",
+ },
page: {
id: "nfzls_SkTc9jKYyxcZ8Lw",
name: "Home",
- title: "Home",
+ title: "Site Title",
meta: {
description: "Page description f511c297-b44f-4e4b-96bd-d013da06bada",
},
diff --git a/fixtures/webstudio-custom-template/app/routes/_index.tsx b/fixtures/webstudio-custom-template/app/routes/_index.tsx
index 29e9cc7e27..d67253fa9f 100644
--- a/fixtures/webstudio-custom-template/app/routes/_index.tsx
+++ b/fixtures/webstudio-custom-template/app/routes/_index.tsx
@@ -4,9 +4,10 @@ import {
type LinksFunction,
type LinkDescriptor,
type ActionArgs,
+ type LoaderArgs,
json,
} from "@remix-run/server-runtime";
-import type { Page as PageType } from "@webstudio-is/sdk";
+import type { Page as PageType, SiteMeta } from "@webstudio-is/sdk";
import { ReactSdkContext } from "@webstudio-is/react-sdk";
import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";
import { Scripts, ScrollRestoration } from "@remix-run/react";
@@ -18,34 +19,108 @@ import {
pagesPaths,
formsProperties,
Page,
+ imageAssets,
} from "../__generated__/_index.tsx";
import css from "../__generated__/index.css";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "~/constants.mjs";
export type PageData = {
+ site?: SiteMeta;
page: PageType;
};
-export const meta: V2_ServerRuntimeMetaFunction = () => {
- const { page } = pageData;
- const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [
- { title: page?.title || "Webstudio" },
- ];
- for (const [name, value] of Object.entries(page?.meta ?? {})) {
- if (name.startsWith("og:")) {
- metas.push({
- property: name,
- content: value,
- });
- continue;
- }
+export const loader = async (arg: LoaderArgs) => {
+ const host =
+ arg.request.headers.get("x-forwarded-host") ||
+ arg.request.headers.get("host") ||
+ "";
+
+ const url = new URL(arg.request.url);
+ url.host = host;
+ url.protocol = "https";
+
+ return json(
+ { host, url: url.href },
+ // No way for current information to change, so add cache for 10 minutes
+ // In case of CRM Data, this should be set to 0
+ { headers: { "Cache-Control": "public, max-age=600" } }
+ );
+};
+
+export const headers = () => {
+ return {
+ "Cache-Control": "public, max-age=0, must-revalidate",
+ };
+};
+
+export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {
+ const { page, site } = pageData;
+
+ const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [];
+
+ if (data?.url) {
+ metas.push({
+ property: "og:url",
+ content: data.url,
+ });
+ }
+
+ if (page.title) {
+ metas.push({ title: page.title });
+
+ metas.push({
+ property: "og:title",
+ content: page.title,
+ });
+ }
+
+ metas.push({ property: "og:type", content: "website" });
+
+ const origin = `https://${data?.host}`;
+
+ if (site?.siteName) {
+ metas.push({
+ property: "og:site_name",
+ content: site.siteName,
+ });
+ metas.push({
+ "script:ld+json": {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: site.siteName,
+ url: origin,
+ },
+ });
+ }
+ if (page.meta.description) {
+ metas.push({
+ name: "description",
+ content: page.meta.description,
+ });
metas.push({
- name,
- content: value,
+ property: "og:description",
+ content: page.meta.description,
});
}
+ if (page.meta.socialImageAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === page.meta.socialImageAssetId
+ );
+
+ if (imageAsset) {
+ metas.push({
+ property: "og:image",
+ content: `https://${data?.host}${imageLoader({
+ src: imageAsset.name,
+ // Do not transform social image (not enough information do we need to do this)
+ format: "raw",
+ })}`,
+ });
+ }
+ }
+
return metas;
};
@@ -57,6 +132,39 @@ export const links: LinksFunction = () => {
href: css,
});
+ const { site } = pageData;
+
+ if (site?.faviconAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === site.faviconAssetId
+ );
+
+ if (imageAsset) {
+ result.push({
+ rel: "icon",
+ href: imageLoader({
+ src: imageAsset.name,
+ width: 128,
+ quality: 100,
+ format: "auto",
+ }),
+ type: undefined,
+ });
+ }
+ } else {
+ result.push({
+ rel: "icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+
+ result.push({
+ rel: "shortcut icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+ }
+
for (const asset of fontAssets) {
if (asset.type === "font") {
result.push({
diff --git a/fixtures/webstudio-custom-template/package.json b/fixtures/webstudio-custom-template/package.json
index 2c42b92ebb..4627d17162 100644
--- a/fixtures/webstudio-custom-template/package.json
+++ b/fixtures/webstudio-custom-template/package.json
@@ -7,7 +7,7 @@
"start": "remix-serve build",
"checks": "pnpm typecheck",
"size-test": "rm -rf ./public && remix build && size-limit",
- "fixtures:link": "webstudio link --link 'https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/0d856812-61d8-4014-a20a-82e01c0eb8ee?authToken=d225fafb-4f20-4340-9359-c21df7c49a3f'",
+ "fixtures:link": "webstudio link --link 'https://webstudio-builder-git-main-getwebstudio.vercel.app/builder/0d856812-61d8-4014-a20a-82e01c0eb8ee?authToken=d225fafb-4f20-4340-9359-c21df7c49a3f'",
"fixtures:sync": "webstudio sync && pnpm prettier --write ./.webstudio/",
"fixtures:build": "webstudio build --template ./custom-template --preview && pnpm prettier --write ./app/ ./package.json"
},
diff --git a/fixtures/webstudio-custom-template/public/custom-folder/home_wsKvRSqvkajPPBeycZ-C8.svg b/fixtures/webstudio-custom-template/public/custom-folder/home_wsKvRSqvkajPPBeycZ-C8.svg
new file mode 100644
index 0000000000..67284862e7
--- /dev/null
+++ b/fixtures/webstudio-custom-template/public/custom-folder/home_wsKvRSqvkajPPBeycZ-C8.svg
@@ -0,0 +1,3 @@
+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M7.6559 0.907089C7.88124 0.846075 8.11876 0.846075 8.34411 0.907089C8.60553 0.97787 8.82581 1.15075 9.00433 1.29086C9.02124 1.30414 9.03777 1.31712 9.05393 1.32968L13.5755 4.84644C13.5927 4.85983 13.6098 4.87308 13.6267 4.88623C13.8784 5.08159 14.0978 5.25187 14.2612 5.47281C14.4047 5.66677 14.5116 5.88528 14.5766 6.11759C14.6507 6.38223 14.6504 6.65995 14.65 6.9786C14.65 7.00004 14.65 7.02165 14.65 7.04347V11.8919C14.65 12.2438 14.65 12.5464 14.6297 12.7954C14.6082 13.0579 14.561 13.3177 14.4338 13.5672C14.2437 13.9404 13.9403 14.2438 13.5671 14.4339C13.3176 14.561 13.0579 14.6083 12.7953 14.6298C12.5463 14.6501 12.2437 14.6501 11.8918 14.6501H4.10816C3.75628 14.6501 3.4537 14.6501 3.20467 14.6298C2.94214 14.6083 2.68243 14.561 2.43292 14.4339C2.05973 14.2438 1.75632 13.9404 1.56617 13.5672C1.43904 13.3177 1.39178 13.0579 1.37033 12.7954C1.34998 12.5464 1.34999 12.2438 1.35 11.8919L1.35 7.04347C1.35 7.02165 1.34998 7.00003 1.34996 6.9786C1.34963 6.65995 1.34934 6.38222 1.42341 6.11759C1.48844 5.88527 1.59531 5.66677 1.73876 5.47281C1.90218 5.25187 2.12158 5.08159 2.3733 4.88623C2.39024 4.87308 2.40732 4.85983 2.42453 4.84644L6.94607 1.32968C6.96223 1.31711 6.97877 1.30414 6.99568 1.29086C7.1742 1.15075 7.39448 0.97787 7.6559 0.907089ZM6.65 13.3501H9.35V9.06675C9.35 8.86934 9.3495 8.76038 9.34308 8.68182C9.34236 8.67303 9.34162 8.66552 9.34091 8.65918C9.33457 8.65847 9.32706 8.65773 9.31827 8.65701C9.23971 8.65059 9.13075 8.65009 8.93334 8.65009H7.06667C6.86926 8.65009 6.76029 8.65059 6.68174 8.65701C6.67294 8.65773 6.66544 8.65847 6.6591 8.65918C6.65839 8.66552 6.65765 8.67303 6.65693 8.68182C6.65051 8.76038 6.65 8.86934 6.65 9.06675V13.3501ZM10.65 13.3501L10.65 9.04584C10.65 8.87727 10.65 8.71403 10.6388 8.57596C10.6264 8.42459 10.5973 8.24721 10.5065 8.069C10.3803 7.82125 10.1788 7.61983 9.93109 7.49359C9.75288 7.40279 9.5755 7.37369 9.42413 7.36133C9.28606 7.35005 9.12282 7.35007 8.95425 7.35008H7.04575C6.87718 7.35007 6.71395 7.35005 6.57587 7.36133C6.42451 7.37369 6.24712 7.40279 6.06892 7.49359C5.82117 7.61983 5.61974 7.82125 5.49351 8.069C5.40271 8.24721 5.37361 8.42459 5.36124 8.57596C5.34996 8.71403 5.34998 8.87727 5.35 9.04584L5.35 13.3501H4.13334C3.74924 13.3501 3.50026 13.3496 3.31054 13.3341C3.1284 13.3192 3.05881 13.2938 3.02311 13.2756C2.89453 13.2101 2.79 13.1056 2.72448 12.977C2.70629 12.9413 2.68089 12.8717 2.66601 12.6896C2.65051 12.4998 2.65 12.2508 2.65 11.8668V7.04347C2.65 6.62375 2.65565 6.53819 2.6753 6.46801C2.6977 6.38796 2.73452 6.31268 2.78395 6.24586C2.82729 6.18726 2.89135 6.13027 3.22266 5.87259L7.74419 2.35584C7.86861 2.25907 7.93516 2.20781 7.98588 2.17392C7.99132 2.17029 7.99601 2.16725 8 2.16473C8.00399 2.16725 8.00869 2.17029 8.01413 2.17392C8.06485 2.20781 8.13139 2.25907 8.25581 2.35584L12.7773 5.87259C13.1087 6.13027 13.1727 6.18726 13.2161 6.24586C13.2655 6.31268 13.3023 6.38796 13.3247 6.46801C13.3444 6.53819 13.35 6.62375 13.35 7.04347V11.8668C13.35 12.2508 13.3495 12.4998 13.334 12.6896C13.3191 12.8717 13.2937 12.9413 13.2755 12.977C13.21 13.1056 13.1055 13.2101 12.9769 13.2756C12.9412 13.2938 12.8716 13.3192 12.6895 13.3341C12.4997 13.3496 12.2508 13.3501 11.8667 13.3501H10.65Z" fill="#11181C"/>
+</svg>
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/README.md b/fixtures/webstudio-remix-netlify-edge-functions/README.md
index 98f5ea7fc4..bc42de8587 100644
--- a/fixtures/webstudio-remix-netlify-edge-functions/README.md
+++ b/fixtures/webstudio-remix-netlify-edge-functions/README.md
@@ -11,7 +11,7 @@ pnpm dev
```bash
# Terminal 2
pnpm webstudio link
-# add following link https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93
+# add following link https://webstudio-builder-git-main-getwebstudio.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93
pnpm webstudio sync && pnpm prettier --write ./.webstudio/
# data.json generated
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx
index 35585adaa7..932d9058b7 100644
--- a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx
+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx
@@ -3,7 +3,7 @@
import { type ReactNode, useState } from "react";
import type { PageData } from "~/routes/_index";
-import type { Asset } from "@webstudio-is/sdk";
+import type { Asset, ImageAsset, SiteMeta } from "@webstudio-is/sdk";
import {
Body as Body,
Heading as Heading,
@@ -11,6 +11,7 @@ import {
} from "@webstudio-is/sdk-components-react";
export const fontAssets: Asset[] = [];
+export const imageAssets: ImageAsset[] = [];
export const pageData: PageData = {
page: {
id: "9di_L14CzctvSruIoKVvE",
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx
index 29e9cc7e27..d67253fa9f 100644
--- a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx
+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx
@@ -4,9 +4,10 @@ import {
type LinksFunction,
type LinkDescriptor,
type ActionArgs,
+ type LoaderArgs,
json,
} from "@remix-run/server-runtime";
-import type { Page as PageType } from "@webstudio-is/sdk";
+import type { Page as PageType, SiteMeta } from "@webstudio-is/sdk";
import { ReactSdkContext } from "@webstudio-is/react-sdk";
import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";
import { Scripts, ScrollRestoration } from "@remix-run/react";
@@ -18,34 +19,108 @@ import {
pagesPaths,
formsProperties,
Page,
+ imageAssets,
} from "../__generated__/_index.tsx";
import css from "../__generated__/index.css";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "~/constants.mjs";
export type PageData = {
+ site?: SiteMeta;
page: PageType;
};
-export const meta: V2_ServerRuntimeMetaFunction = () => {
- const { page } = pageData;
- const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [
- { title: page?.title || "Webstudio" },
- ];
- for (const [name, value] of Object.entries(page?.meta ?? {})) {
- if (name.startsWith("og:")) {
- metas.push({
- property: name,
- content: value,
- });
- continue;
- }
+export const loader = async (arg: LoaderArgs) => {
+ const host =
+ arg.request.headers.get("x-forwarded-host") ||
+ arg.request.headers.get("host") ||
+ "";
+
+ const url = new URL(arg.request.url);
+ url.host = host;
+ url.protocol = "https";
+
+ return json(
+ { host, url: url.href },
+ // No way for current information to change, so add cache for 10 minutes
+ // In case of CRM Data, this should be set to 0
+ { headers: { "Cache-Control": "public, max-age=600" } }
+ );
+};
+
+export const headers = () => {
+ return {
+ "Cache-Control": "public, max-age=0, must-revalidate",
+ };
+};
+
+export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {
+ const { page, site } = pageData;
+
+ const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [];
+
+ if (data?.url) {
+ metas.push({
+ property: "og:url",
+ content: data.url,
+ });
+ }
+
+ if (page.title) {
+ metas.push({ title: page.title });
+
+ metas.push({
+ property: "og:title",
+ content: page.title,
+ });
+ }
+
+ metas.push({ property: "og:type", content: "website" });
+
+ const origin = `https://${data?.host}`;
+
+ if (site?.siteName) {
+ metas.push({
+ property: "og:site_name",
+ content: site.siteName,
+ });
+ metas.push({
+ "script:ld+json": {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: site.siteName,
+ url: origin,
+ },
+ });
+ }
+ if (page.meta.description) {
+ metas.push({
+ name: "description",
+ content: page.meta.description,
+ });
metas.push({
- name,
- content: value,
+ property: "og:description",
+ content: page.meta.description,
});
}
+ if (page.meta.socialImageAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === page.meta.socialImageAssetId
+ );
+
+ if (imageAsset) {
+ metas.push({
+ property: "og:image",
+ content: `https://${data?.host}${imageLoader({
+ src: imageAsset.name,
+ // Do not transform social image (not enough information do we need to do this)
+ format: "raw",
+ })}`,
+ });
+ }
+ }
+
return metas;
};
@@ -57,6 +132,39 @@ export const links: LinksFunction = () => {
href: css,
});
+ const { site } = pageData;
+
+ if (site?.faviconAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === site.faviconAssetId
+ );
+
+ if (imageAsset) {
+ result.push({
+ rel: "icon",
+ href: imageLoader({
+ src: imageAsset.name,
+ width: 128,
+ quality: 100,
+ format: "auto",
+ }),
+ type: undefined,
+ });
+ }
+ } else {
+ result.push({
+ rel: "icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+
+ result.push({
+ rel: "shortcut icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+ }
+
for (const asset of fontAssets) {
if (asset.type === "font") {
result.push({
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/package.json b/fixtures/webstudio-remix-netlify-edge-functions/package.json
index 6a0d72d265..ed2ee32a11 100644
--- a/fixtures/webstudio-remix-netlify-edge-functions/package.json
+++ b/fixtures/webstudio-remix-netlify-edge-functions/package.json
@@ -5,7 +5,7 @@
"build": "remix build",
"dev": "remix dev",
"typecheck": "tsc",
- "fixtures:link": "webstudio link --link 'https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93&'",
+ "fixtures:link": "webstudio link --link 'https://webstudio-builder-git-main-getwebstudio.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93&'",
"fixtures:sync": "webstudio sync && pnpm prettier --write ./.webstudio/",
"fixtures:build": "webstudio build --template netlify-edge-functions --preview && pnpm prettier --write ./app/ ./package.json"
},
diff --git a/fixtures/webstudio-remix-netlify-functions/README.md b/fixtures/webstudio-remix-netlify-functions/README.md
index 98f5ea7fc4..bc42de8587 100644
--- a/fixtures/webstudio-remix-netlify-functions/README.md
+++ b/fixtures/webstudio-remix-netlify-functions/README.md
@@ -11,7 +11,7 @@ pnpm dev
```bash
# Terminal 2
pnpm webstudio link
-# add following link https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93
+# add following link https://webstudio-builder-git-main-getwebstudio.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93
pnpm webstudio sync && pnpm prettier --write ./.webstudio/
# data.json generated
diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx b/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx
index 35585adaa7..932d9058b7 100644
--- a/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx
+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx
@@ -3,7 +3,7 @@
import { type ReactNode, useState } from "react";
import type { PageData } from "~/routes/_index";
-import type { Asset } from "@webstudio-is/sdk";
+import type { Asset, ImageAsset, SiteMeta } from "@webstudio-is/sdk";
import {
Body as Body,
Heading as Heading,
@@ -11,6 +11,7 @@ import {
} from "@webstudio-is/sdk-components-react";
export const fontAssets: Asset[] = [];
+export const imageAssets: ImageAsset[] = [];
export const pageData: PageData = {
page: {
id: "9di_L14CzctvSruIoKVvE",
diff --git a/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx b/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx
index 29e9cc7e27..d67253fa9f 100644
--- a/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx
+++ b/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx
@@ -4,9 +4,10 @@ import {
type LinksFunction,
type LinkDescriptor,
type ActionArgs,
+ type LoaderArgs,
json,
} from "@remix-run/server-runtime";
-import type { Page as PageType } from "@webstudio-is/sdk";
+import type { Page as PageType, SiteMeta } from "@webstudio-is/sdk";
import { ReactSdkContext } from "@webstudio-is/react-sdk";
import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";
import { Scripts, ScrollRestoration } from "@remix-run/react";
@@ -18,34 +19,108 @@ import {
pagesPaths,
formsProperties,
Page,
+ imageAssets,
} from "../__generated__/_index.tsx";
import css from "../__generated__/index.css";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "~/constants.mjs";
export type PageData = {
+ site?: SiteMeta;
page: PageType;
};
-export const meta: V2_ServerRuntimeMetaFunction = () => {
- const { page } = pageData;
- const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [
- { title: page?.title || "Webstudio" },
- ];
- for (const [name, value] of Object.entries(page?.meta ?? {})) {
- if (name.startsWith("og:")) {
- metas.push({
- property: name,
- content: value,
- });
- continue;
- }
+export const loader = async (arg: LoaderArgs) => {
+ const host =
+ arg.request.headers.get("x-forwarded-host") ||
+ arg.request.headers.get("host") ||
+ "";
+
+ const url = new URL(arg.request.url);
+ url.host = host;
+ url.protocol = "https";
+
+ return json(
+ { host, url: url.href },
+ // No way for current information to change, so add cache for 10 minutes
+ // In case of CRM Data, this should be set to 0
+ { headers: { "Cache-Control": "public, max-age=600" } }
+ );
+};
+
+export const headers = () => {
+ return {
+ "Cache-Control": "public, max-age=0, must-revalidate",
+ };
+};
+
+export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {
+ const { page, site } = pageData;
+
+ const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [];
+
+ if (data?.url) {
+ metas.push({
+ property: "og:url",
+ content: data.url,
+ });
+ }
+
+ if (page.title) {
+ metas.push({ title: page.title });
+
+ metas.push({
+ property: "og:title",
+ content: page.title,
+ });
+ }
+
+ metas.push({ property: "og:type", content: "website" });
+
+ const origin = `https://${data?.host}`;
+
+ if (site?.siteName) {
+ metas.push({
+ property: "og:site_name",
+ content: site.siteName,
+ });
+ metas.push({
+ "script:ld+json": {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: site.siteName,
+ url: origin,
+ },
+ });
+ }
+ if (page.meta.description) {
+ metas.push({
+ name: "description",
+ content: page.meta.description,
+ });
metas.push({
- name,
- content: value,
+ property: "og:description",
+ content: page.meta.description,
});
}
+ if (page.meta.socialImageAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === page.meta.socialImageAssetId
+ );
+
+ if (imageAsset) {
+ metas.push({
+ property: "og:image",
+ content: `https://${data?.host}${imageLoader({
+ src: imageAsset.name,
+ // Do not transform social image (not enough information do we need to do this)
+ format: "raw",
+ })}`,
+ });
+ }
+ }
+
return metas;
};
@@ -57,6 +132,39 @@ export const links: LinksFunction = () => {
href: css,
});
+ const { site } = pageData;
+
+ if (site?.faviconAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === site.faviconAssetId
+ );
+
+ if (imageAsset) {
+ result.push({
+ rel: "icon",
+ href: imageLoader({
+ src: imageAsset.name,
+ width: 128,
+ quality: 100,
+ format: "auto",
+ }),
+ type: undefined,
+ });
+ }
+ } else {
+ result.push({
+ rel: "icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+
+ result.push({
+ rel: "shortcut icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+ }
+
for (const asset of fontAssets) {
if (asset.type === "font") {
result.push({
diff --git a/fixtures/webstudio-remix-netlify-functions/package.json b/fixtures/webstudio-remix-netlify-functions/package.json
index b1775ce558..b14f6a1be1 100644
--- a/fixtures/webstudio-remix-netlify-functions/package.json
+++ b/fixtures/webstudio-remix-netlify-functions/package.json
@@ -5,7 +5,7 @@
"build": "remix build",
"dev": "remix dev",
"typecheck": "tsc",
- "fixtures:link": "webstudio link --link 'https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93'",
+ "fixtures:link": "webstudio link --link 'https://webstudio-builder-git-main-getwebstudio.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93'",
"fixtures:sync": "webstudio sync && pnpm prettier --write ./.webstudio/",
"fixtures:build": "webstudio build --template netlify-functions --preview && pnpm prettier --write ./app/ ./package.json"
},
diff --git a/fixtures/webstudio-remix-vercel/.webstudio/data.json b/fixtures/webstudio-remix-vercel/.webstudio/data.json
index 8675f9efbc..56d6d17add 100644
--- a/fixtures/webstudio-remix-vercel/.webstudio/data.json
+++ b/fixtures/webstudio-remix-vercel/.webstudio/data.json
@@ -1,25 +1,35 @@
{
"build": {
- "id": "edd62b7a-c819-42ea-920a-ded682f70ac2",
+ "id": "9ec8b651-0491-4237-9516-88c0bded9af8",
"projectId": "cddc1d44-af37-4cb6-a430-d300cf6f932d",
- "version": 177,
- "createdAt": "2023-09-22T17:58:05.654Z",
+ "version": 214,
+ "createdAt": "2023-10-30T20:58:37.229Z",
"pages": {
+ "meta": {
+ "siteName": "KittyGuardedZone",
+ "faviconAssetId": "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ "code": ""
+ },
"homePage": {
"id": "7Db64ZXgYiRqKSQNR-qTQ",
"name": "Home",
- "title": "Home",
- "meta": {},
+ "title": "The Ultimate Cat Protection Zone",
+ "meta": {
+ "description": "Dive into the world of felines and discover why some whiskers are best left untouched. From intriguing cat behaviors to protective measures, \nKittyGuardedZone is your go-to hub for all things 'hands-off' in the cat realm.",
+ "socialImageAssetId": "cd939c56-bcdd-4e64-bd9c-567a9bccd3da"
+ },
"rootInstanceId": "On9cvWCxr5rdZtY9O1Bv0",
"path": ""
},
"pages": [
{
"id": "xfvB4UThQXmQ_OubPYrkg",
- "name": "radix",
- "title": "radix",
+ "name": "radix excluded from the search",
+ "title": "Radix Revelations: Unraveling the Feline Mystique",
"meta": {
- "description": ""
+ "description": "Delve deep into the radix roots of feline behaviors. At KittyNoTouchy, we dissect the core essence, or 'radix', of what makes cats the enigmatic creatures they are. Join us as we explore the radix of their instincts, habits, and quirks.",
+ "excludePageFromSearch": true,
+ "socialImageAssetId": "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10"
},
"rootInstanceId": "uKWGyE9JY3cPwY-xI9vk6",
"path": "/radix"
@@ -3130,8 +3140,11 @@
"page": {
"id": "7Db64ZXgYiRqKSQNR-qTQ",
"name": "Home",
- "title": "Home",
- "meta": {},
+ "title": "The Ultimate Cat Protection Zone",
+ "meta": {
+ "description": "Dive into the world of felines and discover why some whiskers are best left untouched. From intriguing cat behaviors to protective measures, \nKittyGuardedZone is your go-to hub for all things 'hands-off' in the cat realm.",
+ "socialImageAssetId": "cd939c56-bcdd-4e64-bd9c-567a9bccd3da"
+ },
"rootInstanceId": "On9cvWCxr5rdZtY9O1Bv0",
"path": ""
},
@@ -3139,17 +3152,22 @@
{
"id": "7Db64ZXgYiRqKSQNR-qTQ",
"name": "Home",
- "title": "Home",
- "meta": {},
+ "title": "The Ultimate Cat Protection Zone",
+ "meta": {
+ "description": "Dive into the world of felines and discover why some whiskers are best left untouched. From intriguing cat behaviors to protective measures, \nKittyGuardedZone is your go-to hub for all things 'hands-off' in the cat realm.",
+ "socialImageAssetId": "cd939c56-bcdd-4e64-bd9c-567a9bccd3da"
+ },
"rootInstanceId": "On9cvWCxr5rdZtY9O1Bv0",
"path": ""
},
{
"id": "xfvB4UThQXmQ_OubPYrkg",
- "name": "radix",
- "title": "radix",
+ "name": "radix excluded from the search",
+ "title": "Radix Revelations: Unraveling the Feline Mystique",
"meta": {
- "description": ""
+ "description": "Delve deep into the radix roots of feline behaviors. At KittyNoTouchy, we dissect the core essence, or 'radix', of what makes cats the enigmatic creatures they are. Join us as we explore the radix of their instincts, habits, and quirks.",
+ "excludePageFromSearch": true,
+ "socialImageAssetId": "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10"
},
"rootInstanceId": "uKWGyE9JY3cPwY-xI9vk6",
"path": "/radix"
@@ -3186,6 +3204,20 @@
}
],
"assets": [
+ {
+ "id": "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ "name": "DALL_E_2023-10-30_12.39.46_-_Photo_logo_with_a_bold_cat_silhouette_centered_on_a_contrasting_background_designed_for_clarity_at_small_32x32_favicon_resolution_00h6cEA8u2pJRvVJv7hRe.png",
+ "description": null,
+ "projectId": "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ "size": 268326,
+ "type": "image",
+ "format": "png",
+ "createdAt": "2023-10-30T13:51:08.416Z",
+ "meta": {
+ "width": 790,
+ "height": 786
+ }
+ },
{
"id": "9a8bc926-7804-4d3f-af81-69196b1d2ed8",
"name": "small-avif-kitty_FnabJsioMWpBtXZSGf4DR.webp",
diff --git a/fixtures/webstudio-remix-vercel/README.md b/fixtures/webstudio-remix-vercel/README.md
index 04901a8d32..513dc1e40a 100644
--- a/fixtures/webstudio-remix-vercel/README.md
+++ b/fixtures/webstudio-remix-vercel/README.md
@@ -11,7 +11,7 @@ pnpm dev
```bash
# Terminal 2
pnpm webstudio-cli link
-# add following link https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/cddc1d44-af37-4cb6-a430-d300cf6f932d?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d&mode=preview
+# add following link https://webstudio-builder-git-main-getwebstudio.vercel.app/builder/cddc1d44-af37-4cb6-a430-d300cf6f932d?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d&mode=preview
pnpm webstudio-cli sync && pnpm prettier --write ./.webstudio/
# data.json generated
diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.tsx
index 7e7df038e6..295657ae0a 100644
--- a/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.tsx
+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.tsx
@@ -3,14 +3,54 @@
import { type ReactNode, useState } from "react";
import type { PageData } from "~/routes/_index";
-import type { Asset } from "@webstudio-is/sdk";
+import type { Asset, ImageAsset, SiteMeta } from "@webstudio-is/sdk";
import {
Body as Body,
Image as Image,
} from "@webstudio-is/sdk-components-react";
export const fontAssets: Asset[] = [];
+export const imageAssets: ImageAsset[] = [
+ {
+ id: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ name: "DALL_E_2023-10-30_12.39.46_-_Photo_logo_with_a_bold_cat_silhouette_centered_on_a_contrasting_background_designed_for_clarity_at_small_32x32_favicon_resolution_00h6cEA8u2pJRvVJv7hRe.png",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 268326,
+ type: "image",
+ format: "png",
+ createdAt: "2023-10-30T13:51:08.416Z",
+ meta: { width: 790, height: 786 },
+ },
+ {
+ id: "9a8bc926-7804-4d3f-af81-69196b1d2ed8",
+ name: "small-avif-kitty_FnabJsioMWpBtXZSGf4DR.webp",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 2906,
+ type: "image",
+ format: "webp",
+ createdAt: "2023-09-12T09:44:22.120Z",
+ meta: { width: 100, height: 100 },
+ },
+ {
+ id: "cd939c56-bcdd-4e64-bd9c-567a9bccd3da",
+ name: "_937084ed-a798-49fe-8664-df93a2af605e_uiBk3o6UWdqolyakMvQJ9.jpeg",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 210614,
+ type: "image",
+ format: "jpeg",
+ createdAt: "2023-09-06T11:28:43.031Z",
+ meta: { width: 1024, height: 1024 },
+ },
+];
export const pageData: PageData = {
+ site: {
+ siteName: "KittyGuardedZone",
+ faviconAssetId: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ code: "",
+ },
page: {
id: "szYLvBduHPmbtqQKCDY0b",
name: "RouteWithSymbols",
diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[form]._index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[form]._index.tsx
index 905543ce4f..893b331dd8 100644
--- a/fixtures/webstudio-remix-vercel/app/__generated__/[form]._index.tsx
+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[form]._index.tsx
@@ -3,7 +3,7 @@
import { type ReactNode, useState } from "react";
import type { PageData } from "~/routes/_index";
-import type { Asset } from "@webstudio-is/sdk";
+import type { Asset, ImageAsset, SiteMeta } from "@webstudio-is/sdk";
import {
Body as Body,
Box as Box,
@@ -15,7 +15,47 @@ import {
import { Form as Form } from "@webstudio-is/sdk-components-react-remix";
export const fontAssets: Asset[] = [];
+export const imageAssets: ImageAsset[] = [
+ {
+ id: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ name: "DALL_E_2023-10-30_12.39.46_-_Photo_logo_with_a_bold_cat_silhouette_centered_on_a_contrasting_background_designed_for_clarity_at_small_32x32_favicon_resolution_00h6cEA8u2pJRvVJv7hRe.png",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 268326,
+ type: "image",
+ format: "png",
+ createdAt: "2023-10-30T13:51:08.416Z",
+ meta: { width: 790, height: 786 },
+ },
+ {
+ id: "9a8bc926-7804-4d3f-af81-69196b1d2ed8",
+ name: "small-avif-kitty_FnabJsioMWpBtXZSGf4DR.webp",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 2906,
+ type: "image",
+ format: "webp",
+ createdAt: "2023-09-12T09:44:22.120Z",
+ meta: { width: 100, height: 100 },
+ },
+ {
+ id: "cd939c56-bcdd-4e64-bd9c-567a9bccd3da",
+ name: "_937084ed-a798-49fe-8664-df93a2af605e_uiBk3o6UWdqolyakMvQJ9.jpeg",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 210614,
+ type: "image",
+ format: "jpeg",
+ createdAt: "2023-09-06T11:28:43.031Z",
+ meta: { width: 1024, height: 1024 },
+ },
+];
export const pageData: PageData = {
+ site: {
+ siteName: "KittyGuardedZone",
+ faviconAssetId: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ code: "",
+ },
page: {
id: "U1tRJl2ERr8_OFe0g9cN_",
name: "form",
diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[heading-with-id]._index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[heading-with-id]._index.tsx
index 6db32677bb..438d64455f 100644
--- a/fixtures/webstudio-remix-vercel/app/__generated__/[heading-with-id]._index.tsx
+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[heading-with-id]._index.tsx
@@ -3,14 +3,54 @@
import { type ReactNode, useState } from "react";
import type { PageData } from "~/routes/_index";
-import type { Asset } from "@webstudio-is/sdk";
+import type { Asset, ImageAsset, SiteMeta } from "@webstudio-is/sdk";
import {
Body as Body,
Heading as Heading,
} from "@webstudio-is/sdk-components-react";
export const fontAssets: Asset[] = [];
+export const imageAssets: ImageAsset[] = [
+ {
+ id: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ name: "DALL_E_2023-10-30_12.39.46_-_Photo_logo_with_a_bold_cat_silhouette_centered_on_a_contrasting_background_designed_for_clarity_at_small_32x32_favicon_resolution_00h6cEA8u2pJRvVJv7hRe.png",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 268326,
+ type: "image",
+ format: "png",
+ createdAt: "2023-10-30T13:51:08.416Z",
+ meta: { width: 790, height: 786 },
+ },
+ {
+ id: "9a8bc926-7804-4d3f-af81-69196b1d2ed8",
+ name: "small-avif-kitty_FnabJsioMWpBtXZSGf4DR.webp",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 2906,
+ type: "image",
+ format: "webp",
+ createdAt: "2023-09-12T09:44:22.120Z",
+ meta: { width: 100, height: 100 },
+ },
+ {
+ id: "cd939c56-bcdd-4e64-bd9c-567a9bccd3da",
+ name: "_937084ed-a798-49fe-8664-df93a2af605e_uiBk3o6UWdqolyakMvQJ9.jpeg",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 210614,
+ type: "image",
+ format: "jpeg",
+ createdAt: "2023-09-06T11:28:43.031Z",
+ meta: { width: 1024, height: 1024 },
+ },
+];
export const pageData: PageData = {
+ site: {
+ siteName: "KittyGuardedZone",
+ faviconAssetId: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ code: "",
+ },
page: {
id: "-J9I4Oo6mONfQlf_3-OqG",
name: "heading-with-id",
diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.tsx
index 0d0974d827..ccaeb0e55b 100644
--- a/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.tsx
+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.tsx
@@ -3,7 +3,7 @@
import { type ReactNode, useState } from "react";
import type { PageData } from "~/routes/_index";
-import type { Asset } from "@webstudio-is/sdk";
+import type { Asset, ImageAsset, SiteMeta } from "@webstudio-is/sdk";
import {
Body as Body,
Text as Text,
@@ -19,12 +19,57 @@ import {
} from "@webstudio-is/sdk-components-react-radix";
export const fontAssets: Asset[] = [];
+export const imageAssets: ImageAsset[] = [
+ {
+ id: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ name: "DALL_E_2023-10-30_12.39.46_-_Photo_logo_with_a_bold_cat_silhouette_centered_on_a_contrasting_background_designed_for_clarity_at_small_32x32_favicon_resolution_00h6cEA8u2pJRvVJv7hRe.png",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 268326,
+ type: "image",
+ format: "png",
+ createdAt: "2023-10-30T13:51:08.416Z",
+ meta: { width: 790, height: 786 },
+ },
+ {
+ id: "9a8bc926-7804-4d3f-af81-69196b1d2ed8",
+ name: "small-avif-kitty_FnabJsioMWpBtXZSGf4DR.webp",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 2906,
+ type: "image",
+ format: "webp",
+ createdAt: "2023-09-12T09:44:22.120Z",
+ meta: { width: 100, height: 100 },
+ },
+ {
+ id: "cd939c56-bcdd-4e64-bd9c-567a9bccd3da",
+ name: "_937084ed-a798-49fe-8664-df93a2af605e_uiBk3o6UWdqolyakMvQJ9.jpeg",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 210614,
+ type: "image",
+ format: "jpeg",
+ createdAt: "2023-09-06T11:28:43.031Z",
+ meta: { width: 1024, height: 1024 },
+ },
+];
export const pageData: PageData = {
+ site: {
+ siteName: "KittyGuardedZone",
+ faviconAssetId: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ code: "",
+ },
page: {
id: "xfvB4UThQXmQ_OubPYrkg",
- name: "radix",
- title: "radix",
- meta: { description: "" },
+ name: "radix excluded from the search",
+ title: "Radix Revelations: Unraveling the Feline Mystique",
+ meta: {
+ description:
+ "Delve deep into the radix roots of feline behaviors. At KittyNoTouchy, we dissect the core essence, or 'radix', of what makes cats the enigmatic creatures they are. Join us as we explore the radix of their instincts, habits, and quirks.",
+ excludePageFromSearch: true,
+ socialImageAssetId: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ },
rootInstanceId: "uKWGyE9JY3cPwY-xI9vk6",
path: "/radix",
},
diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/_index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/_index.tsx
index 662143e3f9..370098c958 100644
--- a/fixtures/webstudio-remix-vercel/app/__generated__/_index.tsx
+++ b/fixtures/webstudio-remix-vercel/app/__generated__/_index.tsx
@@ -3,7 +3,7 @@
import { type ReactNode, useState } from "react";
import type { PageData } from "~/routes/_index";
-import type { Asset } from "@webstudio-is/sdk";
+import type { Asset, ImageAsset, SiteMeta } from "@webstudio-is/sdk";
import {
Body as Body,
Heading as Heading,
@@ -15,12 +15,56 @@ import {
import { Link as Link } from "@webstudio-is/sdk-components-react-remix";
export const fontAssets: Asset[] = [];
+export const imageAssets: ImageAsset[] = [
+ {
+ id: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ name: "DALL_E_2023-10-30_12.39.46_-_Photo_logo_with_a_bold_cat_silhouette_centered_on_a_contrasting_background_designed_for_clarity_at_small_32x32_favicon_resolution_00h6cEA8u2pJRvVJv7hRe.png",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 268326,
+ type: "image",
+ format: "png",
+ createdAt: "2023-10-30T13:51:08.416Z",
+ meta: { width: 790, height: 786 },
+ },
+ {
+ id: "9a8bc926-7804-4d3f-af81-69196b1d2ed8",
+ name: "small-avif-kitty_FnabJsioMWpBtXZSGf4DR.webp",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 2906,
+ type: "image",
+ format: "webp",
+ createdAt: "2023-09-12T09:44:22.120Z",
+ meta: { width: 100, height: 100 },
+ },
+ {
+ id: "cd939c56-bcdd-4e64-bd9c-567a9bccd3da",
+ name: "_937084ed-a798-49fe-8664-df93a2af605e_uiBk3o6UWdqolyakMvQJ9.jpeg",
+ description: null,
+ projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ size: 210614,
+ type: "image",
+ format: "jpeg",
+ createdAt: "2023-09-06T11:28:43.031Z",
+ meta: { width: 1024, height: 1024 },
+ },
+];
export const pageData: PageData = {
+ site: {
+ siteName: "KittyGuardedZone",
+ faviconAssetId: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ code: "",
+ },
page: {
id: "7Db64ZXgYiRqKSQNR-qTQ",
name: "Home",
- title: "Home",
- meta: {},
+ title: "The Ultimate Cat Protection Zone",
+ meta: {
+ description:
+ "Dive into the world of felines and discover why some whiskers are best left untouched. From intriguing cat behaviors to protective measures, \nKittyGuardedZone is your go-to hub for all things 'hands-off' in the cat realm.",
+ socialImageAssetId: "cd939c56-bcdd-4e64-bd9c-567a9bccd3da",
+ },
rootInstanceId: "On9cvWCxr5rdZtY9O1Bv0",
path: "",
},
diff --git a/fixtures/webstudio-remix-vercel/app/constants.mjs b/fixtures/webstudio-remix-vercel/app/constants.mjs
index 5a92afbe55..c2280610cb 100644
--- a/fixtures/webstudio-remix-vercel/app/constants.mjs
+++ b/fixtures/webstudio-remix-vercel/app/constants.mjs
@@ -8,18 +8,22 @@ export const imageBaseUrl = "/assets/";
/**
* @type {import("@webstudio-is/image").ImageLoader}
*/
-export const imageLoader = ({ quality, src, width }) => {
+export const imageLoader = (props) => {
if (process.env.NODE_ENV !== "production") {
- return imageBaseUrl + src;
+ return imageBaseUrl + props.src;
+ }
+
+ if (props.format === "raw") {
+ return imageBaseUrl + props.src;
}
// https://vercel.com/blog/build-your-own-web-framework#automatic-image-optimization
return (
"/_vercel/image?url=" +
- encodeURIComponent(imageBaseUrl + src) +
+ encodeURIComponent(imageBaseUrl + props.src) +
"&w=" +
- width +
+ props.width +
"&q=" +
- quality
+ props.quality
);
};
diff --git a/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx
index 279261367e..1a0a54288b 100644
--- a/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx
+++ b/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx
@@ -4,9 +4,10 @@ import {
type LinksFunction,
type LinkDescriptor,
type ActionArgs,
+ type LoaderArgs,
json,
} from "@remix-run/server-runtime";
-import type { Page as PageType } from "@webstudio-is/sdk";
+import type { Page as PageType, SiteMeta } from "@webstudio-is/sdk";
import { ReactSdkContext } from "@webstudio-is/react-sdk";
import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";
import { Scripts, ScrollRestoration } from "@remix-run/react";
@@ -18,34 +19,108 @@ import {
pagesPaths,
formsProperties,
Page,
+ imageAssets,
} from "../__generated__/[_route_with_symbols_]._index.tsx";
import css from "../__generated__/index.css";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "~/constants.mjs";
export type PageData = {
+ site?: SiteMeta;
page: PageType;
};
-export const meta: V2_ServerRuntimeMetaFunction = () => {
- const { page } = pageData;
- const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [
- { title: page?.title || "Webstudio" },
- ];
- for (const [name, value] of Object.entries(page?.meta ?? {})) {
- if (name.startsWith("og:")) {
- metas.push({
- property: name,
- content: value,
- });
- continue;
- }
+export const loader = async (arg: LoaderArgs) => {
+ const host =
+ arg.request.headers.get("x-forwarded-host") ||
+ arg.request.headers.get("host") ||
+ "";
+
+ const url = new URL(arg.request.url);
+ url.host = host;
+ url.protocol = "https";
+
+ return json(
+ { host, url: url.href },
+ // No way for current information to change, so add cache for 10 minutes
+ // In case of CRM Data, this should be set to 0
+ { headers: { "Cache-Control": "public, max-age=600" } }
+ );
+};
+
+export const headers = () => {
+ return {
+ "Cache-Control": "public, max-age=0, must-revalidate",
+ };
+};
+
+export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {
+ const { page, site } = pageData;
+
+ const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [];
+
+ if (data?.url) {
+ metas.push({
+ property: "og:url",
+ content: data.url,
+ });
+ }
+
+ if (page.title) {
+ metas.push({ title: page.title });
+
+ metas.push({
+ property: "og:title",
+ content: page.title,
+ });
+ }
+
+ metas.push({ property: "og:type", content: "website" });
+
+ const origin = `https://${data?.host}`;
+
+ if (site?.siteName) {
+ metas.push({
+ property: "og:site_name",
+ content: site.siteName,
+ });
+ metas.push({
+ "script:ld+json": {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: site.siteName,
+ url: origin,
+ },
+ });
+ }
+ if (page.meta.description) {
+ metas.push({
+ name: "description",
+ content: page.meta.description,
+ });
metas.push({
- name,
- content: value,
+ property: "og:description",
+ content: page.meta.description,
});
}
+ if (page.meta.socialImageAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === page.meta.socialImageAssetId
+ );
+
+ if (imageAsset) {
+ metas.push({
+ property: "og:image",
+ content: `https://${data?.host}${imageLoader({
+ src: imageAsset.name,
+ // Do not transform social image (not enough information do we need to do this)
+ format: "raw",
+ })}`,
+ });
+ }
+ }
+
return metas;
};
@@ -57,6 +132,39 @@ export const links: LinksFunction = () => {
href: css,
});
+ const { site } = pageData;
+
+ if (site?.faviconAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === site.faviconAssetId
+ );
+
+ if (imageAsset) {
+ result.push({
+ rel: "icon",
+ href: imageLoader({
+ src: imageAsset.name,
+ width: 128,
+ quality: 100,
+ format: "auto",
+ }),
+ type: undefined,
+ });
+ }
+ } else {
+ result.push({
+ rel: "icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+
+ result.push({
+ rel: "shortcut icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+ }
+
for (const asset of fontAssets) {
if (asset.type === "font") {
result.push({
diff --git a/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx
index 5f29aac026..5d8e4720ce 100644
--- a/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx
+++ b/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx
@@ -4,9 +4,10 @@ import {
type LinksFunction,
type LinkDescriptor,
type ActionArgs,
+ type LoaderArgs,
json,
} from "@remix-run/server-runtime";
-import type { Page as PageType } from "@webstudio-is/sdk";
+import type { Page as PageType, SiteMeta } from "@webstudio-is/sdk";
import { ReactSdkContext } from "@webstudio-is/react-sdk";
import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";
import { Scripts, ScrollRestoration } from "@remix-run/react";
@@ -18,34 +19,108 @@ import {
pagesPaths,
formsProperties,
Page,
+ imageAssets,
} from "../__generated__/[form]._index.tsx";
import css from "../__generated__/index.css";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "~/constants.mjs";
export type PageData = {
+ site?: SiteMeta;
page: PageType;
};
-export const meta: V2_ServerRuntimeMetaFunction = () => {
- const { page } = pageData;
- const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [
- { title: page?.title || "Webstudio" },
- ];
- for (const [name, value] of Object.entries(page?.meta ?? {})) {
- if (name.startsWith("og:")) {
- metas.push({
- property: name,
- content: value,
- });
- continue;
- }
+export const loader = async (arg: LoaderArgs) => {
+ const host =
+ arg.request.headers.get("x-forwarded-host") ||
+ arg.request.headers.get("host") ||
+ "";
+
+ const url = new URL(arg.request.url);
+ url.host = host;
+ url.protocol = "https";
+
+ return json(
+ { host, url: url.href },
+ // No way for current information to change, so add cache for 10 minutes
+ // In case of CRM Data, this should be set to 0
+ { headers: { "Cache-Control": "public, max-age=600" } }
+ );
+};
+
+export const headers = () => {
+ return {
+ "Cache-Control": "public, max-age=0, must-revalidate",
+ };
+};
+
+export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {
+ const { page, site } = pageData;
+
+ const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [];
+
+ if (data?.url) {
+ metas.push({
+ property: "og:url",
+ content: data.url,
+ });
+ }
+
+ if (page.title) {
+ metas.push({ title: page.title });
+
+ metas.push({
+ property: "og:title",
+ content: page.title,
+ });
+ }
+
+ metas.push({ property: "og:type", content: "website" });
+
+ const origin = `https://${data?.host}`;
+
+ if (site?.siteName) {
+ metas.push({
+ property: "og:site_name",
+ content: site.siteName,
+ });
+ metas.push({
+ "script:ld+json": {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: site.siteName,
+ url: origin,
+ },
+ });
+ }
+ if (page.meta.description) {
+ metas.push({
+ name: "description",
+ content: page.meta.description,
+ });
metas.push({
- name,
- content: value,
+ property: "og:description",
+ content: page.meta.description,
});
}
+ if (page.meta.socialImageAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === page.meta.socialImageAssetId
+ );
+
+ if (imageAsset) {
+ metas.push({
+ property: "og:image",
+ content: `https://${data?.host}${imageLoader({
+ src: imageAsset.name,
+ // Do not transform social image (not enough information do we need to do this)
+ format: "raw",
+ })}`,
+ });
+ }
+ }
+
return metas;
};
@@ -57,6 +132,39 @@ export const links: LinksFunction = () => {
href: css,
});
+ const { site } = pageData;
+
+ if (site?.faviconAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === site.faviconAssetId
+ );
+
+ if (imageAsset) {
+ result.push({
+ rel: "icon",
+ href: imageLoader({
+ src: imageAsset.name,
+ width: 128,
+ quality: 100,
+ format: "auto",
+ }),
+ type: undefined,
+ });
+ }
+ } else {
+ result.push({
+ rel: "icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+
+ result.push({
+ rel: "shortcut icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+ }
+
for (const asset of fontAssets) {
if (asset.type === "font") {
result.push({
diff --git a/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx
index b60a66faee..be7bf26b3f 100644
--- a/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx
+++ b/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx
@@ -4,9 +4,10 @@ import {
type LinksFunction,
type LinkDescriptor,
type ActionArgs,
+ type LoaderArgs,
json,
} from "@remix-run/server-runtime";
-import type { Page as PageType } from "@webstudio-is/sdk";
+import type { Page as PageType, SiteMeta } from "@webstudio-is/sdk";
import { ReactSdkContext } from "@webstudio-is/react-sdk";
import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";
import { Scripts, ScrollRestoration } from "@remix-run/react";
@@ -18,34 +19,108 @@ import {
pagesPaths,
formsProperties,
Page,
+ imageAssets,
} from "../__generated__/[heading-with-id]._index.tsx";
import css from "../__generated__/index.css";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "~/constants.mjs";
export type PageData = {
+ site?: SiteMeta;
page: PageType;
};
-export const meta: V2_ServerRuntimeMetaFunction = () => {
- const { page } = pageData;
- const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [
- { title: page?.title || "Webstudio" },
- ];
- for (const [name, value] of Object.entries(page?.meta ?? {})) {
- if (name.startsWith("og:")) {
- metas.push({
- property: name,
- content: value,
- });
- continue;
- }
+export const loader = async (arg: LoaderArgs) => {
+ const host =
+ arg.request.headers.get("x-forwarded-host") ||
+ arg.request.headers.get("host") ||
+ "";
+
+ const url = new URL(arg.request.url);
+ url.host = host;
+ url.protocol = "https";
+
+ return json(
+ { host, url: url.href },
+ // No way for current information to change, so add cache for 10 minutes
+ // In case of CRM Data, this should be set to 0
+ { headers: { "Cache-Control": "public, max-age=600" } }
+ );
+};
+
+export const headers = () => {
+ return {
+ "Cache-Control": "public, max-age=0, must-revalidate",
+ };
+};
+
+export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {
+ const { page, site } = pageData;
+
+ const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [];
+
+ if (data?.url) {
+ metas.push({
+ property: "og:url",
+ content: data.url,
+ });
+ }
+
+ if (page.title) {
+ metas.push({ title: page.title });
+
+ metas.push({
+ property: "og:title",
+ content: page.title,
+ });
+ }
+
+ metas.push({ property: "og:type", content: "website" });
+
+ const origin = `https://${data?.host}`;
+
+ if (site?.siteName) {
+ metas.push({
+ property: "og:site_name",
+ content: site.siteName,
+ });
+ metas.push({
+ "script:ld+json": {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: site.siteName,
+ url: origin,
+ },
+ });
+ }
+ if (page.meta.description) {
+ metas.push({
+ name: "description",
+ content: page.meta.description,
+ });
metas.push({
- name,
- content: value,
+ property: "og:description",
+ content: page.meta.description,
});
}
+ if (page.meta.socialImageAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === page.meta.socialImageAssetId
+ );
+
+ if (imageAsset) {
+ metas.push({
+ property: "og:image",
+ content: `https://${data?.host}${imageLoader({
+ src: imageAsset.name,
+ // Do not transform social image (not enough information do we need to do this)
+ format: "raw",
+ })}`,
+ });
+ }
+ }
+
return metas;
};
@@ -57,6 +132,39 @@ export const links: LinksFunction = () => {
href: css,
});
+ const { site } = pageData;
+
+ if (site?.faviconAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === site.faviconAssetId
+ );
+
+ if (imageAsset) {
+ result.push({
+ rel: "icon",
+ href: imageLoader({
+ src: imageAsset.name,
+ width: 128,
+ quality: 100,
+ format: "auto",
+ }),
+ type: undefined,
+ });
+ }
+ } else {
+ result.push({
+ rel: "icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+
+ result.push({
+ rel: "shortcut icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+ }
+
for (const asset of fontAssets) {
if (asset.type === "font") {
result.push({
diff --git a/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx
index 2cd4a22e82..6d843561df 100644
--- a/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx
+++ b/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx
@@ -4,9 +4,10 @@ import {
type LinksFunction,
type LinkDescriptor,
type ActionArgs,
+ type LoaderArgs,
json,
} from "@remix-run/server-runtime";
-import type { Page as PageType } from "@webstudio-is/sdk";
+import type { Page as PageType, SiteMeta } from "@webstudio-is/sdk";
import { ReactSdkContext } from "@webstudio-is/react-sdk";
import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";
import { Scripts, ScrollRestoration } from "@remix-run/react";
@@ -18,34 +19,108 @@ import {
pagesPaths,
formsProperties,
Page,
+ imageAssets,
} from "../__generated__/[radix]._index.tsx";
import css from "../__generated__/index.css";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "~/constants.mjs";
export type PageData = {
+ site?: SiteMeta;
page: PageType;
};
-export const meta: V2_ServerRuntimeMetaFunction = () => {
- const { page } = pageData;
- const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [
- { title: page?.title || "Webstudio" },
- ];
- for (const [name, value] of Object.entries(page?.meta ?? {})) {
- if (name.startsWith("og:")) {
- metas.push({
- property: name,
- content: value,
- });
- continue;
- }
+export const loader = async (arg: LoaderArgs) => {
+ const host =
+ arg.request.headers.get("x-forwarded-host") ||
+ arg.request.headers.get("host") ||
+ "";
+
+ const url = new URL(arg.request.url);
+ url.host = host;
+ url.protocol = "https";
+
+ return json(
+ { host, url: url.href },
+ // No way for current information to change, so add cache for 10 minutes
+ // In case of CRM Data, this should be set to 0
+ { headers: { "Cache-Control": "public, max-age=600" } }
+ );
+};
+
+export const headers = () => {
+ return {
+ "Cache-Control": "public, max-age=0, must-revalidate",
+ };
+};
+
+export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {
+ const { page, site } = pageData;
+
+ const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [];
+
+ if (data?.url) {
+ metas.push({
+ property: "og:url",
+ content: data.url,
+ });
+ }
+
+ if (page.title) {
+ metas.push({ title: page.title });
+
+ metas.push({
+ property: "og:title",
+ content: page.title,
+ });
+ }
+
+ metas.push({ property: "og:type", content: "website" });
+
+ const origin = `https://${data?.host}`;
+
+ if (site?.siteName) {
+ metas.push({
+ property: "og:site_name",
+ content: site.siteName,
+ });
+ metas.push({
+ "script:ld+json": {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: site.siteName,
+ url: origin,
+ },
+ });
+ }
+ if (page.meta.description) {
+ metas.push({
+ name: "description",
+ content: page.meta.description,
+ });
metas.push({
- name,
- content: value,
+ property: "og:description",
+ content: page.meta.description,
});
}
+ if (page.meta.socialImageAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === page.meta.socialImageAssetId
+ );
+
+ if (imageAsset) {
+ metas.push({
+ property: "og:image",
+ content: `https://${data?.host}${imageLoader({
+ src: imageAsset.name,
+ // Do not transform social image (not enough information do we need to do this)
+ format: "raw",
+ })}`,
+ });
+ }
+ }
+
return metas;
};
@@ -57,6 +132,39 @@ export const links: LinksFunction = () => {
href: css,
});
+ const { site } = pageData;
+
+ if (site?.faviconAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === site.faviconAssetId
+ );
+
+ if (imageAsset) {
+ result.push({
+ rel: "icon",
+ href: imageLoader({
+ src: imageAsset.name,
+ width: 128,
+ quality: 100,
+ format: "auto",
+ }),
+ type: undefined,
+ });
+ }
+ } else {
+ result.push({
+ rel: "icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+
+ result.push({
+ rel: "shortcut icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+ }
+
for (const asset of fontAssets) {
if (asset.type === "font") {
result.push({
diff --git a/fixtures/webstudio-remix-vercel/app/routes/_index.tsx b/fixtures/webstudio-remix-vercel/app/routes/_index.tsx
index 29e9cc7e27..d67253fa9f 100644
--- a/fixtures/webstudio-remix-vercel/app/routes/_index.tsx
+++ b/fixtures/webstudio-remix-vercel/app/routes/_index.tsx
@@ -4,9 +4,10 @@ import {
type LinksFunction,
type LinkDescriptor,
type ActionArgs,
+ type LoaderArgs,
json,
} from "@remix-run/server-runtime";
-import type { Page as PageType } from "@webstudio-is/sdk";
+import type { Page as PageType, SiteMeta } from "@webstudio-is/sdk";
import { ReactSdkContext } from "@webstudio-is/react-sdk";
import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";
import { Scripts, ScrollRestoration } from "@remix-run/react";
@@ -18,34 +19,108 @@ import {
pagesPaths,
formsProperties,
Page,
+ imageAssets,
} from "../__generated__/_index.tsx";
import css from "../__generated__/index.css";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "~/constants.mjs";
export type PageData = {
+ site?: SiteMeta;
page: PageType;
};
-export const meta: V2_ServerRuntimeMetaFunction = () => {
- const { page } = pageData;
- const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [
- { title: page?.title || "Webstudio" },
- ];
- for (const [name, value] of Object.entries(page?.meta ?? {})) {
- if (name.startsWith("og:")) {
- metas.push({
- property: name,
- content: value,
- });
- continue;
- }
+export const loader = async (arg: LoaderArgs) => {
+ const host =
+ arg.request.headers.get("x-forwarded-host") ||
+ arg.request.headers.get("host") ||
+ "";
+
+ const url = new URL(arg.request.url);
+ url.host = host;
+ url.protocol = "https";
+
+ return json(
+ { host, url: url.href },
+ // No way for current information to change, so add cache for 10 minutes
+ // In case of CRM Data, this should be set to 0
+ { headers: { "Cache-Control": "public, max-age=600" } }
+ );
+};
+
+export const headers = () => {
+ return {
+ "Cache-Control": "public, max-age=0, must-revalidate",
+ };
+};
+
+export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {
+ const { page, site } = pageData;
+
+ const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [];
+
+ if (data?.url) {
+ metas.push({
+ property: "og:url",
+ content: data.url,
+ });
+ }
+
+ if (page.title) {
+ metas.push({ title: page.title });
+
+ metas.push({
+ property: "og:title",
+ content: page.title,
+ });
+ }
+
+ metas.push({ property: "og:type", content: "website" });
+
+ const origin = `https://${data?.host}`;
+
+ if (site?.siteName) {
+ metas.push({
+ property: "og:site_name",
+ content: site.siteName,
+ });
+ metas.push({
+ "script:ld+json": {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: site.siteName,
+ url: origin,
+ },
+ });
+ }
+ if (page.meta.description) {
+ metas.push({
+ name: "description",
+ content: page.meta.description,
+ });
metas.push({
- name,
- content: value,
+ property: "og:description",
+ content: page.meta.description,
});
}
+ if (page.meta.socialImageAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === page.meta.socialImageAssetId
+ );
+
+ if (imageAsset) {
+ metas.push({
+ property: "og:image",
+ content: `https://${data?.host}${imageLoader({
+ src: imageAsset.name,
+ // Do not transform social image (not enough information do we need to do this)
+ format: "raw",
+ })}`,
+ });
+ }
+ }
+
return metas;
};
@@ -57,6 +132,39 @@ export const links: LinksFunction = () => {
href: css,
});
+ const { site } = pageData;
+
+ if (site?.faviconAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === site.faviconAssetId
+ );
+
+ if (imageAsset) {
+ result.push({
+ rel: "icon",
+ href: imageLoader({
+ src: imageAsset.name,
+ width: 128,
+ quality: 100,
+ format: "auto",
+ }),
+ type: undefined,
+ });
+ }
+ } else {
+ result.push({
+ rel: "icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+
+ result.push({
+ rel: "shortcut icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+ }
+
for (const asset of fontAssets) {
if (asset.type === "font") {
result.push({
diff --git a/fixtures/webstudio-remix-vercel/package.json b/fixtures/webstudio-remix-vercel/package.json
index 9f269d5b8a..d35e08c984 100644
--- a/fixtures/webstudio-remix-vercel/package.json
+++ b/fixtures/webstudio-remix-vercel/package.json
@@ -4,7 +4,7 @@
"build": "remix build",
"dev": "remix dev",
"typecheck": "tsc",
- "fixtures:link": "webstudio link --link 'https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/cddc1d44-af37-4cb6-a430-d300cf6f932d?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d&mode=preview'",
+ "fixtures:link": "webstudio link --link 'https://webstudio-builder-git-main-getwebstudio.vercel.app/builder/cddc1d44-af37-4cb6-a430-d300cf6f932d?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d&mode=preview'",
"fixtures:sync": "webstudio sync && pnpm prettier --write ./.webstudio/",
"fixtures:build": "webstudio build --preview && pnpm prettier --write ./app/ ./package.json"
},
diff --git a/fixtures/webstudio-remix-vercel/public/assets/DALL_E_2023-10-30_12.39.46_-_Photo_logo_with_a_bold_cat_silhouette_centered_on_a_contrasting_background_designed_for_clarity_at_small_32x32_favicon_resolution_00h6cEA8u2pJRvVJv7hRe.png b/fixtures/webstudio-remix-vercel/public/assets/DALL_E_2023-10-30_12.39.46_-_Photo_logo_with_a_bold_cat_silhouette_centered_on_a_contrasting_background_designed_for_clarity_at_small_32x32_favicon_resolution_00h6cEA8u2pJRvVJv7hRe.png
new file mode 100644
index 0000000000..72c49a3ab2
Binary files /dev/null and b/fixtures/webstudio-remix-vercel/public/assets/DALL_E_2023-10-30_12.39.46_-_Photo_logo_with_a_bold_cat_silhouette_centered_on_a_contrasting_background_designed_for_clarity_at_small_32x32_favicon_resolution_00h6cEA8u2pJRvVJv7hRe.png differ
diff --git a/packages/cli/__generated__/index.tsx b/packages/cli/__generated__/index.tsx
index da6a943af3..a96d8ebfdb 100644
--- a/packages/cli/__generated__/index.tsx
+++ b/packages/cli/__generated__/index.tsx
@@ -3,11 +3,17 @@
**/
import type { ReactNode } from "react";
import type { PageData } from "../templates/route-template";
-import type { Asset } from "@webstudio-is/sdk";
+import type { Asset, ImageAsset } from "@webstudio-is/sdk";
export const fontAssets: Asset[] = [];
+export const imageAssets: ImageAsset[] = [];
export const pageData: PageData = {
+ site: {
+ siteName: "",
+ faviconAssetId: "",
+ code: "",
+ },
page: {
id: "",
name: "",
diff --git a/packages/cli/src/prebuild.ts b/packages/cli/src/prebuild.ts
index 13b0e8dbb7..78bc695a73 100644
--- a/packages/cli/src/prebuild.ts
+++ b/packages/cli/src/prebuild.ts
@@ -35,6 +35,7 @@ import type {
Deployment,
Asset,
FontAsset,
+ ImageAsset,
} from "@webstudio-is/sdk";
import {
createScope,
@@ -340,6 +341,13 @@ export const prebuild = async (options: {
const assetsToDownload: Promise<void>[] = [];
const fontAssets: FontAsset[] = [];
+ const imageAssets: ImageAsset[] = [];
+ for (const asset of siteData.assets) {
+ if (asset.type === "image") {
+ imageAssets.push(asset);
+ }
+ }
+
const appDomain = options.preview ? "wstd.work" : "wstd.io";
const assetBuildUrl = `https://${domain}.${appDomain}/cgi/asset/`;
@@ -353,8 +361,6 @@ export const prebuild = async (options: {
for (const asset of siteData.assets) {
if (asset.type === "image") {
const imageSrc = imageLoader({
- width: 16,
- quality: 100,
src: asset.name,
format: "raw",
});
@@ -463,6 +469,7 @@ export const prebuild = async (options: {
const pageData = siteDataByPage[pathName];
// serialize data only used in runtime
const renderedPageData: PageData = {
+ site: siteData.build.pages.meta,
page: pageData.page,
};
@@ -491,9 +498,10 @@ export const prebuild = async (options: {
/* This is a auto generated file for building the project */ \n
import { type ReactNode, useState } from "react";
import type { PageData } from "~/routes/_index";
-import type { Asset } from "@webstudio-is/sdk";
+import type { Asset, ImageAsset, SiteMeta } from "@webstudio-is/sdk";
${componentImports}
export const fontAssets: Asset[] = ${JSON.stringify(fontAssets)}
+export const imageAssets: ImageAsset[] = ${JSON.stringify(imageAssets)}
export const pageData: PageData = ${JSON.stringify(renderedPageData)};
export const user: { email: string | null } | undefined = ${JSON.stringify(
siteData.user
diff --git a/packages/cli/templates/route-template.tsx b/packages/cli/templates/route-template.tsx
index 4df0c256c2..5abdb3b5e0 100644
--- a/packages/cli/templates/route-template.tsx
+++ b/packages/cli/templates/route-template.tsx
@@ -4,9 +4,10 @@ import {
type LinksFunction,
type LinkDescriptor,
type ActionArgs,
+ type LoaderArgs,
json,
} from "@remix-run/server-runtime";
-import type { Page as PageType } from "@webstudio-is/sdk";
+import type { Page as PageType, SiteMeta } from "@webstudio-is/sdk";
import { ReactSdkContext } from "@webstudio-is/react-sdk";
import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";
import { Scripts, ScrollRestoration } from "@remix-run/react";
@@ -18,34 +19,108 @@ import {
pagesPaths,
formsProperties,
Page,
+ imageAssets,
} from "../__generated__/index";
import css from "../__generated__/index.css";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "~/constants.mjs";
export type PageData = {
+ site?: SiteMeta;
page: PageType;
};
-export const meta: V2_ServerRuntimeMetaFunction = () => {
- const { page } = pageData;
- const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [
- { title: page?.title || "Webstudio" },
- ];
- for (const [name, value] of Object.entries(page?.meta ?? {})) {
- if (name.startsWith("og:")) {
- metas.push({
- property: name,
- content: value,
- });
- continue;
- }
+export const loader = async (arg: LoaderArgs) => {
+ const host =
+ arg.request.headers.get("x-forwarded-host") ||
+ arg.request.headers.get("host") ||
+ "";
+
+ const url = new URL(arg.request.url);
+ url.host = host;
+ url.protocol = "https";
+
+ return json(
+ { host, url: url.href },
+ // No way for current information to change, so add cache for 10 minutes
+ // In case of CRM Data, this should be set to 0
+ { headers: { "Cache-Control": "public, max-age=600" } }
+ );
+};
+
+export const headers = () => {
+ return {
+ "Cache-Control": "public, max-age=0, must-revalidate",
+ };
+};
+
+export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {
+ const { page, site } = pageData;
+
+ const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [];
+
+ if (data?.url) {
+ metas.push({
+ property: "og:url",
+ content: data.url,
+ });
+ }
+
+ if (page.title) {
+ metas.push({ title: page.title });
+
+ metas.push({
+ property: "og:title",
+ content: page.title,
+ });
+ }
+
+ metas.push({ property: "og:type", content: "website" });
+
+ const origin = `https://${data?.host}`;
+
+ if (site?.siteName) {
+ metas.push({
+ property: "og:site_name",
+ content: site.siteName,
+ });
+ metas.push({
+ "script:ld+json": {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: site.siteName,
+ url: origin,
+ },
+ });
+ }
+ if (page.meta.description) {
+ metas.push({
+ name: "description",
+ content: page.meta.description,
+ });
metas.push({
- name,
- content: value,
+ property: "og:description",
+ content: page.meta.description,
});
}
+ if (page.meta.socialImageAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === page.meta.socialImageAssetId
+ );
+
+ if (imageAsset) {
+ metas.push({
+ property: "og:image",
+ content: `https://${data?.host}${imageLoader({
+ src: imageAsset.name,
+ // Do not transform social image (not enough information do we need to do this)
+ format: "raw",
+ })}`,
+ });
+ }
+ }
+
return metas;
};
@@ -57,6 +132,39 @@ export const links: LinksFunction = () => {
href: css,
});
+ const { site } = pageData;
+
+ if (site?.faviconAssetId) {
+ const imageAsset = imageAssets.find(
+ (asset) => asset.id === site.faviconAssetId
+ );
+
+ if (imageAsset) {
+ result.push({
+ rel: "icon",
+ href: imageLoader({
+ src: imageAsset.name,
+ width: 128,
+ quality: 100,
+ format: "auto",
+ }),
+ type: undefined,
+ });
+ }
+ } else {
+ result.push({
+ rel: "icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+
+ result.push({
+ rel: "shortcut icon",
+ href: "/favicon.ico",
+ type: "image/x-icon",
+ });
+ }
+
for (const asset of fontAssets) {
if (asset.type === "font") {
result.push({
diff --git a/packages/cli/templates/vercel/app/constants.mjs b/packages/cli/templates/vercel/app/constants.mjs
index 5a92afbe55..c2280610cb 100644
--- a/packages/cli/templates/vercel/app/constants.mjs
+++ b/packages/cli/templates/vercel/app/constants.mjs
@@ -8,18 +8,22 @@ export const imageBaseUrl = "/assets/";
/**
* @type {import("@webstudio-is/image").ImageLoader}
*/
-export const imageLoader = ({ quality, src, width }) => {
+export const imageLoader = (props) => {
if (process.env.NODE_ENV !== "production") {
- return imageBaseUrl + src;
+ return imageBaseUrl + props.src;
+ }
+
+ if (props.format === "raw") {
+ return imageBaseUrl + props.src;
}
// https://vercel.com/blog/build-your-own-web-framework#automatic-image-optimization
return (
"/_vercel/image?url=" +
- encodeURIComponent(imageBaseUrl + src) +
+ encodeURIComponent(imageBaseUrl + props.src) +
"&w=" +
- width +
+ props.width +
"&q=" +
- quality
+ props.quality
);
};
diff --git a/packages/image/src/image-loaders.ts b/packages/image/src/image-loaders.ts
index 91db805498..ab0a3886f0 100644
--- a/packages/image/src/image-loaders.ts
+++ b/packages/image/src/image-loaders.ts
@@ -11,7 +11,11 @@ export type ImageLoaderOptions = {
**/
export const createImageLoader =
(loaderOptions: ImageLoaderOptions): ImageLoader =>
- ({ width, src, quality, format }) => {
+ (props) => {
+ const width = props.format === "raw" ? 16 : props.width;
+ const quality = props.format === "raw" ? 100 : props.quality;
+ const { format, src } = props;
+
if (process.env.NODE_ENV !== "production") {
warnOnce(
allSizes.includes(width) === false,
diff --git a/packages/image/src/image-optimize.test.ts b/packages/image/src/image-optimize.test.ts
index 33dc6289f7..37b03b5135 100644
--- a/packages/image/src/image-optimize.test.ts
+++ b/packages/image/src/image-optimize.test.ts
@@ -93,8 +93,10 @@ describe("Image optimizations applied", () => {
srcSet: undefined,
sizes: "100vw",
quality: 70,
- loader: ({ width, src, quality }) =>
- `${new URL(src).pathname}?w=${width}&q=${quality}`,
+ loader: (props) =>
+ `${new URL(props.src).pathname}?w=${
+ props.format !== "raw" ? props.width : 0
+ }&q=${props.format !== "raw" ? props.quality : 0}`,
});
expect(imgAttr).toMatchInlineSnapshot(`
diff --git a/packages/image/src/image-optimize.ts b/packages/image/src/image-optimize.ts
index b6d25a6979..fd004902af 100644
--- a/packages/image/src/image-optimize.ts
+++ b/packages/image/src/image-optimize.ts
@@ -85,12 +85,16 @@
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**/
-export type ImageLoader = (props: {
- width: number;
- quality: number;
- src: string;
- format?: "auto" | "raw";
-}) => string;
+export type ImageLoader = (
+ props:
+ | {
+ width: number;
+ quality: number;
+ src: string;
+ format?: "auto";
+ }
+ | { src: string; format: "raw" }
+) => string;
/**
* max(...imageSizes) must be less then min(...deviceSizes)
diff --git a/packages/react-sdk/src/app/root.tsx b/packages/react-sdk/src/app/root.tsx
index 984d5a1cfb..a6893de252 100644
--- a/packages/react-sdk/src/app/root.tsx
+++ b/packages/react-sdk/src/app/root.tsx
@@ -13,8 +13,6 @@ export const Root = ({
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
- <link rel="icon" href="/favicon.ico" type="image/x-icon" />
- <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<Meta />
<Links />
</head>
diff --git a/packages/sdk/src/schema/pages.ts b/packages/sdk/src/schema/pages.ts
index df3f16c975..052eda0a2a 100644
--- a/packages/sdk/src/schema/pages.ts
+++ b/packages/sdk/src/schema/pages.ts
@@ -73,18 +73,17 @@ const Page = z.object({
path: PagePath,
});
-const SiteMeta = z
- .object({
- siteName: z.string().optional(),
- faviconAssetId: z.string().optional(),
- code: z.string().optional(),
- })
- .default({});
+const SiteMeta = z.object({
+ siteName: z.string().optional(),
+ faviconAssetId: z.string().optional(),
+ code: z.string().optional(),
+});
+export type SiteMeta = z.infer<typeof SiteMeta>;
export type Page = z.infer<typeof Page>;
export const Pages = z.object({
- meta: SiteMeta,
+ meta: SiteMeta.optional(),
homePage: HomePage,
pages: z
.array(Page)