From e589e95fe1cbb9f65c4dede578f7e22a44706fb9 Mon Sep 17 00:00:00 2001 From: ocean-gao Date: Tue, 26 Sep 2023 10:42:12 +0800 Subject: [PATCH] =?UTF-8?q?chore(docs):=20=E6=96=87=E6=A1=A3=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=A2=9E=E5=8A=A0code=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/.vitepress/components/tag/index.md | 2 -- docs/.vitepress/scripts/genComponentDoc.js | 24 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/.vitepress/components/tag/index.md b/docs/.vitepress/components/tag/index.md index d0b44536..55586838 100644 --- a/docs/.vitepress/components/tag/index.md +++ b/docs/.vitepress/components/tag/index.md @@ -68,8 +68,6 @@ withForm.vue tooltip.vue ::: -:::code::: - ## Tag Props | 属性 | 说明 | 类型 | 默认值 | diff --git a/docs/.vitepress/scripts/genComponentDoc.js b/docs/.vitepress/scripts/genComponentDoc.js index 5925354e..71836cb5 100644 --- a/docs/.vitepress/scripts/genComponentDoc.js +++ b/docs/.vitepress/scripts/genComponentDoc.js @@ -113,18 +113,18 @@ async function genComponentExample(dir, name) { tempCode[`${name}.${demoName}-code`] = await highlight(rawCode); const dashMatchRegExp = new RegExp(`--${demoName}`, 'ig'); - const nameMatchRegExp = new RegExp( + const colonMatchRegExp = new RegExp( `:::demo[\\s]*${demoName}\.vue[\\s]*:::`, 'g', ); if ( dashMatchRegExp.test(fileContent) || - nameMatchRegExp.test(fileContent) + colonMatchRegExp.test(fileContent) ) { fileContent = fileContent .replace(dashMatchRegExp, demoContent.join('\n\n\n')) - .replace(nameMatchRegExp, demoContent.join('\n\n\n')); + .replace(colonMatchRegExp, demoContent.join('\n\n\n')); } else { demoMDStrs.push(...demoContent); } @@ -138,14 +138,22 @@ async function genComponentExample(dir, name) { demoMDStrs.push(scriptStr); + const dashCodeMatchRegExp = new RegExp(`--CODE`); + const colonCodeMatchRegExp = new RegExp(`:::code[\\s\\S]*:::`); + if ( + !( + dashCodeMatchRegExp.test(fileContent) || + colonCodeMatchRegExp.test(fileContent) + ) + ) { + const appendContent = '\n\n:::code:::\n\n'; + fileContent = fileContent + appendContent; + } fse.outputFileSync( output, fileContent - .replace('--CODE', demoMDStrs.join('\n\n')) - .replace( - new RegExp(`:::code[\\s\\S]*:::`), - demoMDStrs.join('\n\n'), - ), + .replace(dashCodeMatchRegExp, demoMDStrs.join('\n\n')) + .replace(colonCodeMatchRegExp, demoMDStrs.join('\n\n')), ); if (Object.keys(tempCode).length) {