-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cbb223
commit 84db36c
Showing
3 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters