Skip to content

Commit

Permalink
Merge pull request #173 from moiz-deriv/moiz/language-link-sitemap-re…
Browse files Browse the repository at this point in the history
…moval

fix: removed language links for /locations from sitemap
  • Loading branch information
ali-hosseini-deriv authored Oct 10, 2024
2 parents 3e3094f + 6b90d73 commit e2b5dd2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion .github/modify_sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,26 @@ fs.readFile(inputFile, "utf8", (err, data) => {
const newContent = data.replace(pattern, `https://${newDomain}`);

const urlBlockPattern = /(<url>[\s\S]*?<\/url>)/g;
const xhtmlLinkPattern =
/(<xhtml:link[^>]*?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 <loc> tag itself contains an extra segment and should be removed
if (locPattern.test(match) && !locDirectPattern.test(match)) {
return ""; // Remove entire <url> block if <loc> contains an unwanted segment
}
const cleanedMatch = match.replace(xhtmlLinkPattern, (xhtmlLink) => {
if (locPattern.test(xhtmlLink) && !locDirectPattern.test(xhtmlLink)) {
return ""; // Remove <xhtml:link> element with extra segment before /locations
}
return xhtmlLink; // Keep valid <xhtml:link> elements
});
return cleanedMatch;
});

fs.writeFile(inputFile, filteredContent, "utf8", (err) => {
Expand Down

0 comments on commit e2b5dd2

Please sign in to comment.