From ac86c0de14ccebf3794880d657a04bdc070b6066 Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Fri, 27 Jun 2025 05:10:14 -0700 Subject: [PATCH] feat(route/smartlink): enhance title parsing for none YouTube link (#19469) --- lib/routes/smartlink/index.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/routes/smartlink/index.ts b/lib/routes/smartlink/index.ts index 2dabe10c7..235fc805b 100644 --- a/lib/routes/smartlink/index.ts +++ b/lib/routes/smartlink/index.ts @@ -22,10 +22,20 @@ function parseTitle(smartlinkUrl: string): string { } } +function isYouTubeUrl(url: string): boolean { + try { + const parsedUrl = new URL(url); + const hostname = parsedUrl.hostname.toLowerCase(); + return hostname === 'youtube.com' || hostname === 'www.youtube.com' || hostname === 'm.youtube.com' || hostname === 'youtu.be'; + } catch { + return false; + } +} + function getTitle(item: any): string { - return item.type === 'video' - ? item.smartlink.split('?')[0] // For video items, use the full YouTube URL (without query parameters) - : parseTitle(item.smartlink); // Use existing parseTitle for photo items + return isYouTubeUrl(item.smartlink) + ? item.smartlink.split('?')[0] // For YouTube URLs, use the URL without query parameters + : parseTitle(item.smartlink); // Use existing parseTitle for other URLs } export const route: Route = {