easy-sitemap-generator 0.1.12 → 0.1.13
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/package.json +2 -1
- package/utils/kleur.js +8 -0
- package/utils/xml.js +27 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-sitemap-generator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "Easy and free sitemap.xml file generator without any restrictions for your website.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sitemap",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"bin",
|
|
36
36
|
"example",
|
|
37
37
|
"lib",
|
|
38
|
+
"utils",
|
|
38
39
|
"services",
|
|
39
40
|
"index.d.ts",
|
|
40
41
|
"index.js",
|
package/utils/kleur.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const kleur = require('kleur');
|
|
2
|
+
|
|
3
|
+
const logInfo = msg => console.log(kleur.blue().bold('[INFO]: ') + msg);
|
|
4
|
+
const logSuccess = msg => console.log(kleur.green().bold('[SUCCESS]: ') + msg);
|
|
5
|
+
const logError = msg => console.error(kleur.red().bold('[ERROR]: ') + msg);
|
|
6
|
+
const logWarning = msg => console.warn(kleur.yellow().bold('[WARN]: ') + msg);
|
|
7
|
+
|
|
8
|
+
module.exports = { logInfo, logSuccess, logError, logWarning };
|
package/utils/xml.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const escapeXml = str =>
|
|
2
|
+
str.replace(/&/g, '&')
|
|
3
|
+
.replace(/</g, '<')
|
|
4
|
+
.replace(/>/g, '>')
|
|
5
|
+
.replace(/"/g, '"')
|
|
6
|
+
.replace(/'/g, ''');
|
|
7
|
+
|
|
8
|
+
const normalizeUrl = url => {
|
|
9
|
+
const parsedUrl = new URL(url);
|
|
10
|
+
parsedUrl.hash = '';
|
|
11
|
+
return parsedUrl.toString();
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const calculatePriority = (url, baseUrl) => {
|
|
15
|
+
const path = url.replace(baseUrl, '').split('/').filter(Boolean);
|
|
16
|
+
const depth = path.length;
|
|
17
|
+
const hasQuery = url.includes('?');
|
|
18
|
+
|
|
19
|
+
if (depth === 0) return 1.0;
|
|
20
|
+
if (depth === 1) return 0.85;
|
|
21
|
+
if (depth === 2) return hasQuery ? 0.54 : 0.74;
|
|
22
|
+
if (depth >= 3) return hasQuery ? 0.34 : 0.44;
|
|
23
|
+
|
|
24
|
+
return 0.5;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports = { escapeXml, normalizeUrl, calculatePriority };
|