diff --git a/.github/modify_sitemap.js b/.github/modify_sitemap.js index 5b22b4d..223a261 100644 --- a/.github/modify_sitemap.js +++ b/.github/modify_sitemap.js @@ -32,12 +32,26 @@ fs.readFile(inputFile, "utf8", (err, data) => { const newContent = data.replace(pattern, `https://${newDomain}`); const urlBlockPattern = /([\s\S]*?<\/url>)/g; + const xhtmlLinkPattern = + /(]*?href="https:\/\/[^\/]+\/[^\/]+\/locations[^"]*"[^>]*?>)/g; + const locPattern = new RegExp(`https://${newDomain}\/[^\/]+\/locations`, "i"); // Matches URLs with an extra segment before /locations + const locDirectPattern = new RegExp(`https://${newDomain}\/locations\/`, "i"); // Matches URLs directly starting with /locations let filteredContent = newContent.replace(urlBlockPattern, (match) => { if (/https:\/\/deriv\.com(\/[a-z-]{2,5})?\/eu\//.test(match)) { return ""; } - return match; + // Check if the tag itself contains an extra segment and should be removed + if (locPattern.test(match) && !locDirectPattern.test(match)) { + return ""; // Remove entire block if contains an unwanted segment + } + const cleanedMatch = match.replace(xhtmlLinkPattern, (xhtmlLink) => { + if (locPattern.test(xhtmlLink) && !locDirectPattern.test(xhtmlLink)) { + return ""; // Remove element with extra segment before /locations + } + return xhtmlLink; // Keep valid elements + }); + return cleanedMatch; }); fs.writeFile(inputFile, filteredContent, "utf8", (err) => {