File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ export default hydrogenRoutes([
2020 ) ,
2121 route ( "sitemap.xml" , "routes/seo/sitemap.ts" ) ,
2222 route ( "sitemap/:type/:page.xml" , "routes/seo/sitemap-page.ts" ) ,
23+ route ( "sitemap-weaverse.xml" , "routes/seo/sitemap-weaverse.xml.ts" ) ,
2324 route ( "pages/:pageHandle" , "routes/pages/regular-page.tsx" ) ,
2425 route ( "discount/:code" , "routes/others/discount-code.tsx" ) ,
2526 ...prefix ( "api" , [
Original file line number Diff line number Diff line change 1+ import type { LoaderFunctionArgs } from "react-router" ;
2+
3+ function escapeXml ( str : string ) : string {
4+ return str
5+ . replace ( / & / g, "&" )
6+ . replace ( / < / g, "<" )
7+ . replace ( / > / g, ">" )
8+ . replace ( / " / g, """ )
9+ . replace ( / ' / g, "'" ) ;
10+ }
11+
12+ export async function loader ( { request, context } : LoaderFunctionArgs ) {
13+ const { weaverse } = context as any ;
14+ const url = new URL ( request . url ) ;
15+ const baseUrl = `${ url . protocol } //${ url . host } ` ;
16+
17+ const entries = await weaverse . fetchCustomPages ( ) ;
18+
19+ const urls = entries . map ( ( entry ) => {
20+ const loc = escapeXml ( `${ baseUrl } ${ entry . path } ` ) ;
21+ return ` <url>
22+ <loc>${ loc } </loc>
23+ <lastmod>${ escapeXml ( entry . lastModified ) } </lastmod>
24+ <changefreq>${ entry . changeFrequency || "weekly" } </changefreq>
25+ <priority>${ entry . priority ?? 0.7 } </priority>
26+ </url>` ;
27+ } ) ;
28+
29+ const xml = `<?xml version="1.0" encoding="UTF-8"?>
30+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
31+ ${ urls . join ( "\n" ) }
32+ </urlset>` ;
33+
34+ return new Response ( xml , {
35+ headers : {
36+ "Content-Type" : "application/xml" ,
37+ "Cache-Control" : `max-age=${ 60 * 60 * 24 } ` ,
38+ } ,
39+ } ) ;
40+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,21 @@ export async function loader({
1010 request,
1111 } ) ;
1212
13- response . headers . set ( "Cache-Control" , `max-age=${ 60 * 60 * 24 } ` ) ;
14- return response ;
13+ // Add Weaverse custom pages sitemap to the index
14+ const sitemapXml = await response . text ( ) ;
15+ const url = new URL ( request . url ) ;
16+ const weaverseSitemapUrl = `${ url . protocol } //${ url . host } /sitemap-weaverse.xml` ;
17+
18+ // Insert Weaverse sitemap before closing sitemapindex tag
19+ const modifiedXml = sitemapXml . replace (
20+ "</sitemapindex>" ,
21+ ` <sitemap>\n <loc>${ weaverseSitemapUrl } </loc>\n </sitemap>\n</sitemapindex>`
22+ ) ;
23+
24+ return new Response ( modifiedXml , {
25+ headers : {
26+ "Content-Type" : "application/xml" ,
27+ "Cache-Control" : `max-age=${ 60 * 60 * 24 } ` ,
28+ } ,
29+ } ) ;
1530}
Original file line number Diff line number Diff line change 6464 "@shopify/hydrogen" : " ^2026.4.1" ,
6565 "@shopify/hydrogen-react" : " ^2026.4.1" ,
6666 "@tailwindcss/vite" : " ^4.2.2" ,
67- "@weaverse/hydrogen" : " ^5.12 .0" ,
67+ "@weaverse/hydrogen" : " ^5.13 .0" ,
6868 "class-variance-authority" : " 0.7.1" ,
6969 "clsx" : " 2.1.1" ,
7070 "colord" : " 2.9.3" ,
You can’t perform that action at this time.
0 commit comments