Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop-astro-nacos' into deve…
Browse files Browse the repository at this point in the history
…lop-astro-nacos
  • Loading branch information
Tinie13 committed Jun 24, 2024
2 parents 57dc53c + a28c9b1 commit e0f9f77
Show file tree
Hide file tree
Showing 302 changed files with 5,114 additions and 1,214 deletions.
198 changes: 198 additions & 0 deletions script/translateToEn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
import fs from "fs/promises";
import path from "path";
import { fileURLToPath } from 'url';
import { config } from "dotenv";
import { request } from "./util.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const envPath = path.resolve(__dirname, '../.env');
config({ path: envPath });

const isTranslate = false;

const askAI = async (content) => {
const url = "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation"
const header = {
"Content-Type": "application/json",
"Authorization": "Bearer "+ process.env.QWEN_TOKEN
}
const body = {
"model": "qwen-max",
"input":{
"messages": [
{
"role": "system",
"content": "你是SEO领域的专家,擅长总结文章并输出有利于SEO的关键词。你还是一个翻译专家,擅长以开源微服务为技术背景做中/英文之间的翻译,生成与中文文档格式完全一致的英文翻译稿"
},
{
"role": "user",
"content": `请阅读以下markdown格式的文章,并严格按照下面的格式输出回答,方便后续进行正则匹配和内容截取(关键词、描述信息、翻译后的英文文章},这些小标题一个字都不允许变),同时请注意关键词与描述信息需要为中文内容:
1. 关键词: "总结的中文关键词,要求格式为数组,多个关键词用英文逗号分隔,不超过5个",
2. 描述信息: "总结的内容,语言为中文,大概在150-160字之间,不要超过200字"
3. 翻译后的英文文章:"根据原文翻译之后的英文文章。需要与我给你的格式完全相同,即需要有front-matter。不需要为markdown格式,为字符串格式即可"
请根据以下原文进行生成返回内容:
${content}
`
}
]

},
"parameters": {
"result_format": "message"
}
}
try {
let res = await request(url, "POST", header, body);
return res.output.choices[0].message.content
} catch (error) {
throw(error)
}

}

async function traverseDirectorySync (dir) {
try {
const files = await fs.readdir(dir,{ withFileTypes: true })
// console.log("-======",files)
for (const file of files) {
const filePath = path.join(dir, file.name);
if (file.isDirectory()) {
// 如果是文件夹,输出文件夹路径并递归遍历
console.log(`目录:${filePath}`);
traverseDirectorySync(filePath);
} else if (file.name.endsWith('.md') || file.name.endsWith('.mdx')) {
const data = await fs.readFile(filePath, 'utf8');
let res = await askAI(data);
console.log(file.name, "回答问题完成");
console.log("======",res)
const { keywords, description, content } = regContent(res);

// 替换中文文档内容
await replaceZhContent( filePath, data, keywords, description );
// 生成英文翻译文件
isTranslate && await generateEnFile(filePath, content)
}
}
} catch (err) {
console.error(err);
}
}

function regContent(res) {
const keywordsRegex = /关键词:\s*"([^"]*)"/;
const regDescrip = /描述信息:\s*"([^"]*)"/;
const regContent = /翻译后的英文文章:\s*"([\s\S]*)"/;

const keywordsMatch = res.match(keywordsRegex);
const keywords = keywordsMatch ? keywordsMatch[1].trim() : '';

const descripMatch = res.match(regDescrip);
const description = descripMatch ? descripMatch[1].trim() : '';

const contentMatch = res.match(regContent);
const content = contentMatch ? contentMatch[1].trim() : '';
return { keywords, description, content };
}
// const filename = "activity-preview-nacos.md"
// fs.readFile(path.resolve(__dirname, '../src/content/blog/activity-preview-nacos.md'), 'utf8')
// .then(async data => {
// // let res = await askAI(data);
// // console.log(res)
// const keywordsRegex = /关键词:\s*"([^"]*)"/;
// const regDescrip = /描述信息:\s*"([^"]*)"/;
// const regContent = /翻译后的英文文章:\s*"([\s\S]*)"/;

// // const keywordsMatch = res.match(keywordsRegex);
// // const keywords = keywordsMatch ? keywordsMatch[1].trim() : '';
// // console.log("关键词:", keywords);

// // const descripMatch = res.match(regDescrip);
// // const description = descripMatch ? descripMatch[1].trim() : '';
// // console.log("描述信息:", description);

// // const contentMatch = res.match(regContent);
// // const content = contentMatch ? contentMatch[1].trim() : '';
// // console.log("翻译后的英文文章:\n", content);

