feat(route/smartlink): enhance title parsing for none YouTube link (#19469)

This commit is contained in:
Qiang Huang 2025-06-27 05:10:14 -07:00 committed by GitHub
parent c82cb78105
commit ac86c0de14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 3 deletions

View File

@ -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 = {