create-sitecore-jss 22.6.0-canary.25 → 22.6.0-canary.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
2
|
import { NativeDataFetcher, GraphQLSitemapXmlService } from '@sitecore-jss/sitecore-jss-nextjs';
|
|
3
3
|
import { siteResolver } from 'lib/site-resolver';
|
|
4
|
-
import config from 'temp/config';
|
|
5
4
|
import clientFactory from 'lib/graphql-client-factory';
|
|
6
5
|
|
|
7
|
-
const ABSOLUTE_URL_REGEXP = '^(?:[a-z]+:)?//';
|
|
8
|
-
|
|
9
6
|
const sitemapApi = async (
|
|
10
7
|
req: NextApiRequest,
|
|
11
8
|
res: NextApiResponse
|
|
@@ -30,13 +27,9 @@ const sitemapApi = async (
|
|
|
30
27
|
|
|
31
28
|
// regular sitemap
|
|
32
29
|
if (sitemapPath) {
|
|
33
|
-
const isAbsoluteUrl = sitemapPath.match(ABSOLUTE_URL_REGEXP);
|
|
34
|
-
const sitemapUrl = isAbsoluteUrl ? sitemapPath : `${config.sitecoreApiHost}${sitemapPath}`;
|
|
35
|
-
res.setHeader('Content-Type', 'text/xml;charset=utf-8');
|
|
36
|
-
|
|
37
30
|
try {
|
|
38
31
|
const fetcher = new NativeDataFetcher();
|
|
39
|
-
const xmlResponse = await fetcher.fetch<string>(
|
|
32
|
+
const xmlResponse = await fetcher.fetch<string>(sitemapPath);
|
|
40
33
|
|
|
41
34
|
return res.send(xmlResponse.data);
|
|
42
35
|
} catch (error) {
|
|
@@ -51,22 +44,23 @@ const sitemapApi = async (
|
|
|
51
44
|
return res.redirect('/404');
|
|
52
45
|
}
|
|
53
46
|
|
|
54
|
-
const
|
|
47
|
+
const reqHost = req.headers.host;
|
|
55
48
|
const reqProtocol = req.headers['x-forwarded-proto'] || 'https';
|
|
56
49
|
const SitemapLinks = sitemaps
|
|
57
50
|
.map((item: string) => {
|
|
58
51
|
const parseUrl = item.split('/');
|
|
59
52
|
const lastSegment = parseUrl[parseUrl.length - 1];
|
|
53
|
+
const escapedUrl = `${reqProtocol}://${reqHost}/${lastSegment}`.replace(/&/g, '&');
|
|
60
54
|
|
|
61
55
|
return `<sitemap>
|
|
62
|
-
<loc>${
|
|
56
|
+
<loc>${escapedUrl}</loc>
|
|
63
57
|
</sitemap>`;
|
|
64
58
|
})
|
|
65
59
|
.join('');
|
|
66
60
|
|
|
67
61
|
res.setHeader('Content-Type', 'text/xml;charset=utf-8');
|
|
68
62
|
|
|
69
|
-
return res.send(
|
|
63
|
+
return res.send(`<?xml version="1.0" encoding="UTF-8"?>
|
|
70
64
|
<sitemapindex xmlns="http://sitemaps.org/schemas/sitemap/0.9" encoding="UTF-8">${SitemapLinks}</sitemapindex>
|
|
71
65
|
`);
|
|
72
66
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-sitecore-jss",
|
|
3
|
-
"version": "22.6.0-canary.
|
|
3
|
+
"version": "22.6.0-canary.26",
|
|
4
4
|
"description": "Sitecore JSS initializer",
|
|
5
5
|
"bin": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"ts-node": "^10.9.1",
|
|
66
66
|
"typescript": "~5.6.3"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "829976f7fa59e56cf6f02bd8b39af76ccb13924c"
|
|
69
69
|
}
|