-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e268d3e
commit ae21836
Showing
2 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { MetadataRoute } from 'next'; | ||
import { fetchAddonsQuery, gql } from '../../lib/fetch-addons-query'; | ||
import { validateResponse } from '@repo/utils'; | ||
|
||
type AddonValue = string; | ||
|
||
interface AddonsData { | ||
addons: { name: string }[]; | ||
} | ||
|
||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> { | ||
/** | ||
* TODO: Move this to a shared location, @repo/utils? | ||
* Canonical source: apps/addon-catalog/lib/fetch-addons-data.ts | ||
*/ | ||
async function fetchAddonsData() { | ||
try { | ||
let value: AddonValue[] = []; | ||
async function fetchPartialData(skip: number = 0) { | ||
const data = await fetchAddonsQuery<AddonsData, { skip: number }>( | ||
gql` | ||
query Addons($skip: Int!) { | ||
addons(limit: 30, skip: $skip) { | ||
name | ||
} | ||
} | ||
`, | ||
{ | ||
variables: { skip }, | ||
}, | ||
); | ||
|
||
validateResponse(() => data.addons); | ||
|
||
const { addons } = data; | ||
|
||
value = [...value, ...addons.map(({ name }) => name)]; | ||
|
||
if (addons.length > 0) await fetchPartialData(skip + addons.length); | ||
|
||
return value; | ||
} | ||
|
||
return await fetchPartialData(); | ||
} catch (error) { | ||
// @ts-expect-error - Seems safe | ||
throw new Error(`Failed to fetch addons data: ${error.message}`); | ||
} | ||
} | ||
|
||
type TagValue = string; | ||
|
||
interface TagsData { | ||
tags: { name: string }[]; | ||
} | ||
|
||
/** | ||
* TODO: Move this to a shared location, @repo/utils? | ||
* Canonical source: apps/addon-catalog/lib/fetch-tags-data.ts | ||
*/ | ||
async function fetchTagsData({ | ||
isCategory, | ||
}: { | ||
isCategory?: boolean; | ||
} = {}) { | ||
try { | ||
let value: TagValue[] = []; | ||
async function fetchPartialData(skip: number = 0) { | ||
const data = await fetchAddonsQuery< | ||
TagsData, | ||
{ isCategory: boolean; skip: number } | ||
>( | ||
gql` | ||
query TagNames($isCategory: Boolean!, $skip: Int!) { | ||
tags(isCategory: $isCategory, limit: 30, skip: $skip) { | ||
name | ||
} | ||
} | ||
`, | ||
{ | ||
variables: { isCategory: Boolean(isCategory), skip }, | ||
}, | ||
); | ||
|
||
validateResponse(() => data?.tags); | ||
|
||
const { tags } = data; | ||
|
||
value = [...value, ...tags.map(({ name }) => name)]; | ||
|
||
if (tags.length > 0) await fetchPartialData(skip + tags.length); | ||
|
||
return value; | ||
} | ||
|
||
return await fetchPartialData(); | ||
} catch (error) { | ||
// @ts-expect-error - Seems safe | ||
throw new Error(`Failed to fetch addons data: ${error.message}`); | ||
} | ||
} | ||
|
||
return []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
<sitemap> | ||
<loc>https://storybook.js.org/sitemap/docs/sitemap.xml</loc> | ||
<loc>https://storybook.js.org/docs/sitemap.xml</loc> | ||
</sitemap> | ||
<sitemap> | ||
<loc>https://storybook.js.org/sitemap/addons/sitemap.xml</loc> | ||
<loc>https://storybook.js.org/addons/sitemap.xml</loc> | ||
</sitemap> | ||
<sitemap> | ||
<loc>https://storybook.js.org/sitemap/recipes/sitemap.xml</loc> | ||
<loc>https://storybook.js.org/recipes/sitemap.xml</loc> | ||
</sitemap> | ||
<sitemap> | ||
<loc>https://storybook.js.org/sitemap/blog/sitemap.xml</loc> | ||
<loc>https://storybook.js.org/blog/sitemap.xml</loc> | ||
</sitemap> | ||
<sitemap> | ||
<loc>https://storybook.js.org/sitemap/showcase/sitemap.xml</loc> | ||
<loc>https://storybook.js.org/showcase/sitemap.xml</loc> | ||
</sitemap> | ||
<sitemap> | ||
<loc>https://storybook.js.org/sitemap/tutorials/sitemap.xml</loc> | ||
<loc>https://storybook.js.org/tutorials/sitemap.xml</loc> | ||
</sitemap> | ||
</sitemapindex> |