From 138151bc30979eede459110315c18af91e79cef5 Mon Sep 17 00:00:00 2001 From: Ce1ling <2134045201@qq.com> Date: Thu, 5 Oct 2023 00:02:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(docs):=20=E6=96=B0=E5=A2=9E=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E9=A2=84=E8=A7=88=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/.vitepress/plugins/mdPlugin.ts | 13 +- docs/.vitepress/theme/styles/vars.scss | 1 + docs/.vitepress/vitepress/Demo.vue | 27 +-- .../vitepress/components/example/Example.vue | 2 +- docs/examples/Home/Home.vue | 167 ++++++++++++++++++ docs/examples/index.ts | 0 docs/index.md | 10 +- 7 files changed, 192 insertions(+), 28 deletions(-) create mode 100644 docs/examples/Home/Home.vue delete mode 100644 docs/examples/index.ts diff --git a/docs/.vitepress/plugins/mdPlugin.ts b/docs/.vitepress/plugins/mdPlugin.ts index 8767f9a..afb6804 100644 --- a/docs/.vitepress/plugins/mdPlugin.ts +++ b/docs/.vitepress/plugins/mdPlugin.ts @@ -4,12 +4,12 @@ import fs from 'fs' import path from 'path' import MarkdownIt from 'markdown-it' import mdContainer from 'markdown-it-container' + import { getDocsRoot } from '../utils/getDocsRoot' import { highlight } from '../utils/highlight' import type Token from 'markdown-it/lib/token' - interface ContainerOpts { validate?(params: string): boolean render?(tokens: Token[], index: number): string @@ -21,10 +21,10 @@ interface MdPlugin { export const mdPlugin: MdPlugin = (md, k = 'demo') => { // 匹配参数 k 开头,任意结尾的字符串 const reg = new RegExp(`^${k}\\s*(.*)$`) - + md.use(mdContainer, k, { // validate 返回 true 则 render,否则不会调用 render 函数 - validate: (params) => !!params.trim().match(reg), + validate: params => !!params.trim().match(reg), render(tokens, idx) { const m = tokens[idx].info.trim().match(reg) const title = (m && m[1]) ?? '' @@ -35,7 +35,7 @@ export const mdPlugin: MdPlugin = (md, k = 'demo') => { throw new Error(`错误的文件路径: "${filePath}"`) } const textFile = fs.readFileSync( - path.resolve(getDocsRoot(), 'examples', `${filePath}.vue`), + path.resolve(getDocsRoot(), 'examples', `${filePath}.vue`), 'utf-8' ) @@ -44,10 +44,11 @@ export const mdPlugin: MdPlugin = (md, k = 'demo') => { path="${filePath}" code="${encodeURIComponent(highlight(textFile, 'vue'))}" raw-code="${encodeURIComponent(textFile)}" + :is-home="${title === 'home'}" >` } else { return '' } - } + }, } as ContainerOpts) -} \ No newline at end of file +} diff --git a/docs/.vitepress/theme/styles/vars.scss b/docs/.vitepress/theme/styles/vars.scss index 9384998..94d2827 100644 --- a/docs/.vitepress/theme/styles/vars.scss +++ b/docs/.vitepress/theme/styles/vars.scss @@ -22,6 +22,7 @@ --doc-search-mask-color: #eeeeeeaa; --doc-search-modal-shadow-color: #555555; --doc-search-result-item-shadow-color: #ddd; + --doc-example-padding: 18px; --doc-example-header-bg-color: #ececec; --doc-example-border-color: #ececec; diff --git a/docs/.vitepress/vitepress/Demo.vue b/docs/.vitepress/vitepress/Demo.vue index 1ff0255..577ee4a 100644 --- a/docs/.vitepress/vitepress/Demo.vue +++ b/docs/.vitepress/vitepress/Demo.vue @@ -1,25 +1,29 @@ - - diff --git a/docs/.vitepress/vitepress/components/example/Example.vue b/docs/.vitepress/vitepress/components/example/Example.vue index 79b23b5..acd72db 100644 --- a/docs/.vitepress/vitepress/components/example/Example.vue +++ b/docs/.vitepress/vitepress/components/example/Example.vue @@ -17,4 +17,4 @@ defineProps<{ .example { padding: var(--doc-example-padding); } - \ No newline at end of file + diff --git a/docs/examples/Home/Home.vue b/docs/examples/Home/Home.vue new file mode 100644 index 0000000..992188b --- /dev/null +++ b/docs/examples/Home/Home.vue @@ -0,0 +1,167 @@ + + + + + diff --git a/docs/examples/index.ts b/docs/examples/index.ts deleted file mode 100644 index e69de29..0000000 diff --git a/docs/index.md b/docs/index.md index 7be3375..72b1d9f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -12,7 +12,7 @@ head: hero: name: Violet text: 一款基于 Vue3 的 UI 组件库 - tagline: 点击 “开始” 按钮,预览 Violet UI 组件。 + tagline: 点击 “开始” 按钮,查看 Violet 的所有组件。 actions: - theme: brand text: 开始 @@ -20,4 +20,10 @@ hero: - theme: alt text: 在 GitHub 上查看 link: https://github.com/Ce1ling/violet ---- \ No newline at end of file +--- + +::: demo home + +Home/Home + +:::