remix-seo-plus
Version:
Collection of SEO utilities like sitemap, robots.txt, etc. for a Remix application. A fork of https://github.com/balavishnuvj/remix-seo with some added bug fixes and features.
22 lines (19 loc) • 621 B
text/typescript
import type { ServerBuild } from "@remix-run/server-runtime";
import { GenerateSitemapArgs, SEOOptions } from "../types";
import { getSitemapXml } from "./utils";
export async function generateSitemap(
args: GenerateSitemapArgs,
routes: ServerBuild["routes"],
options: SEOOptions
) {
const { siteUrl, headers } = options;
const sitemap = await getSitemapXml(args, routes, { siteUrl });
const bytes = new TextEncoder().encode(sitemap).byteLength;
return new Response(sitemap, {
headers: {
...headers,
"Content-Type": "application/xml",
"Content-Length": String(bytes),
},
});
}