Created
November 22, 2025 03:20
-
-
Save bytemain/878532707e60dc2550d5176fdac5760e to your computer and use it in GitHub Desktop.
A tiny script that can improve copywriting, correct spaces, words, and punctuations between CJK. Powered by https://github.com/huacnlee/autocorrect
This file contains hidden or 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
| 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