// const keywords = "Nacos 0.1.0, Review活动, 社区交流, GitHub issue, 贡献流程, 小礼品奖励";
// const description = "文章概述了Nacos 0.1.0版本的Review活动设计,包括任务列表如官网与文档审查、功能测试、提供建议等,参与方式涉及加入社区微信群与提交GitHub issue,奖励机制鼓励突出贡献者,并强调沟通透明与建议采纳原则。";
// const content = `
// ---
// title: Nacos 0.1.0 Version Review Event Design
// keywords: [Nacos 0.1.0, Review event, community engagement, GitHub issue, contribution process, reward]
// description: This article outlines the design of the Nacos 0.1.0 version review event, featuring tasks such as reviewing official website and documentation, testing functionalities, and providing suggestions. It details participation methods including joining the community WeChat group and submitting GitHub issues, with a reward mechanism to incentivize notable contributors, emphasizing transparent communication and the principle of suggestion adoption.
// date: \"2018-11-15\"
// category: activity-preview
// ---

// # Nacos 0.1.0 Version Review Event Design

// ## I. Activity Task List

// - Review official content, identify bugs, and suggest improvements for both Chinese and English websites.
// - Read through the Chinese and English documentation, find errors, and propose enhancements, especially focusing on poor English translations.
// - Test the code compilation, Nacos server startup/shutdown流程, and suggest improvements.
// - Attempt to configure and launch multi-node Nacos cluster mode, offering improvement advice.
// - Utilize the Nacos Java SDK and provide feedback for enhancements.
// - Try the Nacos Open API and suggest improvements.
// - Follow the 'How to Contribute to Nacos Documentation TODO' guide, test the contribution process, and give feedback.
// - Submit requirements, development plans, ideas, and requests for Nacos.

// ## II. Participation Methods

// - Scan the WeChat QR code of 'Super Brother' to join the 'Nacos Community Chat Group'.
// - Choose one or more tasks from Section I.
// - Report issues or bugs found following the 'Issue Reporting Process' in Section III, assigning them to @github user[xuechaos](https://github.com/xuechaos).

// ## III. Issue Reporting Process

// * Process details TODO

// ## IV. Reward Mechanism

// * Customized small gifts are being prepared for contributors who make outstanding contributions, with consideration for shipping to those who stand out during the process.
// * The gifts, though modest, aim to express gratitude for your assistance.

// ## V. Additional Notes

// * Not every suggestion will necessarily be adopted, but we will endeavor to communicate our considerations if your suggestion is not implemented.
// * Prefer using email lists or reporting issues over reporting problems in the WeChat group to document and facilitate our communication process.`
// replaceZhContent(path.resolve(__dirname, '../src/content/blog/activity-preview-nacos.md'),data, keywords, description);
// // generateEnFile(filename, content )
// })

