From 9bf8dbbf77df9952ea0ea0b05cd3f8b866d66174 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Sat, 30 May 2026 15:48:38 +0700 Subject: [PATCH] fix(mt-add-post): preserve YouTube video id in duplicate check bareUrl() dropped the query string, collapsing every youtube.com/watch URL to the same bare key and flagging all YouTube links as duplicates. Keep host identity params (v for youtube) so distinct videos are not treated as duplicates. --- .../skills/mt-add-post/scripts/prepare-url.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.claude/skills/mt-add-post/scripts/prepare-url.js b/.claude/skills/mt-add-post/scripts/prepare-url.js index 3edcd80..6cb3e0e 100644 --- a/.claude/skills/mt-add-post/scripts/prepare-url.js +++ b/.claude/skills/mt-add-post/scripts/prepare-url.js @@ -38,11 +38,26 @@ function cleanUrl(rawUrl) { } } -// Extract the bare URL (scheme + host + path) — used for stricter duplicate checks +// Some sites carry the resource identity in a query param, not the path +// (e.g. YouTube /watch?v=ID). Stripping the query for these collapses every +// item to the same bare URL, causing false-positive duplicates. Preserve the +// identity param for those hosts. +const IDENTITY_PARAMS = { + "youtube.com": "v", + "www.youtube.com": "v", + "m.youtube.com": "v", +}; + +// Extract the bare URL (scheme + host + path) — used for stricter duplicate checks. +// Keeps the host's identity query param when one is defined above. function bareUrl(targetUrl) { try { const p = new URL(targetUrl); - return `${p.protocol}//${p.host}${p.pathname}`.replace(/\/$/, ""); + let bare = `${p.protocol}//${p.host}${p.pathname}`.replace(/\/$/, ""); + const idParam = IDENTITY_PARAMS[p.host.toLowerCase()]; + const idValue = idParam ? p.searchParams.get(idParam) : null; + if (idValue) bare += `?${idParam}=${idValue}`; + return bare; } catch { return targetUrl.split("?")[0].replace(/\/$/, ""); }