From b43b717f6c0bf6f74664ab3ad710e78529ec1da0 Mon Sep 17 00:00:00 2001 From: eyworldwide Date: Tue, 23 Apr 2024 15:22:06 +0800 Subject: [PATCH] fix: excel script links bug --- scripts/md2excel.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/md2excel.js b/scripts/md2excel.js index 561e9fb2e..8146e3ead 100644 --- a/scripts/md2excel.js +++ b/scripts/md2excel.js @@ -5,7 +5,11 @@ const XLSX = require('xlsx'); const data = []; -const reg = /---\n([\s\S]*?)\n---/; +// yaml content +const yamlReg = /---\n([\s\S]*?)\n---/; +const docLinkReg = /\${docs}/g; +const apiLinkReg = /\${api}/g; +const exampleLinkReg = /\${examples}/g; async function readFiles(dir) { try { @@ -25,10 +29,17 @@ async function readFiles(dir) { } async function readMarkdownFile(file, filePath) { - const content = await fs.readFile(filePath, 'utf8'); - const yamlContent = content.match(reg)[1]; + let content = await fs.readFile(filePath, 'utf8'); + const yamlContent = content.match(yamlReg)[1]; const { title, type, group } = yaml.load(yamlContent); + // remove yaml content + content = content.replace(yamlReg, ''); + + // replace links + content = content.replace(docLinkReg, 'https://galacean.antgroup.com/engine/docs/latest/cn/') + content = content.replace(apiLinkReg, 'https://galacean.antgroup.com/engine/api/latest/') + content = content.replace(exampleLinkReg, 'https://galacean.antgroup.com/engine/examples/latest/') data.push({ // directory: group ? `${type}-${group}` : type, @@ -38,7 +49,7 @@ async function readMarkdownFile(file, filePath) { extends: '', refs: '', format: 'Markdown', - content: content.replace(reg, ''), + content, remarks: `官网文档: https://galacean.antgroup.com/engine/docs/latest/cn/${file.replace(/(\.zh-CN)?\.md$/, '')}` }) }