Skip to content

Commit

Permalink
chore(docs): 文档自动增加code逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
ocean-gao committed Sep 26, 2023
1 parent eb05535 commit e589e95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 0 additions & 2 deletions docs/.vitepress/components/tag/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ withForm.vue
tooltip.vue
:::

:::code:::

## Tag Props

| 属性 | 说明 | 类型 | 默认值 |
Expand Down
24 changes: 16 additions & 8 deletions docs/.vitepress/scripts/genComponentDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down

0 comments on commit e589e95

Please sign in to comment.