const replaceZhContent = async (filePath, data, keywords, description) => {
const keywordsRegex = /keywords: \[\s*([^"]*)\]\n/s;
const regDescrip = /description:\s*([^\n]*)\n/;
const oriKeywordMatch = data.match(keywordsRegex);
const originKeywords = oriKeywordMatch ? oriKeywordMatch[0].trim() : '';
const oriDescripMatch = data.match(regDescrip);
const originDescrip = oriDescripMatch ? oriDescripMatch[0].trim() : '';

const newData = data.replace(originKeywords,`keywords: [${keywords}]`).replace(originDescrip, `description: ${description}`);

try {
await fs.writeFile(filePath, newData, 'utf8');
console.log(`${filePath} 已被更新完成`);
} catch (err) {
console.error(err);
}
}

const generateEnFile = async (filename, content) => {
const enFilename = filename.replace('zh-cn', 'en');
try {
await fs.writeFile(enFilename, content, 'utf8');
console.log(`${enFilename} 已被生成`);
} catch (err) {
console.log("err",err)
}
}

await traverseDirectorySync(path.resolve(__dirname, '../src/content/docs/ebook/zh-cn'))




10 changes: 10 additions & 0 deletions script/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const request = async (url, method = "GET", headers = {}, body = {}) => {
const res = await fetch(url, { headers, method, body: JSON.stringify(body) });
if (!res.ok) throw new Error(res.statusText);
const data = await res.json();
if (data.error) {
throw new Error(data.error)
} else {
return data;
}
};
2 changes: 1 addition & 1 deletion src/content/blog/faq/NACOS-user-question-history10482.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Nacos旨在提升微服务平台的构建、部署与运维效率,不仅适用

## <font color="#FF0000">答疑服务说明:</font>

本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://opensource.alibaba.com/chatBot) 。 咨询其他产品的的问题
本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://answer.opensource.alibaba.com/docs/intro) 。 咨询其他产品的的问题

### 反馈
如问答有错漏,欢迎点:[差评](https://ai.nacos.io/user/feedbackByEnhancerGradePOJOID?enhancerGradePOJOId=13679)给我们反馈。
2 changes: 1 addition & 1 deletion src/content/blog/faq/NACOS-user-question-history10483.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Nacos作为一款动态服务发现、配置管理和服务管理平台,其核

## <font color="#FF0000">答疑服务说明:</font>

本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://opensource.alibaba.com/chatBot) 。 咨询其他产品的的问题
本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://answer.opensource.alibaba.com/docs/intro) 。 咨询其他产品的的问题

### 反馈
如问答有错漏,欢迎点:[差评](https://ai.nacos.io/user/feedbackByEnhancerGradePOJOID?enhancerGradePOJOId=13680)给我们反馈。
2 changes: 1 addition & 1 deletion src/content/blog/faq/NACOS-user-question-history10484.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Nacos与Zookeeper和Consul的主要区别可以从以下几个方面进行分析

## <font color="#FF0000">答疑服务说明:</font>

本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://opensource.alibaba.com/chatBot) 。 咨询其他产品的的问题
本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://answer.opensource.alibaba.com/docs/intro) 。 咨询其他产品的的问题

### 反馈
如问答有错漏,欢迎点:[差评](https://ai.nacos.io/user/feedbackByEnhancerGradePOJOID?enhancerGradePOJOId=13681)给我们反馈。
2 changes: 1 addition & 1 deletion src/content/blog/faq/NACOS-user-question-history10485.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Nacos的配置管理主要通过以下几个步骤工作:

## <font color="#FF0000">答疑服务说明:</font>

本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://opensource.alibaba.com/chatBot) 。 咨询其他产品的的问题
本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://answer.opensource.alibaba.com/docs/intro) 。 咨询其他产品的的问题

### 反馈
如问答有错漏,欢迎点:[差评](https://ai.nacos.io/user/feedbackByEnhancerGradePOJOID?enhancerGradePOJOId=13682)给我们反馈。
2 changes: 1 addition & 1 deletion src/content/blog/faq/NACOS-user-question-history10486.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Nacos支持的服务注册与发现功能包括:

## <font color="#FF0000">答疑服务说明:</font>

本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://opensource.alibaba.com/chatBot) 。 咨询其他产品的的问题
本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://answer.opensource.alibaba.com/docs/intro) 。 咨询其他产品的的问题

### 反馈
如问答有错漏,欢迎点:[差评](https://ai.nacos.io/user/feedbackByEnhancerGradePOJOID?enhancerGradePOJOId=13683)给我们反馈。
2 changes: 1 addition & 1 deletion src/content/blog/faq/NACOS-user-question-history10487.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Nacos的高可用性主要通过以下几个方面来保证:

## <font color="#FF0000">答疑服务说明:</font>

本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://opensource.alibaba.com/chatBot) 。 咨询其他产品的的问题
本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://answer.opensource.alibaba.com/docs/intro) 。 咨询其他产品的的问题

### 反馈
如问答有错漏,欢迎点:[差评](https://ai.nacos.io/user/feedbackByEnhancerGradePOJOID?enhancerGradePOJOId=13684)给我们反馈。
2 changes: 1 addition & 1 deletion src/content/blog/faq/NACOS-user-question-history10488.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Nacos主要支持以下存储介质:

## <font color="#FF0000">答疑服务说明:</font>

本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://opensource.alibaba.com/chatBot) 。 咨询其他产品的的问题
本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://answer.opensource.alibaba.com/docs/intro) 。 咨询其他产品的的问题

### 反馈
如问答有错漏,欢迎点:[差评](https://ai.nacos.io/user/feedbackByEnhancerGradePOJOID?enhancerGradePOJOId=13685)给我们反馈。
2 changes: 1 addition & 1 deletion src/content/blog/faq/NACOS-user-question-history10489.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ spring:
## <font color="#FF0000">答疑服务说明:</font>
本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://opensource.alibaba.com/chatBot) 。 咨询其他产品的的问题
本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://answer.opensource.alibaba.com/docs/intro) 。 咨询其他产品的的问题
### 反馈
如问答有错漏,欢迎点:[差评](https://ai.nacos.io/user/feedbackByEnhancerGradePOJOID?enhancerGradePOJOId=13686)给我们反馈。
2 changes: 1 addition & 1 deletion src/content/blog/faq/NACOS-user-question-history10490.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ keywords: ["Nacos","配置","动态刷新"]

## <font color="#FF0000">答疑服务说明:</font>

本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://opensource.alibaba.com/chatBot) 。 咨询其他产品的的问题
本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://answer.opensource.alibaba.com/docs/intro) 。 咨询其他产品的的问题

### 反馈
如问答有错漏,欢迎点:[差评](https://ai.nacos.io/user/feedbackByEnhancerGradePOJOID?enhancerGradePOJOId=13687)给我们反馈。
2 changes: 1 addition & 1 deletion src/content/blog/faq/NACOS-user-question-history10491.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Nacos的配置推送机制从UDP转向gRPC双向流,体现了从追求速度

## <font color="#FF0000">答疑服务说明:</font>

本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://opensource.alibaba.com/chatBot) 。 咨询其他产品的的问题
本内容经由技术专家审阅的用户问答的镜像生成,我们提供了<font color="#FF0000">专家智能答疑服务</font>,在<font color="#FF0000">页面的右下的浮窗”专家答疑“</font>。您也可以访问 : [全局专家答疑](https://answer.opensource.alibaba.com/docs/intro) 。 咨询其他产品的的问题

### 反馈
如问答有错漏,欢迎点:[差评](https://ai.nacos.io/user/feedbackByEnhancerGradePOJOID?enhancerGradePOJOId=13688)给我们反馈。
Loading

0 comments on commit e0f9f77

Please sign in to comment.