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.

feat: Add sitemap generation (#2566)

Ivan Starkovc620f1ecba7a
diff --git a/fixtures/webstudio-custom-template/.webstudio/data.json b/fixtures/webstudio-custom-template/.webstudio/data.json
index c0938da7b1..174a93672a 100644
--- a/fixtures/webstudio-custom-template/.webstudio/data.json
+++ b/fixtures/webstudio-custom-template/.webstudio/data.json
@@ -4,6 +4,7 @@
"projectId": "0d856812-61d8-4014-a20a-82e01c0eb8ee",
"version": 17,
"createdAt": "2023-11-03T11:20:29.565Z",
+ "updatedAt": "2023-11-03T11:20:29.565Z",
"pages": {
"meta": {
"siteName": "Fixture Site",
diff --git a/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml].ts b/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml].ts
index 419fc83e31..a477c535e4 100644
--- a/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml].ts
+++ b/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml].ts
@@ -2,6 +2,7 @@ export const sitemap = {
pages: [
{
path: "",
+ lastModified: "2023-11-03T11:20:29.565Z",
},
],
};
diff --git a/fixtures/webstudio-custom-template/app/routes/[robots.txt].tsx b/fixtures/webstudio-custom-template/app/routes/[robots.txt].tsx
index 1b8d531fd6..a2be4a2ad3 100644
--- a/fixtures/webstudio-custom-template/app/routes/[robots.txt].tsx
+++ b/fixtures/webstudio-custom-template/app/routes/[robots.txt].tsx
@@ -11,8 +11,7 @@ export const loader = (arg: LoaderArgs) => {
User-agent: *
Disallow: /api/
-# Uncomment
-# Sitemap: https://${host}/sitemap.xml
+Sitemap: https://${host}/sitemap.xml
`,
{
diff --git a/fixtures/webstudio-custom-template/app/routes/[sitemap.xml].tsx b/fixtures/webstudio-custom-template/app/routes/[sitemap.xml].tsx
index 43782d0c18..bf4846a0d3 100644
--- a/fixtures/webstudio-custom-template/app/routes/[sitemap.xml].tsx
+++ b/fixtures/webstudio-custom-template/app/routes/[sitemap.xml].tsx
@@ -1,4 +1,5 @@
import type { LoaderArgs } from "@remix-run/server-runtime";
+import { sitemap } from "../__generated__/[sitemap.xml]";
export const loader = (arg: LoaderArgs) => {
const host =
@@ -6,13 +7,21 @@ export const loader = (arg: LoaderArgs) => {
arg.request.headers.get("host") ||
"";
+ const urls = sitemap.pages.map((page) => {
+ const url = new URL(`https://${host}${page.path}`);
+
+ return `
+ <url>
+ <loc>${url.href}</loc>
+ <lastmod>${page.lastModified.split("T")[0]}</lastmod>
+ </url>
+ `;
+ });
+
return new Response(
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
- <url>
- <loc>https://${host}/</loc>
- <lastmod>2023-11-05</lastmod>
- </url>
+${urls.join("")}
</urlset>
`,
{
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json b/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json
index 40584d7f66..f5ee04df15 100644
--- a/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json
+++ b/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json
@@ -4,6 +4,7 @@
"projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",
"version": 18,
"createdAt": "2023-09-23T09:29:28.107Z",
+ "updatedAt": "2023-09-23T09:29:28.107Z",
"pages": {
"homePage": {
"id": "9di_L14CzctvSruIoKVvE",
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[sitemap.xml].ts b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[sitemap.xml].ts
index 419fc83e31..91e4065385 100644
--- a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[sitemap.xml].ts
+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[sitemap.xml].ts
@@ -2,6 +2,7 @@ export const sitemap = {
pages: [
{
path: "",
+ lastModified: "2023-09-23T09:29:28.107Z",
},
],
};
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[robots.txt].tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[robots.txt].tsx
index 1b8d531fd6..a2be4a2ad3 100644
--- a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[robots.txt].tsx
+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[robots.txt].tsx
@@ -11,8 +11,7 @@ export const loader = (arg: LoaderArgs) => {
User-agent: *
Disallow: /api/
-# Uncomment
-# Sitemap: https://${host}/sitemap.xml
+Sitemap: https://${host}/sitemap.xml
`,
{
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[sitemap.xml].tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[sitemap.xml].tsx
index 43782d0c18..bf4846a0d3 100644
--- a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[sitemap.xml].tsx
+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[sitemap.xml].tsx
@@ -1,4 +1,5 @@
import type { LoaderArgs } from "@remix-run/server-runtime";
+import { sitemap } from "../__generated__/[sitemap.xml]";
export const loader = (arg: LoaderArgs) => {
const host =
@@ -6,13 +7,21 @@ export const loader = (arg: LoaderArgs) => {
arg.request.headers.get("host") ||
"";
+ const urls = sitemap.pages.map((page) => {
+ const url = new URL(`https://${host}${page.path}`);
+
+ return `
+ <url>
+ <loc>${url.href}</loc>
+ <lastmod>${page.lastModified.split("T")[0]}</lastmod>
+ </url>
+ `;
+ });
+
return new Response(
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
- <url>
- <loc>https://${host}/</loc>
- <lastmod>2023-11-05</lastmod>
- </url>
+${urls.join("")}
</urlset>
`,
{
diff --git a/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json b/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json
index 40584d7f66..f5ee04df15 100644
--- a/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json
+++ b/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json
@@ -4,6 +4,7 @@
"projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",
"version": 18,
"createdAt": "2023-09-23T09:29:28.107Z",
+ "updatedAt": "2023-09-23T09:29:28.107Z",
"pages": {
"homePage": {
"id": "9di_L14CzctvSruIoKVvE",
diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/[sitemap.xml].ts b/fixtures/webstudio-remix-netlify-functions/app/__generated__/[sitemap.xml].ts
index 419fc83e31..91e4065385 100644
--- a/fixtures/webstudio-remix-netlify-functions/app/__generated__/[sitemap.xml].ts
+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/[sitemap.xml].ts
@@ -2,6 +2,7 @@ export const sitemap = {
pages: [
{
path: "",
+ lastModified: "2023-09-23T09:29:28.107Z",
},
],
};
diff --git a/fixtures/webstudio-remix-netlify-functions/app/routes/[robots.txt].tsx b/fixtures/webstudio-remix-netlify-functions/app/routes/[robots.txt].tsx
index 1b8d531fd6..a2be4a2ad3 100644
--- a/fixtures/webstudio-remix-netlify-functions/app/routes/[robots.txt].tsx
+++ b/fixtures/webstudio-remix-netlify-functions/app/routes/[robots.txt].tsx
@@ -11,8 +11,7 @@ export const loader = (arg: LoaderArgs) => {
User-agent: *
Disallow: /api/
-# Uncomment
-# Sitemap: https://${host}/sitemap.xml
+Sitemap: https://${host}/sitemap.xml
`,
{
diff --git a/fixtures/webstudio-remix-netlify-functions/app/routes/[sitemap.xml].tsx b/fixtures/webstudio-remix-netlify-functions/app/routes/[sitemap.xml].tsx
index 43782d0c18..bf4846a0d3 100644
--- a/fixtures/webstudio-remix-netlify-functions/app/routes/[sitemap.xml].tsx
+++ b/fixtures/webstudio-remix-netlify-functions/app/routes/[sitemap.xml].tsx
@@ -1,4 +1,5 @@
import type { LoaderArgs } from "@remix-run/server-runtime";
+import { sitemap } from "../__generated__/[sitemap.xml]";
export const loader = (arg: LoaderArgs) => {
const host =
@@ -6,13 +7,21 @@ export const loader = (arg: LoaderArgs) => {
arg.request.headers.get("host") ||
"";
+ const urls = sitemap.pages.map((page) => {
+ const url = new URL(`https://${host}${page.path}`);
+
+ return `
+ <url>
+ <loc>${url.href}</loc>
+ <lastmod>${page.lastModified.split("T")[0]}</lastmod>
+ </url>
+ `;
+ });
+
return new Response(
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
- <url>
- <loc>https://${host}/</loc>
- <lastmod>2023-11-05</lastmod>
- </url>
+${urls.join("")}
</urlset>
`,
{
diff --git a/fixtures/webstudio-remix-vercel/.webstudio/data.json b/fixtures/webstudio-remix-vercel/.webstudio/data.json
index a1cfeb7901..dc0f74679e 100644
--- a/fixtures/webstudio-remix-vercel/.webstudio/data.json
+++ b/fixtures/webstudio-remix-vercel/.webstudio/data.json
@@ -4,6 +4,7 @@
"projectId": "cddc1d44-af37-4cb6-a430-d300cf6f932d",
"version": 222,
"createdAt": "2023-11-03T13:22:34.879Z",
+ "updatedAt": "2023-11-03T13:22:34.879Z",
"pages": {
"meta": {
"siteName": "KittyGuardedZone",
diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[sitemap.xml].ts b/fixtures/webstudio-remix-vercel/app/__generated__/[sitemap.xml].ts
index 378018b587..1e2aae4c79 100644
--- a/fixtures/webstudio-remix-vercel/app/__generated__/[sitemap.xml].ts
+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[sitemap.xml].ts
@@ -2,18 +2,23 @@ export const sitemap = {
pages: [
{
path: "",
+ lastModified: "2023-11-03T13:22:34.879Z",
},
{
path: "/radix",
+ lastModified: "2023-11-03T13:22:34.879Z",
},
{
path: "/_route_with_symbols_",
+ lastModified: "2023-11-03T13:22:34.879Z",
},
{
path: "/form",
+ lastModified: "2023-11-03T13:22:34.879Z",
},
{
path: "/heading-with-id",
+ lastModified: "2023-11-03T13:22:34.879Z",
},
],
};
diff --git a/fixtures/webstudio-remix-vercel/app/routes/[robots.txt].tsx b/fixtures/webstudio-remix-vercel/app/routes/[robots.txt].tsx
index 1b8d531fd6..a2be4a2ad3 100644
--- a/fixtures/webstudio-remix-vercel/app/routes/[robots.txt].tsx
+++ b/fixtures/webstudio-remix-vercel/app/routes/[robots.txt].tsx
@@ -11,8 +11,7 @@ export const loader = (arg: LoaderArgs) => {
User-agent: *
Disallow: /api/
-# Uncomment
-# Sitemap: https://${host}/sitemap.xml
+Sitemap: https://${host}/sitemap.xml
`,
{
diff --git a/fixtures/webstudio-remix-vercel/app/routes/[sitemap.xml].tsx b/fixtures/webstudio-remix-vercel/app/routes/[sitemap.xml].tsx
index 43782d0c18..bf4846a0d3 100644
--- a/fixtures/webstudio-remix-vercel/app/routes/[sitemap.xml].tsx
+++ b/fixtures/webstudio-remix-vercel/app/routes/[sitemap.xml].tsx
@@ -1,4 +1,5 @@
import type { LoaderArgs } from "@remix-run/server-runtime";
+import { sitemap } from "../__generated__/[sitemap.xml]";
export const loader = (arg: LoaderArgs) => {
const host =
@@ -6,13 +7,21 @@ export const loader = (arg: LoaderArgs) => {
arg.request.headers.get("host") ||
"";
+ const urls = sitemap.pages.map((page) => {
+ const url = new URL(`https://${host}${page.path}`);
+
+ return `
+ <url>
+ <loc>${url.href}</loc>
+ <lastmod>${page.lastModified.split("T")[0]}</lastmod>
+ </url>
+ `;
+ });
+
return new Response(
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
- <url>
- <loc>https://${host}/</loc>
- <lastmod>2023-11-05</lastmod>
- </url>
+${urls.join("")}
</urlset>
`,
{
diff --git a/packages/cli/templates/defaults/app/__generated__/[sitemap.xml].ts b/packages/cli/templates/defaults/app/__generated__/[sitemap.xml].ts
index cd4c7ff537..4477d9bc85 100644
--- a/packages/cli/templates/defaults/app/__generated__/[sitemap.xml].ts
+++ b/packages/cli/templates/defaults/app/__generated__/[sitemap.xml].ts
@@ -1,4 +1,11 @@
/**
* The only intent of this file is to support typings inside ../routes/[sitemap.xml].tsx for easier development.
**/
-export const sitemap = {};
+export const sitemap = {
+ pages: [
+ {
+ path: "",
+ lastModified: "2021-10-13T12:00:00.000Z",
+ },
+ ],
+};
diff --git a/packages/cli/templates/defaults/app/routes/[robots.txt].tsx b/packages/cli/templates/defaults/app/routes/[robots.txt].tsx
index 1b8d531fd6..a2be4a2ad3 100644
--- a/packages/cli/templates/defaults/app/routes/[robots.txt].tsx
+++ b/packages/cli/templates/defaults/app/routes/[robots.txt].tsx
@@ -11,8 +11,7 @@ export const loader = (arg: LoaderArgs) => {
User-agent: *
Disallow: /api/
-# Uncomment
-# Sitemap: https://${host}/sitemap.xml
+Sitemap: https://${host}/sitemap.xml
`,
{
diff --git a/packages/cli/templates/defaults/app/routes/[sitemap.xml].tsx b/packages/cli/templates/defaults/app/routes/[sitemap.xml].tsx
index 43782d0c18..bf4846a0d3 100644
--- a/packages/cli/templates/defaults/app/routes/[sitemap.xml].tsx
+++ b/packages/cli/templates/defaults/app/routes/[sitemap.xml].tsx
@@ -1,4 +1,5 @@
import type { LoaderArgs } from "@remix-run/server-runtime";
+import { sitemap } from "../__generated__/[sitemap.xml]";
export const loader = (arg: LoaderArgs) => {
const host =
@@ -6,13 +7,21 @@ export const loader = (arg: LoaderArgs) => {
arg.request.headers.get("host") ||
"";
+ const urls = sitemap.pages.map((page) => {
+ const url = new URL(`https://${host}${page.path}`);
+
+ return `
+ <url>
+ <loc>${url.href}</loc>
+ <lastmod>${page.lastModified.split("T")[0]}</lastmod>
+ </url>
+ `;
+ });
+
return new Response(
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
- <url>
- <loc>https://${host}/</loc>
- <lastmod>2023-11-05</lastmod>
- </url>
+${urls.join("")}
</urlset>
`,
{