Skip to content

Commit

Permalink
Merge branch 'main' into add-locale-check
Browse files Browse the repository at this point in the history
  • Loading branch information
yin1999 authored Sep 27, 2023
2 parents 7267bda + bbc5c78 commit 75e0435
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scripts/check-url-locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,14 @@ function fixUrlLocale(content, errors, expectedLocale) {
}
return a.line - b.line;
});
expectedLocale = `/${expectedLocale}/`;
const lines = content.split("\n");
for (const { url, line, column, urlLocale } of errors) {
let lineContent = lines[line - 1];
const prefix = lineContent.slice(0, column - 1);
const newUrl = url.replace(urlLocale, expectedLocale);
// replace the slashed locale with the expected locale
// to prevent replacing the empty url locale
const newUrl = url.replace(`/${urlLocale}/`, expectedLocale);
const suffix = lineContent.slice(column - 1).replace(url, newUrl);
lines[line - 1] = `${prefix}${suffix}`;
}
Expand Down Expand Up @@ -221,7 +224,7 @@ async function main() {

spinner.text = "Crawling files...";

const dryRun = argv.dry;
const dryRun = !argv.fix;

for (const fp of argv.files) {
const fstats = await fs.stat(fp);
Expand Down

0 comments on commit 75e0435

Please sign in to comment.