From d8a189e23716e526fdf359f469becd550a0192dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E7=BA=B8=E5=BF=98=E5=BF=A7?= Date: Fri, 1 Nov 2024 11:23:00 +0800 Subject: [PATCH] fix: astro check type error --- package.json | 2 +- translate.ts | 45 --------------------------------------------- tsconfig.json | 2 +- 3 files changed, 2 insertions(+), 47 deletions(-) delete mode 100644 translate.ts diff --git a/package.json b/package.json index 3c3f2437..d2710ed1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "orm-drizzle-docs-astro", "type": "module", "version": "0.0.1", - "packageManager": "pnpm@9.6.0", + "packageManager": "pnpm@9.12.3", "scripts": { "preinstall": "npx only-allow pnpm", "dev": "astro dev --host", diff --git a/translate.ts b/translate.ts deleted file mode 100644 index efd5c72c..00000000 --- a/translate.ts +++ /dev/null @@ -1,45 +0,0 @@ -import OpenAI from "openai"; -import fs from "fs"; -import path from "path"; - -const openai = new OpenAI({ - apiKey: process.env.OPENAI_API, - baseURL: process.env.OPENAI_BASE_URL, -}); - -const extname = ".mdx"; -const prompt = - "将以下 mdx 文档翻译成中文,要求在中文和英文单词之间插入空格隔开,严格按照原 mdx 格式"; - -async function translate(content: string) { - const response = await openai.chat.completions.create({ - messages: [ - { role: "user", content: prompt }, - { role: "user", content }, - ], - model: "gpt-3.5-turbo-16k", - }); - return response.choices[0].message.content || ""; -} - -async function main(targetPath: string) { - const isDir = fs.statSync(targetPath).isDirectory(); - - const files = isDir - ? fs.readdirSync(targetPath).map((file) => path.join(targetPath, file)) - : [targetPath]; - - for (const filePath of files) { - const ext = path.extname(filePath); - if (ext === extname) { - const content = fs.readFileSync(filePath, "utf8"); - const translated = await translate(content); - fs.writeFileSync(filePath, translated, "utf8"); - console.log(`已翻译:${path.basename(filePath)}`); - } else { - console.log(`未翻译:${path.basename(filePath)}`); - } - } -} - -await main("src/content/documentation/docs/overview.mdx"); diff --git a/tsconfig.json b/tsconfig.json index dbf0d867..d196aa1a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,5 +18,5 @@ "jsxImportSource": "react", "types": ["vite/client"] }, - "include": ["./src/", "./src/types/declarations.d.ts", "./**/*.ts"] + "include": ["./src/", "./src/types/declarations.d.ts"] } \ No newline at end of file