From dfef5c8b24e69ef0cbd90ddafa5de5b8c3961490 Mon Sep 17 00:00:00 2001 From: techfg Date: Wed, 4 Dec 2024 10:31:18 -0800 Subject: [PATCH] update per PR comments --- .changeset/neat-deers-pretend.md | 2 +- packages/starlight/schemas/favicon.ts | 6 +++--- packages/starlight/utils/path.ts | 13 +------------ 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/.changeset/neat-deers-pretend.md b/.changeset/neat-deers-pretend.md index a9e2e91c4a..cec30a8c8b 100644 --- a/.changeset/neat-deers-pretend.md +++ b/.changeset/neat-deers-pretend.md @@ -2,4 +2,4 @@ '@astrojs/starlight': patch --- -Fixes favicon url parsing of query and fragment +Fixes support for favicon URLs that contain a search query and/or hash diff --git a/packages/starlight/schemas/favicon.ts b/packages/starlight/schemas/favicon.ts index 771402b7a0..b3b6a57009 100644 --- a/packages/starlight/schemas/favicon.ts +++ b/packages/starlight/schemas/favicon.ts @@ -1,6 +1,5 @@ import { extname } from 'node:path'; import { z } from 'astro/zod'; -import { splitQueryAndFragment } from '../utils/path'; const faviconTypeMap = { '.ico': 'image/x-icon', @@ -16,8 +15,9 @@ export const FaviconSchema = () => .string() .default('/favicon.svg') .transform((favicon, ctx) => { - const { base } = splitQueryAndFragment(favicon); - const ext = extname(base).toLowerCase(); + // favicon can be absolute or relative url + const { pathname } = new URL(favicon, 'https://example.com'); + const ext = extname(pathname).toLowerCase(); if (!isFaviconExt(ext)) { ctx.addIssue({ diff --git a/packages/starlight/utils/path.ts b/packages/starlight/utils/path.ts index b9865d1866..4752856e0c 100644 --- a/packages/starlight/utils/path.ts +++ b/packages/starlight/utils/path.ts @@ -49,15 +49,4 @@ export function ensureHtmlExtension(path: string) { path = path ? path + '.html' : '/index.html'; } return ensureLeadingSlash(path); -} - -export function splitQueryAndFragment(url: string) { - const [urlWithQuery, hash] = url.split('#'); - const [urlBase, queryString] = (urlWithQuery || '').split('?'); - - return { - base: urlBase || '', - query: queryString ? `?${queryString}` : '', - fragment: hash ? `#${hash}` : '', - }; -} +} \ No newline at end of file