-
Notifications
You must be signed in to change notification settings - Fork 37
/
sitemap.ts
38 lines (30 loc) · 974 Bytes
/
sitemap.ts
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
const fs = require('fs');
const path = require('path');
import { MetadataRoute } from 'next';
export function getFoldersRecursive(filePath: any) {
const folders: any = [];
function shouldIgnoreFolder(folderName: any) {
const ignoredPrefixes = ['[', '(', '_', '-', 'api'];
return ignoredPrefixes.some((prefix) => folderName.startsWith(prefix));
}
function traverse(currentPath: any) {
const files = fs.readdirSync(currentPath, { withFileTypes: true });
files.forEach((file: any) => {
if (file.isDirectory()) {
const folderName = file.name;
if (!shouldIgnoreFolder(folderName)) {
folders.push(folderName);
traverse(path.join(currentPath, folderName));
}
}
});
}
traverse(filePath);
return folders;
}
// Usage example
const targetPath = '/app';
const folderNames = getFoldersRecursive(targetPath);
export default function sitemap(): MetadataRoute.Sitemap {
return folderNames
}