@cocreate/sitemap
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -0,1 +1,8 @@ | ||
## [1.2.1](https://github.com/CoCreate-app/CoCreate-sitemap/compare/v1.2.0...v1.2.1) (2024-09-01) | ||
### Bug Fixes | ||
* return if no title, parse sub object in createEntry ([97d8751](https://github.com/CoCreate-app/CoCreate-sitemap/commit/97d8751808e9f7e43c61de864820905949f89dba)) | ||
# [1.2.0](https://github.com/CoCreate-app/CoCreate-sitemap/compare/v1.1.0...v1.2.0) (2024-08-30) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@cocreate/sitemap", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "A simple sitemap component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -39,11 +39,14 @@ /******************************************************************************** | ||
// Check if the file is HTML and contains a noindex meta tag | ||
if (file['content-type'] === 'text/html' | ||
&& /<meta\s+name=["']robots["']\s+content=["'][^"']*noindex[^"']*["']/i.test(file.src)) | ||
return; | ||
// Check if the file is HTML and contains a noindex meta or title tag | ||
if (file['content-type'] === 'text/html') { | ||
if (/<meta\s+name=["']robots["']\s+content=["'][^"']*noindex[^"']*["']/i.test(file.src)) | ||
return; | ||
if (!(/<title[^>]*>[\s\S]*?<\/title>/i.test(file.src))) | ||
return; | ||
} | ||
// Compare the lastmod date in the sitemap with the modified.on date | ||
if (file.sitemap && file.sitemap.lastmod && file.modified.on) { | ||
if (new Date(file.sitemap.lastmod) >= new Date(file.modified.on)) | ||
return; | ||
// if (new Date(file.sitemap.lastmod) >= new Date(file.modified.on)) | ||
// return; | ||
} | ||
@@ -57,2 +60,5 @@ | ||
try { | ||
if (!file.sitemap) | ||
file.sitemap = {} | ||
// TODO: need to get info such as host | ||
@@ -97,3 +103,3 @@ const entry = this.createEntry(file); | ||
if (file['content-type'] === 'text/html') { | ||
parseHtml(file) | ||
this.parseHtml(file) | ||
@@ -125,4 +131,15 @@ if (file.sitemap.type !== 'news') { | ||
for (const nestedKey of Object.keys(value[i])) { | ||
const nestedValue = value[nestedKey]; | ||
entry += `\t\t\t<${key}:${nestedKey}>${nestedValue}</${key}:${nestedKey}>\n`; | ||
const nestedValue = value[i][nestedKey]; | ||
// Handle nested objects | ||
if (typeof nestedValue === 'object' && nestedValue !== null && !(nestedValue instanceof Date)) { | ||
entry += `\t\t\t<${key}:${nestedKey}>\n`; | ||
for (const subKey of Object.keys(nestedValue)) { | ||
const subValue = nestedValue[subKey]; | ||
entry += `\t\t\t\t<${key}:${subKey}>${subValue}</${key}:${subKey}>\n`; | ||
} | ||
entry += `\t\t\t</${key}:${nestedKey}>\n`; | ||
} else { | ||
entry += `\t\t\t<${key}:${nestedKey}>${nestedValue}</${key}:${nestedKey}>\n`; | ||
} | ||
} | ||
@@ -171,3 +188,2 @@ | ||
// Query the database for the correct sitemap based on the loc and type | ||
@@ -338,3 +354,3 @@ if (file.sitemap.pathname) { | ||
parseHtml(file) { | ||
const dom = parse(html); | ||
const dom = parse(file.src); | ||
const entries = dom.querySelectorAll('[sitemap="true"]'); | ||
@@ -364,3 +380,3 @@ | ||
query = 'loc' | ||
entryObject.loc = entries[i].src; | ||
entryObject.loc = entries[i].getAttribute('src'); | ||
entryObject.title = entries[i].getAttribute('sitemap-title') || entries[i].getAttribute('title') || entries[i].getAttribute('alt'); | ||
@@ -367,0 +383,0 @@ entryObject.caption = entries[i].getAttribute('sitemap-caption') || entries[i].getAttribute('alt') || entryObject.title; |
81385
410