diff --git a/packages/easy-sitemap/src/Sitemap.ts b/packages/easy-sitemap/src/Sitemap.ts index 7d20490..c44f3ae 100644 --- a/packages/easy-sitemap/src/Sitemap.ts +++ b/packages/easy-sitemap/src/Sitemap.ts @@ -36,12 +36,7 @@ export default class Sitemap { }) { let entryString = '' - const url = `${this.domain}${path}` - .replace(/&/g, '&') - .replace(/'/g, ''') - .replace(/"/g, '"') - .replace(/>/g, '>') - .replace(/${url}` if (options) { @@ -53,7 +48,7 @@ export default class Sitemap { } } if (options.lastmod) { - entryString += `${options.lastmod.toISOString()}` + entryString += `${this.fixText(options.lastmod.toISOString())}` } if (options.priority) { if (options.priority <= 1 && options.priority >= 0 && options.priority.toString().length <= 3) { @@ -72,11 +67,11 @@ export default class Sitemap { continue } entryString += '' - entryString += `${image.location.startsWith('/') ? `${this.domain}${image.location}` : image.location}` - entryString += this.optionalEntry('image:caption', image.caption) - entryString += this.optionalEntry('image:geo_location', image.geoLocation) - entryString += this.optionalEntry('image:title', image.title) - entryString += this.optionalEntry('image:license', image.license) + entryString += `${this.fixText(image.location.startsWith('/') ? `${this.domain}${image.location}` : image.location)}` + entryString += this.fixText(this.optionalEntry('image:caption', image.caption)) + entryString += this.fixText(this.optionalEntry('image:geo_location', image.geoLocation)) + entryString += this.fixText(this.optionalEntry('image:title', image.title)) + entryString += this.fixText(this.optionalEntry('image:license', image.license)) entryString += '' } } @@ -105,4 +100,12 @@ export default class Sitemap { private optionalEntry(tag: string, entry?: string) { return entry ? `<${tag}>${entry}` : '' } + + private fixText(txt: string): string { + return txt.replace(/&/g, '&') + .replace(/'/g, ''') + .replace(/"/g, '"') + .replace(/>/g, '>') + .replace(/