feat: add sitemap image URL validation gate

This commit is contained in:
2026-05-04 13:04:00 +08:00
parent ca08024cb5
commit e0df92e05e
2 changed files with 85 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
/**
* Validates an image URL for sitemap use.
* Returns `null` for invalid inputs, otherwise returns the trimmed HTTPS URL.
*/
export function validateImageUrl(url: string | null | undefined): string | null {
if (!url || typeof url !== "string") return null
const trimmed = url.trim()
if (trimmed.length === 0) return null
if (!trimmed.startsWith("https://")) return null
if (trimmed.length > 2048) return null
return trimmed
}