@cocreate/sitemap
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -0,1 +1,8 @@ | ||
## [1.2.3](https://github.com/CoCreate-app/CoCreate-sitemap/compare/v1.2.2...v1.2.3) (2024-09-08) | ||
### Bug Fixes | ||
* encodeValues for characters xml cant parse. Format date correctly ([e928405](https://github.com/CoCreate-app/CoCreate-sitemap/commit/e928405998d5f7492acdd1bb35c67f44c9bce4ad)) | ||
## [1.2.2](https://github.com/CoCreate-app/CoCreate-sitemap/compare/v1.2.1...v1.2.2) (2024-09-01) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@cocreate/sitemap", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "A simple sitemap component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -62,4 +62,3 @@ /******************************************************************************** | ||
// TODO: need to get info such as host | ||
const entry = this.createEntry(file); | ||
const entry = this.createEntry(file, host); | ||
@@ -105,3 +104,3 @@ let { mainSitemap, sitemap } = await this.getSitemap(file, host); | ||
if (file.sitemap.type !== 'news') { | ||
if (file.sitemap.changefreq) | ||
if (!file.sitemap.changefreq) | ||
file.sitemap.changefreq = 'monthly'; | ||
@@ -121,2 +120,3 @@ | ||
continue | ||
let value = file.sitemap[key]; | ||
@@ -127,2 +127,3 @@ | ||
value = [value] | ||
for (let i = 0; i < value.length; i++) { | ||
@@ -132,4 +133,3 @@ entry += `\t\t<${key}:${key}>\n`; | ||
for (const nestedKey of Object.keys(value[i])) { | ||
const nestedValue = value[i][nestedKey]; | ||
let nestedValue = value[i][nestedKey]; | ||
// Handle nested objects | ||
@@ -144,2 +144,12 @@ if (typeof nestedValue === 'object' && nestedValue !== null && !(nestedValue instanceof Date)) { | ||
} else { | ||
if (nestedKey === 'loc') { | ||
if (!nestedValue.startsWith('https://') && !nestedValue.startsWith('http://') && !nestedValue.startsWith('{{$host}}')) { | ||
nestedValue = `{{$host}}${nestedValue}`; | ||
} | ||
} else if (nestedKey === 'publication_date') { | ||
nestedValue = new Date(nestedValue).toISOString().split('.')[0] + "Z"; | ||
} else { | ||
nestedValue = this.encodeXML(nestedValue) | ||
} | ||
entry += `\t\t\t<${key}:${nestedKey}>${nestedValue}</${key}:${nestedKey}>\n`; | ||
@@ -152,2 +162,12 @@ } | ||
} else { | ||
if (key === 'loc') { | ||
if (!value.startsWith('https://') && !value.startsWith('http://')) { | ||
value = `{{$host}}${value}`; | ||
} | ||
} else if (key === 'lastmod') { | ||
value = new Date(file.modified.on).toISOString().split('.')[0] + "Z"; | ||
} else { | ||
value = this.encodeXML(value) | ||
} | ||
entry += `\t\t<${key}>${value}</${key}>\n`; | ||
@@ -450,4 +470,15 @@ } | ||
} | ||
encodeXML(str) { | ||
if (str) | ||
return str | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, '''); | ||
} | ||
} | ||
module.exports = CoCreateSitemap; |
83255
436