Skip to content

Commit

Permalink
fix: adding helpers semrush modules
Browse files Browse the repository at this point in the history
  • Loading branch information
robsongajunior committed Jan 26, 2025
1 parent 3cbb223 commit 84db36c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
28 changes: 28 additions & 0 deletions backend/semrush-replace-url/helpers/csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { parse } from 'csv-parse';
import { createReadStream } from 'fs';

export async function read(filepath) {
const redirects = [];
const parser = createReadStream(filepath).pipe(
parse({
columns: true,
skip_empty_lines: true,
})
);

try {
for await (const record of parser) {
redirects.push({
page: record.page,
initialUrl: record.initial_url,
destinationUrl: record.destination_url,
statusCode: record.status,
discovered: record.discovered
});
}

return redirects;
} catch (error) {
throw new Error(`Error loading redirects: ${error.message}`);
}
}
5 changes: 5 additions & 0 deletions backend/semrush-replace-url/helpers/url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const wwwazioncom = () => 'https://www.azion.com';
export const removeLangFromUrl = (url) => url.replace('/pt-br', '').replace('/en', '');
export const removeHostFromUrl = (url) => url.replace(wwwazioncom(), '');
export const removeHostAndLangFromUrl = (url) => removeLangFromUrl(removeHostFromUrl(url));
export const isFromRoot = (url) => url === wwwazioncom();
2 changes: 1 addition & 1 deletion backend/semrush-replace-url/index.i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function processFile(filePath, redirects) {

if(contentMatchDoubleQuote.length) {
newContent = newContent.replace(
isRoot ? /"https\:\/\/www\.azion\.com\/"çççç/ : rgx,
isRoot ? /"https\:\/\/www\.azion\.com\/"/ : rgx,
`'${url200}'`
);
}
Expand Down

0 comments on commit 84db36c

Please sign in to comment.