@alex-drocks/react-snap-sitemap
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Create a sitemap post react-snap SSR", | ||
@@ -10,0 +10,0 @@ "keywords": [ |
@@ -15,2 +15,4 @@ # React Snap Sitemap | ||
You can also add `--change-frequency=always|daily|weekly|monthly|yearly|never`. | ||
You can also add `--change-frequency=always|daily|weekly|monthly|yearly|never`. | ||
If you need trailing slashes at the end of your URLs add `--add-slash=true` |
18
run.js
@@ -11,2 +11,3 @@ #!/usr/bin/env node | ||
const preFormattedChangeFrequency = args.find((arg) => arg.startsWith('--change-frequency=')); | ||
const addSlash = args.find((arg) => arg.startsWith('--add-slash=')); | ||
let blackList = []; | ||
@@ -21,3 +22,2 @@ | ||
let baseUrl; | ||
if (preFormattedBaseUrl) { | ||
@@ -28,3 +28,2 @@ baseUrl = preFormattedBaseUrl.split('=')[1]; | ||
} | ||
if (baseUrl.length === 0) { | ||
@@ -35,3 +34,2 @@ throw (new Error('Pass a valid url to --base-url')); | ||
let changeFrequency; | ||
if (preFormattedChangeFrequency) { | ||
@@ -43,2 +41,5 @@ changeFrequency = preFormattedChangeFrequency.split('=')[1]; | ||
const shouldAddSlashes = addSlash ? true : false; | ||
console.log({shouldAddSlashes}) | ||
const asyncReaddir = promisify(readdir), asyncWriteFile = promisify(writeFile), asyncLStat = promisify(lstat); | ||
@@ -107,4 +108,9 @@ | ||
.forEach(url => { | ||
const isMainPage = url + "/" === baseUrl; | ||
const u = urlset.ele('url'); | ||
u.ele('loc', url); | ||
if (!isMainPage && shouldAddSlashes) { | ||
u.ele("loc", url + "/"); | ||
} else { | ||
u.ele('loc', url); | ||
} | ||
u.ele('lastmod', formatDate(Date.now())) | ||
@@ -115,5 +121,3 @@ if (changeFrequency) { | ||
url + "/" === baseUrl | ||
? u.ele('priority', "1.0") | ||
: u.ele('priority', "0.8"); | ||
isMainPage ? u.ele('priority', "1.0") : u.ele('priority', "0.5"); | ||
}); | ||
@@ -120,0 +124,0 @@ |
4608
96
17