Fix
This commit is contained in:
@@ -89,13 +89,13 @@ export type SitemapRouteOptions = {
|
||||
export function createSitemapRouteHandler(
|
||||
sitemap: () => Promise<SitemapEntry[]>,
|
||||
opts: SitemapRouteOptions = {},
|
||||
): (req: Request) => Promise<Response> {
|
||||
): (req?: Request) => Promise<Response> {
|
||||
const style = opts.cssUrl ? false : opts.style === false ? false : (opts.style ?? {})
|
||||
|
||||
return async (req: Request) => {
|
||||
const url = new URL(req.url)
|
||||
return async (req?: Request) => {
|
||||
const url = req ? new URL(req.url) : null
|
||||
|
||||
if (style && url.searchParams.has(SITEMAP_STYLE_PARAM)) {
|
||||
if (style && url?.searchParams.has(SITEMAP_STYLE_PARAM)) {
|
||||
let title: string | undefined
|
||||
try {
|
||||
title = typeof style.title === 'function' ? await style.title() : style.title
|
||||
@@ -111,7 +111,7 @@ export function createSitemapRouteHandler(
|
||||
})
|
||||
}
|
||||
|
||||
const cssUrl = opts.cssUrl ?? (style ? `${url.pathname}?${SITEMAP_STYLE_PARAM}` : undefined)
|
||||
const cssUrl = opts.cssUrl ?? (style ? `${url?.pathname ?? '/sitemap.xml'}?${SITEMAP_STYLE_PARAM}` : undefined)
|
||||
try {
|
||||
const entries = await sitemap()
|
||||
const xml = buildSitemapXml(entries, { cssUrl })
|
||||
|
||||
Reference in New Issue
Block a user