Skip to content

Commit

Permalink
chore(docs): 文档构建支持新的组件引入方式
Browse files Browse the repository at this point in the history
  • Loading branch information
ocean-gao committed Sep 26, 2023
1 parent 8c25b84 commit 6a6d00e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 26 deletions.
35 changes: 26 additions & 9 deletions docs/.vitepress/components/tag/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,62 @@ app.use(FTag);

### 基础用法

--BASIC
:::demo
basic.vue
:::

### 可移除标签

设置 `closable` 属性可以定义一个标签是否可移除。

--CLOSABLE
:::demo
closable.vue
:::

### 动态编辑标签

动态编辑标签可以通过点击标签关闭按钮后触发的 `close` 事件来实现

--EDIT
:::demo
edit.vue
:::

### 不同尺寸

Tag 组件提供了以下几种尺寸,可以在不同场景下选择合适的尺寸。

--SIZE
:::demo
size.vue
:::

### 不同主题

Tag 组件提供了三个不同的主题。

--THEME
:::demo
theme.vue
:::

### 带图标

--WITHICON
:::demo
withIcon.vue
:::

### 结合 Form 组件

--WITHFORM
:::demo
withForm.vue
:::

### 超长省略

--TOOLTIP
:::demo
tooltip.vue
:::

--CODE
:::code
:::

## Tag Props

Expand Down
8 changes: 1 addition & 7 deletions docs/.vitepress/scripts/constants.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
exports.SCRIPT_TEMPLATE = `
<script>
<script setup>
IMPORT_EXPRESSION
export default {
components: {
COMPONENTS
}
}
</script>
`;

Expand Down
29 changes: 19 additions & 10 deletions docs/.vitepress/scripts/genComponentDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,19 @@ async function genComponent(dir, name) {
tempCode[`${name}.${demoName}`] = rawCode;
tempCode[`${name}.${demoName}-code`] = await highlight(rawCode);

const matchStr = new RegExp(
`--${demoName.toLocaleUpperCase()}\\s`,
'i',
const dashMatchRegExp = new RegExp(`--${demoName}`, 'ig');
const nameMatchRegExp = new RegExp(
`:::demo[\\s]*${demoName}\.vue[\\s]*:::`,
'g',
);
if (matchStr.test(fileContent)) {
fileContent = fileContent.replace(
matchStr,
demoContent.join('\n\n\n'),
);

if (
dashMatchRegExp.test(fileContent) ||
nameMatchRegExp.test(fileContent)
) {
fileContent = fileContent
.replace(dashMatchRegExp, demoContent.join('\n\n\n'))
.replace(nameMatchRegExp, demoContent.join('\n\n\n'));
} else {
demoMDStrs.push(...demoContent);
}
Expand All @@ -131,13 +135,18 @@ async function genComponent(dir, name) {
const scriptStr = SCRIPT_TEMPLATE.replace(
'IMPORT_EXPRESSION',
scriptCode.imports.join('\n'),
).replace('COMPONENTS', scriptCode.components.join(',\n'));
);

demoMDStrs.push(scriptStr);

fse.outputFileSync(
output,
fileContent.replace('--CODE', demoMDStrs.join('\n\n')),
fileContent
.replace('--CODE', demoMDStrs.join('\n\n'))
.replace(
new RegExp(`:::code[\\s\\S]*:::`),
demoMDStrs.join('\n\n'),
),
);

if (Object.keys(tempCode).length) {
Expand Down

0 comments on commit 6a6d00e

Please sign in to comment.