Files
sgemed/scripts/sitemap-config.mjs
T

12 lines
1.0 KiB
JavaScript

import {readdir,mkdir,writeFile} from 'node:fs/promises';
import path from 'node:path';
const staticPages=[];
const seoByPath={
'/':{changefreq:'daily',priority:1},
'/about-us':{changefreq:'monthly',priority:0.6},
'/tmas-bama':{changefreq:'monthly',priority:0.5},
'/blog':{changefreq:'weekly',priority:0.7},
};
async function scan(dir,parts=[]){for(const entry of await readdir(dir,{withFileTypes:true})){if(entry.isDirectory()&&!entry.name.startsWith('[')&&!entry.name.startsWith('_')&&!['api','account','admin','login','cart','checkout'].includes(entry.name))await scan(path.join(dir,entry.name),entry.name.startsWith('(')?parts:[...parts,entry.name]);else if(entry.isFile()&&/^page\.(tsx|jsx|js|ts)$/.test(entry.name)){const route='/'+parts.join('/');staticPages.push({path:route,...(seoByPath[route]||{changefreq:'monthly',priority:0.6})})}}}
await scan('app');await mkdir('public/meshkee',{recursive:true});await writeFile('public/meshkee/sitemap-config.json',JSON.stringify({baseUrl:'https://sgemed.com',staticPages},null,2)+'\n');