@cocreate/sitemap 1.2.0 → 1.2.1

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.2.1](https://github.com/CoCreate-app/CoCreate-sitemap/compare/v1.2.0...v1.2.1) (2024-09-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * return if no title, parse sub object in createEntry ([97d8751](https://github.com/CoCreate-app/CoCreate-sitemap/commit/97d8751808e9f7e43c61de864820905949f89dba))
7
+
1
8
  # [1.2.0](https://github.com/CoCreate-app/CoCreate-sitemap/compare/v1.1.0...v1.2.0) (2024-08-30)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/sitemap",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "A simple sitemap component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "sitemap",
package/src/index.js CHANGED
@@ -36,15 +36,18 @@ class CoCreateSitemap {
36
36
  if (!file.public || file.public === "false")
37
37
  return;
38
38
 
39
- // Check if the file is HTML and contains a noindex meta tag
40
- if (file['content-type'] === 'text/html'
41
- && /<meta\s+name=["']robots["']\s+content=["'][^"']*noindex[^"']*["']/i.test(file.src))
42
- return;
39
+ // Check if the file is HTML and contains a noindex meta or title tag
40
+ if (file['content-type'] === 'text/html') {
41
+ if (/<meta\s+name=["']robots["']\s+content=["'][^"']*noindex[^"']*["']/i.test(file.src))
42
+ return;
43
+ if (!(/<title[^>]*>[\s\S]*?<\/title>/i.test(file.src)))
44
+ return;
45
+ }
43
46
 
44
47
  // Compare the lastmod date in the sitemap with the modified.on date
45
48
  if (file.sitemap && file.sitemap.lastmod && file.modified.on) {
46
- if (new Date(file.sitemap.lastmod) >= new Date(file.modified.on))
47
- return;
49
+ // if (new Date(file.sitemap.lastmod) >= new Date(file.modified.on))
50
+ // return;
48
51
  }
49
52
 
50
53
  // Logic to update the sitemap
@@ -53,6 +56,9 @@ class CoCreateSitemap {
53
56
 
54
57
  async updateSitemap(file, host) {
55
58
  try {
59
+ if (!file.sitemap)
60
+ file.sitemap = {}
61
+
56
62
  // TODO: need to get info such as host
57
63
  const entry = this.createEntry(file);
58
64
 
@@ -92,7 +98,7 @@ class CoCreateSitemap {
92
98
  file.sitemap.lastmod = file.modified.on;
93
99
 
94
100
  if (file['content-type'] === 'text/html') {
95
- parseHtml(file)
101
+ this.parseHtml(file)
96
102
 
97
103
  if (file.sitemap.type !== 'news') {
98
104
  if (file.sitemap.changefreq)
@@ -119,8 +125,19 @@ class CoCreateSitemap {
119
125
  entry += `\t\t<${key}:${key}>\n`;
120
126
 
121
127
  for (const nestedKey of Object.keys(value[i])) {
122
- const nestedValue = value[nestedKey];
123
- entry += `\t\t\t<${key}:${nestedKey}>${nestedValue}</${key}:${nestedKey}>\n`;
128
+ const nestedValue = value[i][nestedKey];
129
+
130
+ // Handle nested objects
131
+ if (typeof nestedValue === 'object' && nestedValue !== null && !(nestedValue instanceof Date)) {
132
+ entry += `\t\t\t<${key}:${nestedKey}>\n`;
133
+ for (const subKey of Object.keys(nestedValue)) {
134
+ const subValue = nestedValue[subKey];
135
+ entry += `\t\t\t\t<${key}:${subKey}>${subValue}</${key}:${subKey}>\n`;
136
+ }
137
+ entry += `\t\t\t</${key}:${nestedKey}>\n`;
138
+ } else {
139
+ entry += `\t\t\t<${key}:${nestedKey}>${nestedValue}</${key}:${nestedKey}>\n`;
140
+ }
124
141
  }
125
142
 
126
143
  entry += `\t\t</${key}:${key}>\n`;
@@ -164,7 +181,6 @@ class CoCreateSitemap {
164
181
  // Update loc using pathname
165
182
  file.sitemap.loc = `${file.pathname}`
166
183
 
167
-
168
184
  // Query the database for the correct sitemap based on the loc and type
169
185
  if (file.sitemap.pathname) {
170
186
  sitemap = await this.readSitemap(sitemap, host);
@@ -330,7 +346,7 @@ class CoCreateSitemap {
330
346
  }
331
347
 
332
348
  parseHtml(file) {
333
- const dom = parse(html);
349
+ const dom = parse(file.src);
334
350
  const entries = dom.querySelectorAll('[sitemap="true"]');
335
351
 
336
352
  let types = ['image', 'video', 'news']
@@ -355,7 +371,7 @@ class CoCreateSitemap {
355
371
  if (entries[i].tagName === 'IMG') { // Corrected to 'IMG' for images
356
372
  type = 'image';
357
373
  query = 'loc'
358
- entryObject.loc = entries[i].src;
374
+ entryObject.loc = entries[i].getAttribute('src');
359
375
  entryObject.title = entries[i].getAttribute('sitemap-title') || entries[i].getAttribute('title') || entries[i].getAttribute('alt');
360
376
  entryObject.caption = entries[i].getAttribute('sitemap-caption') || entries[i].getAttribute('alt') || entryObject.title;
361
377
  entryObject.geo_location = entries[i].getAttribute('sitemap-geo-location');