mirror of
https://iceshrimp.dev/Crimekillz/jointrashposs.git
synced 2024-11-24 17:59:07 +01:00
1734b7bff6
* vercel initial * [ci skip] add gitignore * fix config * fix * (add) prerendered routes を自動生成 * fix config * fix path * (fix) trailing slash
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import type { Nitro } from "nitropack";
|
|
//import { useRuntimeConfig } from "nuxt/app";
|
|
import { SitemapStream, streamToPromise, SitemapItem } from 'sitemap';
|
|
import { Readable } from 'stream';
|
|
import { writeFileSync } from 'fs';
|
|
import path from 'path';
|
|
|
|
export default async function genSitemap(nitro: Nitro) {
|
|
if (!nitro._prerenderedRoutes) {
|
|
return;
|
|
}
|
|
|
|
const domain = nitro.options.runtimeConfig.public.baseUrl;
|
|
const publicDir = nitro.options.output.publicDir;
|
|
|
|
const routes = nitro._prerenderedRoutes?.map((e) => e.fileName || null).filter((e, i, a) => e && a.indexOf(e) === i && e.endsWith("index.html")).map((e) => {
|
|
return {
|
|
url: e?.replace(/index\.html$/, ''),
|
|
|
|
changefreq: 'weekly',
|
|
priority: .7,
|
|
} as SitemapItem;
|
|
});
|
|
|
|
if (routes.length === 0) return;
|
|
|
|
const smStream = new SitemapStream({ hostname: domain });
|
|
Readable.from(routes).pipe(smStream);
|
|
|
|
const data = await streamToPromise(smStream);
|
|
|
|
writeFileSync(path.join(publicDir, 'sitemap.xml'), data.toString());
|
|
console.log("Sitemap was generated");
|
|
} |