From 9276b3629d99a96293aac664690217da65ff3ee2 Mon Sep 17 00:00:00 2001 From: Kyle Gach Date: Mon, 30 Dec 2024 12:16:02 -0600 Subject: [PATCH 1/2] Error on empty sitemap data --- apps/frontpage/app/addons/sitemap.ts | 4 ++++ apps/frontpage/app/blog/sitemap.ts | 4 ++++ apps/frontpage/app/recipes/sitemap.ts | 4 ++++ apps/frontpage/app/releases/sitemap.ts | 4 ++++ apps/frontpage/app/showcase/sitemap.ts | 4 ++++ apps/frontpage/app/tutorials/sitemap.ts | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/apps/frontpage/app/addons/sitemap.ts b/apps/frontpage/app/addons/sitemap.ts index ebfdae57..c63c6851 100644 --- a/apps/frontpage/app/addons/sitemap.ts +++ b/apps/frontpage/app/addons/sitemap.ts @@ -104,6 +104,10 @@ export default async function sitemap(): Promise { const categories = await fetchTagsData({ isCategory: true }); const tags = await fetchTagsData(); + if (addons.length === 0 || categories.length === 0 || tags.length === 0) { + throw new Error('Failed to fetch addons data'); + } + const addonPaths = addons.map((name) => { if (!name) throw new Error('Addon name is missing'); return { loc: `https://storybook.js.org/addons/${name}` }; diff --git a/apps/frontpage/app/blog/sitemap.ts b/apps/frontpage/app/blog/sitemap.ts index fa1ce91b..a7f8b679 100644 --- a/apps/frontpage/app/blog/sitemap.ts +++ b/apps/frontpage/app/blog/sitemap.ts @@ -8,5 +8,9 @@ export default async function sitemap(): Promise { if (error) throw new Error(error); + if (sites.length === 0) { + throw new Error('Failed to fetch blog data'); + } + return sites; } diff --git a/apps/frontpage/app/recipes/sitemap.ts b/apps/frontpage/app/recipes/sitemap.ts index c4261488..3fce28f2 100644 --- a/apps/frontpage/app/recipes/sitemap.ts +++ b/apps/frontpage/app/recipes/sitemap.ts @@ -4,6 +4,10 @@ import { fetchRecipesData } from '../../lib/fetch-recipes-data'; export default async function sitemap(): Promise { const recipes = (await fetchRecipesData()) || []; + if (recipes.length === 0) { + throw new Error('Failed to fetch recipes data'); + } + return recipes.map((name) => ({ url: `https://storybook.js.org/recipes/${name}`, })); diff --git a/apps/frontpage/app/releases/sitemap.ts b/apps/frontpage/app/releases/sitemap.ts index 4544830b..3f527e1d 100644 --- a/apps/frontpage/app/releases/sitemap.ts +++ b/apps/frontpage/app/releases/sitemap.ts @@ -4,6 +4,10 @@ import { getReleases } from '../../lib/get-releases'; export default function sitemap(): MetadataRoute.Sitemap { const releases = getReleases(); + if (releases.length === 0) { + throw new Error('Failed to fetch releases data'); + } + return releases.map((name) => ({ url: `https://storybook.js.org/releases/${name}`, })); diff --git a/apps/frontpage/app/showcase/sitemap.ts b/apps/frontpage/app/showcase/sitemap.ts index 6752f32b..caa051e3 100644 --- a/apps/frontpage/app/showcase/sitemap.ts +++ b/apps/frontpage/app/showcase/sitemap.ts @@ -8,5 +8,9 @@ export default async function sitemap(): Promise { if (error) throw new Error(error); + if (sites.length === 0) { + throw new Error('Failed to fetch showcase data'); + } + return sites; } diff --git a/apps/frontpage/app/tutorials/sitemap.ts b/apps/frontpage/app/tutorials/sitemap.ts index a7a10ad8..fcb2c58f 100644 --- a/apps/frontpage/app/tutorials/sitemap.ts +++ b/apps/frontpage/app/tutorials/sitemap.ts @@ -8,5 +8,9 @@ export default async function sitemap(): Promise { if (error) throw new Error(error); + if (sites.length === 0) { + throw new Error('Failed to fetch tutorials data'); + } + return sites; } From 977344cd63c85832a25fb65da8d5643cc52b1bb8 Mon Sep 17 00:00:00 2001 From: Kyle Gach Date: Mon, 30 Dec 2024 12:36:50 -0600 Subject: [PATCH 2/2] Simplify sitemap.xml redirects --- apps/frontpage/public/netlify.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/frontpage/public/netlify.toml b/apps/frontpage/public/netlify.toml index 3a537b35..f8f41a68 100644 --- a/apps/frontpage/public/netlify.toml +++ b/apps/frontpage/public/netlify.toml @@ -5,7 +5,7 @@ [[redirects]] from = "/addons/sitemap.xml" - to = "https://storybook-frontpage.netlify.app/addons/sitemap.xml" + to = "/addons/sitemap.xml" status = 200 [[redirects]] @@ -15,7 +15,7 @@ [[redirects]] from = "/blog/sitemap.xml" - to = "https://storybook-frontpage.netlify.app/blog/sitemap.xml" + to = "/blog/sitemap.xml" status = 200 [[redirects]] @@ -30,7 +30,7 @@ [[redirects]] from = "/showcase/sitemap.xml" - to = "https://storybook-frontpage.netlify.app/showcase/sitemap.xml" + to = "/showcase/sitemap.xml" status = 200 [[redirects]] @@ -40,7 +40,7 @@ [[redirects]] from = "/tutorials/sitemap.xml" - to = "https://storybook-frontpage.netlify.app/tutorials/sitemap.xml" + to = "/tutorials/sitemap.xml" status = 200 [[redirects]]