easy-sitemap-generator 0.1.0 → 0.1.2

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.
@@ -6,7 +6,7 @@ const path = require('path');
6
6
  const { escapeXml, normalizeUrl, calculatePriority } = require('../utils/xml.js');
7
7
  const { logInfo, logSuccess, logError, logWarning } = require('../utils/kleur.js');
8
8
 
9
- const VISITED_URLS = new Set();
9
+ const VISITED_URLS = new Map();
10
10
  const IGNORED_PATTERNS = ['cdn-cgi', '?referrer=', '&referrer=', '/signin/v2/usernamerecovery', '/lifecycle/flows/signup', 'join?return_to='];
11
11
  const BASE_DELAY = 8000;
12
12
 
@@ -16,7 +16,6 @@ const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
16
16
  const fetchUrl = async (url, retries = 0) => {
17
17
  try {
18
18
  logInfo(`GET ${url}`);
19
-
20
19
  return await axios.get(url);
21
20
  } catch (err) {
22
21
  logError(`Error fetching URL: ${url} - ${err.message}`);
@@ -43,15 +42,13 @@ const fetchUrl = async (url, retries = 0) => {
43
42
 
44
43
  const crawl = async (url, baseUrl) => {
45
44
  const normalizedUrl = normalizeUrl(url);
46
- if (VISITED_URLS.has(normalizedUrl)) return; else VISITED_URLS.add(normalizedUrl);
45
+ if (VISITED_URLS.has(normalizedUrl)) return;
46
+ VISITED_URLS.set(normalizedUrl, { url: normalizedUrl });
47
47
 
48
- const response = await fetchUrl(normalizedUrl);
49
- if (!response) {
50
- logWarning(`No response received for URL: ${normalizedUrl}`);
51
- return;
52
- }
48
+ const res = await fetchUrl(normalizedUrl);
49
+ if (!res) return logWarning(`No response received for URL: ${normalizedUrl}`);
53
50
 
54
- const { document } = new JSDOM(response.data).window;
51
+ const { document } = new JSDOM(res.data).window;
55
52
  const links = Array.from(document.querySelectorAll('a[href]'))
56
53
  .map(link => urlModule.resolve(baseUrl, link.getAttribute('href')))
57
54
  .map(normalizeUrl)
@@ -63,7 +60,11 @@ const crawl = async (url, baseUrl) => {
63
60
  await crawl(link, baseUrl);
64
61
  }
65
62
 
66
- return { url: normalizedUrl, lastmod: response.headers['last-modified'] ? new Date(response.headers['last-modified']).toISOString() : new Date().toISOString() };
63
+ VISITED_URLS.set(normalizedUrl, {
64
+ url: normalizedUrl,
65
+ lastmod: (res.headers['last-modified'] ? new Date(res.headers['last-modified']) : new Date()).toISOString(),
66
+ priority: calculatePriority(normalizedUrl, baseUrl)
67
+ });
67
68
  };
68
69
 
69
70
  const generateSitemap = async (baseUrl, destination = 'sitemap.xml') => {
@@ -73,17 +74,11 @@ const generateSitemap = async (baseUrl, destination = 'sitemap.xml') => {
73
74
 
74
75
  logInfo(`Generating sitemap with ${VISITED_URLS.size} URLs...`);
75
76
 
76
- const urls = Array.from(VISITED_URLS)
77
- .filter(url => shouldIncludeUrl(url, baseUrl))
78
- .map(url => ({
79
- url,
80
- priority: calculatePriority(url, baseUrl),
81
- lastmod: new Date().toISOString()
82
- }))
77
+ const urls = Array.from(VISITED_URLS.values())
83
78
  .sort((a, b) => b.priority - a.priority);
84
79
 
85
80
  const sitemapContent = `<?xml version="1.0" encoding="UTF-8"?>
86
- <!-- Generated by sitemap generator - ${new Date()} -->
81
+ <!-- Generated by https://github.com/sefinek24/easy-sitemap-generator at ${new Date().toISOString()} -->
87
82
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
88
83
  ${urls.map(({ url, priority, lastmod }) => ` <url>
89
84
  <loc>${escapeXml(url)}</loc>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-sitemap-generator",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Free and easy sitemap.xml file generator without any restrictions for your website. Try now!",
5
5
  "homepage": "https://github.com/sefinek24/easy-sitemap-generator#readme",
6
6
  "bugs": {
@@ -21,11 +21,11 @@
21
21
  "sitemap-generator": "./bin/cli.js"
22
22
  },
23
23
  "scripts": {
24
- "test": "jest test/index.test.js",
24
+ "test": "echo \"Error: no test specified\" && exit 1",
25
25
  "up": "ncu -u && npm install && npm update && npm audit fix"
26
26
  },
27
27
  "dependencies": {
28
- "axios": "^1.7.3",
28
+ "axios": "^1.7.4",
29
29
  "jsdom": "^24.1.1",
30
30
  "kleur": "^4.1.5"
31
31
  },