Skip to content

Commit ad13b5f

Browse files
authored
Add files via upload
1 parent c277281 commit ad13b5f

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

generate-sitemap.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
// Function to recursively get all files in a directory, excluding .git and .github
5+
function getAllFiles(dirPath, arrayOfFiles) {
6+
const files = fs.readdirSync(dirPath);
7+
8+
arrayOfFiles = arrayOfFiles || [];
9+
10+
files.forEach(function(file) {
11+
if (['.git', '.github', 'assets', 'go', 'link','static','.nojekyll','manifest.json','sw.js','ads.txt'].includes(file)) {
12+
return;
13+
}
14+
if (fs.statSync(dirPath + '/' + file).isDirectory()) {
15+
arrayOfFiles = getAllFiles(dirPath + '/' + file, arrayOfFiles);
16+
} else {
17+
arrayOfFiles.push(path.join(dirPath, '/', file));
18+
}
19+
});
20+
21+
return arrayOfFiles;
22+
}
23+
24+
// Generate sitemap.xml content
25+
function generateSitemap(files) {
26+
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n';
27+
xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n';
28+
29+
files.forEach(function(file) {
30+
const url = 'https://clashv2ray-hub.github.io/' + file.replace('./', ''); // Update URL as needed
31+
xml += `\t<url>\n\t\t<loc>${url}</loc>\n\t</url>\n`;
32+
});
33+
34+
xml += '</urlset>';
35+
36+
return xml;
37+
}
38+
39+
// Main script
40+
const files = getAllFiles('./'); // Start from the root directory, you can change this path as needed
41+
const sitemapContent = generateSitemap(files);
42+
43+
// Write sitemap.xml file
44+
fs.writeFileSync('sitemap.xml', sitemapContent);
45+
46+
console.log('sitemap.xml generated successfully!');

package.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "tg-nav.github.io",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"generate-sitemap": "node generate-sitemap.js"
6+
}
7+
}

0 commit comments

Comments
 (0)