| 8 | const urls: MetadataRoute.Sitemap = [] |
| 9 | |
| 10 | function readDirectory(dir: string, baseUrl: string) { |
| 11 | const files = fs.readdirSync(dir) |
| 12 | |
| 13 | files.forEach((file) => { |
| 14 | const filePath = path.join(dir, file) |
| 15 | const stats = fs.statSync(filePath) |
| 16 | |
| 17 | if (stats.isDirectory()) { |
| 18 | // Recursively search subdirectories |
| 19 | readDirectory(filePath, `${baseUrl}/${file}`) |
| 20 | } else if (file.endsWith('page.tsx') || file.endsWith('page.mdx')) { |
| 21 | // Adjust path by removing "/(docs)" |
| 22 | const adjustedUrl = baseUrl.replace('/(docs)', '') |
| 23 | |
| 24 | // Add this page to the sitemap |
| 25 | urls.push({ |
| 26 | url: `https://syntaxui.com${adjustedUrl || '/'}`, |
| 27 | lastModified: new Date().toISOString(), |
| 28 | priority: 1, |
| 29 | changeFrequency: 'daily', |
| 30 | }) |
| 31 | } |
| 32 | }) |
| 33 | } |
| 34 | |
| 35 | // Initialize the recursive search |
| 36 | readDirectory(rootDir, '') |