From 54360f9eaa744fe81bf97da2ca63f5dccfa965cb Mon Sep 17 00:00:00 2001
From: Vishnu Sankar <4602725+iamvishnusankar@users.noreply.github.com>
Date: Mon, 17 Oct 2022 19:08:11 +0530
Subject: [PATCH 1/2] [Fix] Sitemap fails when adding alternate refs.
Fix: #479
---
examples/i18n/next-sitemap.config.js | 10 ++++++++++
packages/next-sitemap/src/builders/sitemap-builder.ts | 4 ++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/examples/i18n/next-sitemap.config.js b/examples/i18n/next-sitemap.config.js
index f13e29cf..af2c1641 100644
--- a/examples/i18n/next-sitemap.config.js
+++ b/examples/i18n/next-sitemap.config.js
@@ -10,6 +10,16 @@ const config = {
'https://example.com/my-custom-sitemap-3.xml',
],
},
+ alternateRefs: [
+ {
+ href: 'https://es.example.com',
+ hreflang: 'es',
+ },
+ {
+ href: 'https://fr.example.com',
+ hreflang: 'fr',
+ },
+ ],
}
export default config
diff --git a/packages/next-sitemap/src/builders/sitemap-builder.ts b/packages/next-sitemap/src/builders/sitemap-builder.ts
index fb253930..cc01be7c 100644
--- a/packages/next-sitemap/src/builders/sitemap-builder.ts
+++ b/packages/next-sitemap/src/builders/sitemap-builder.ts
@@ -11,7 +11,7 @@ export class SitemapBuilder {
* @returns
*/
withXMLTemplate(content: string): string {
- return `\n\n${content}`
+ return `\n\n${content}`
}
/**
@@ -22,7 +22,7 @@ export class SitemapBuilder {
buildSitemapIndexXml(allSitemaps: string[]) {
return [
'',
- '',
+ '',
...(allSitemaps?.map((x) => `${x}`) ?? []),
'',
].join('\n')
From 4f87ba7afebeb1f0e422f216a97ee678e21683d6 Mon Sep 17 00:00:00 2001
From: Vishnu Sankar <4602725+iamvishnusankar@users.noreply.github.com>
Date: Mon, 17 Oct 2022 19:34:35 +0530
Subject: [PATCH 2/2] Fix snapshot test
---
.../__tests__/sitemap-builder/build-sitemap-xml.test.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/next-sitemap/src/builders/__tests__/sitemap-builder/build-sitemap-xml.test.ts b/packages/next-sitemap/src/builders/__tests__/sitemap-builder/build-sitemap-xml.test.ts
index 876aae25..31673e1a 100644
--- a/packages/next-sitemap/src/builders/__tests__/sitemap-builder/build-sitemap-xml.test.ts
+++ b/packages/next-sitemap/src/builders/__tests__/sitemap-builder/build-sitemap-xml.test.ts
@@ -30,7 +30,7 @@ describe('SitemapBuilder', () => {
// Expect the generated sitemap to match snapshot.
expect(content).toMatchInlineSnapshot(`
"
-
+
https://example.com
https://example.comsome-value
"