-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext-sitemap.config.js
43 lines (37 loc) · 1.14 KB
/
next-sitemap.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const fs = require('fs');
const path = require('path');
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: 'https://mp3martin.xyz',
outDir: 'out',
generateRobotsTxt: true,
robotsTxtOptions: {
policies: [
{
userAgent: '*',
disallow: '/cdn-cgi/'
}
]
},
additionalPaths: async (config) => {
const publicDir = path.join(process.cwd(), 'public');
const getHtmlFiles = (dir) => {
let results = [];
const list = fs.readdirSync(dir);
list.forEach(file => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
// Recursively get files from subdirectories
results = results.concat(getHtmlFiles(filePath));
} else if (file.endsWith('.html')) {
const relativePath = path.relative(publicDir, filePath).replace('.html', '');
results.push(`/${relativePath.replace(/\\/g, '/')}`);
}
});
return results;
};
const htmlFiles = getHtmlFiles(publicDir);
return Promise.all(htmlFiles.map(file => config.transform(config, file)));
}
};