Skip to content

Instantly share code, notes, and snippets.

@bytemain
Created November 22, 2025 03:20
Show Gist options
  • Select an option

  • Save bytemain/74c179ba1f8b74295896c4e01af6aea3 to your computer and use it in GitHub Desktop.

Select an option

Save bytemain/74c179ba1f8b74295896c4e01af6aea3 to your computer and use it in GitHub Desktop.
A script that can improve copywriting, correct spaces, words, and punctuations between CJK
import autocorrect from "autocorrect-node";
import fs from "node:fs/promises";
import path from "node:path";
import process from "node:process";
const docsDir = path.join(process.cwd(), "site", "content", "zh", "docs");
async function run() {
const entries = await fs.readdir(docsDir, { withFileTypes: true });
for (const entry of entries) {
if (!entry.isFile()) continue;
const filePath = path.join(docsDir, entry.name);
const original = await fs.readFile(filePath, "utf8");
const formatted = autocorrect.format(original);
if (formatted !== original) {
await fs.writeFile(filePath, formatted, "utf8");
console.log("formatted", path.relative(process.cwd(), filePath));
} else {
console.log("unchanged", path.relative(process.cwd(), filePath));
}
}
}
run().catch((err) => {
console.error(err);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment