Skip to content

Commit

Permalink
Fix sitemap example by using sitemapindex elements (#2460)
Browse files Browse the repository at this point in the history
  • Loading branch information
blittle authored Aug 23, 2024
1 parent 1b217cd commit 0933f81
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions examples/sitemap/app/lib/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {
LanguageCode,
} from '@shopify/hydrogen/storefront-api-types';

const SITEMAP_INDEX_PREFIX = `<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">`;
const SITEMAP_INDEX_SUFFIX = `</sitemapindex>`;

const SITEMAP_PREFIX = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">`;
const SITEMAP_SUFFIX = `</urlset>`;
Expand Down Expand Up @@ -43,7 +47,7 @@ export async function getSitemapIndex({
const baseUrl = new URL(request.url).origin;

const body =
SITEMAP_PREFIX +
SITEMAP_INDEX_PREFIX +
types
.map((type) =>
getSiteMapLinks(type, data[type].pagesCount.count, baseUrl),
Expand All @@ -52,7 +56,7 @@ export async function getSitemapIndex({
customUrls
.map((url) => '<sitemap><loc>' + url + '</loc></sitemap>')
.join('\n') +
SITEMAP_SUFFIX;
SITEMAP_INDEX_SUFFIX;

return new Response(body, {
headers: {
Expand Down

0 comments on commit 0933f81

Please sign in to comment.