-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnext-sitemap.config.js
More file actions
executable file
·47 lines (39 loc) · 1.35 KB
/
Copy pathnext-sitemap.config.js
File metadata and controls
executable file
·47 lines (39 loc) · 1.35 KB
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
43
44
45
46
47
const fs = require('fs');
const path = require('path');
// Scan app/ folder recursively, include only folders with page.jsx
function getAllPages(dir = 'app', prefix = '') {
const routes = [];
const items = fs.readdirSync(dir);
for (const item of items) {
const fullPath = path.join(dir, item);
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
if (item === 'api' || item.startsWith('_')) continue; // skip API and special folders
const pageFile = fs.readdirSync(fullPath).find(f => f === 'page.jsx' || f === 'page.tsx');
if (pageFile) {
routes.push(`${prefix}/${item}`);
}
// Recurse into subfolders
routes.push(...getAllPages(fullPath, `${prefix}/${item}`));
}
}
return routes;
}
/** @type {import('next-sitemap').IConfig} */
const config = {
siteUrl: 'https://dsavisualizer.in',
generateRobotsTxt: true,
sitemapSize: 5000,
transform: async (config, path) => ({
loc: path,
lastmod: new Date().toISOString(),
}),
additionalPaths: async (config) => {
const allRoutes = getAllPages(); // recursively get all module pages
return allRoutes.map(route => ({
loc: route,
lastmod: new Date().toISOString(),
}));
},
};
module.exports = config;