Redirecting to ${escapedLocation}.
` return new Response(html, { headers: { 'Content-Type': 'text/html; charset=utf-8' } }) } function escapeHtml(value: string): string { return value .replaceAll('&', '&') .replaceAll('"', '"') .replaceAll('<', '<') .replaceAll('>', '>') } function extractAssetPaths(elements: HTMLElement[], baseUrl: string): string[] { let linkAttrs = elements .filter((el) => { if (el.name !== 'link') return false let rels = rel(el) return !rels.includes('nofollow') }) .map((el) => el.getAttribute('href')) let srcAttrs = elements .filter((el) => (el.name === 'script' || el.name === 'img') && el.getAttribute('src')) .map((el) => el.getAttribute('src')) return [...linkAttrs, ...srcAttrs] .filter((href): href is string => href != null) .filter((href) => !isNonNavigable(href)) .filter(isRelativeUrl) .map((href) => resolveHref(href, baseUrl)) .filter((href): href is string => href != null) } function extractLinkPaths(elements: HTMLElement[], baseUrl: string): string[] { return elements .filter( (el) => !rel(el).includes('nofollow') && (el.name === 'a' || (el.name === 'link' && rel(el).includes('alternate'))), ) .map((el) => el.getAttribute('href')) .filter((href): href is string => href != null) .filter((href) => !isNonNavigable(href)) .filter(isRelativeUrl) .map((href) => resolveHref(href, baseUrl)) .filter((href): href is string => href != null) } function shouldCrawlLinks(elements: HTMLElement[]): boolean { let hasPageNoFollowDirective = elements.some((el) => { if (el.name !== 'meta') return false let name = el.getAttribute('name')?.toLowerCase() if (name !== 'robots' && name !== 'googlebot') return false let content = el.getAttribute('content')?.toLowerCase() ?? '' return content.split(/[\s,]+/).includes('nofollow') }) return !hasPageNoFollowDirective } function rel(el: HTMLElement) { return el.getAttribute('rel')?.split(/\s+/) || [] } function isNonNavigable(href: string): boolean { return ( href.startsWith('#') || href.startsWith('mailto:') || href.startsWith('tel:') || href.startsWith('javascript:') || href.startsWith('data:') ) } function isRelativeUrl(href: string): boolean { return !href.startsWith('http://') && !href.startsWith('https://') && !href.startsWith('//') } function resolveHref(href: string, baseUrl: string): string | null { if (/^https?:\/\//.test(href) || href.startsWith('//')) { try { return new URL(href).pathname } catch { return null } } try { return new URL(href, `${BASE_URL}${baseUrl}`).pathname } catch { return null } }