Skip to content

Commit 330e8c7

Browse files
docs: ✏️ 文档新增演示页面源码和组件源码链接
1 parent a40dd9f commit 330e8c7

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

docs/.vitepress/config.mts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
/*
22
* @Author: weisheng
33
* @Date: 2023-07-27 10:26:09
4-
* @LastEditTime: 2024-11-03 13:30:06
4+
* @LastEditTime: 2024-11-09 21:52:24
55
* @LastEditors: weisheng
66
* @Description:
7-
* @FilePath: \wot-design-uni\docs\.vitepress\config.mts
7+
* @FilePath: /wot-design-uni/docs/.vitepress/config.mts
88
* 记得注释
99
*/
1010
import { defineConfig } from 'vitepress';
1111
import viteCompression from 'vite-plugin-compression'
1212

13+
import { MarkdownTransform } from './plugins/markdown-transform'
14+
15+
1316
export default defineConfig({
1417
vite: {
1518
plugins: [
19+
MarkdownTransform(),
1620
viteCompression({
1721
verbose: true,
1822
disable: false,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { Plugin } from 'vite'
2+
import { camelCase } from '../../../src/uni_modules/wot-design-uni/components/common/util'
3+
import path from 'path'
4+
export function MarkdownTransform(): Plugin {
5+
return {
6+
name: 'md-transform',
7+
enforce: 'pre',
8+
async transform(code, id) {
9+
if (!id.endsWith('.md')) return
10+
if (!code.includes('<frame/>')) return
11+
const GITHUB_URL = 'https://github.com/Moonofweisheng/wot-design-uni/tree/master'
12+
const componentId = path.basename(id, '.md')
13+
const componentName = `wd-${componentId}`
14+
const camelComponentId = camelCase(componentId)
15+
const demoUrl = `${GITHUB_URL}/src/pages/${camelComponentId}`
16+
const componentUrl = `${GITHUB_URL}/src/uni_modules/wot-design-uni/components/${componentName}`
17+
return {
18+
code:`${code}\n## 源代码\n<ExternalLink href=${demoUrl}>文档</ExternalLink> • <ExternalLink href=${componentUrl}>组件</ExternalLink>`
19+
}
20+
},
21+
}
22+
}
23+
24+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<script setup lang="ts">
2+
import { defineComponent, h } from 'vue';
3+
defineProps({
4+
href: {
5+
type: String,
6+
required: true
7+
}
8+
})
9+
10+
const ExternalLinkIconComponent = defineComponent({
11+
name: 'ExternalLinkIcon',
12+
render() {
13+
const ExternalLinkIcon = {
14+
template: `
15+
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
16+
<g fill="none">
17+
<path d="m12.593 23.258l-.011.002l-.071.035l-.02.004l-.014-.004l-.071-.035q-.016-.005-.024.005l-.004.01l-.017.428l.005.02l.01.013l.104.074l.015.004l.012-.004l.104-.074l.012-.016l.004-.017l-.017-.427q-.004-.016-.017-.018m.265-.113l-.013.002l-.185.093l-.01.01l-.003.011l.018.43l.005.012l.008.007l.201.093q.019.005.029-.008l.004-.014l-.034-.614q-.005-.018-.02-.022m-.715.002a.02.02 0 0 0-.027.006l-.006.014l-.034.614q.001.018.017.024l.015-.002l.201-.093l.01-.008l.004-.011l.017-.43l-.003-.012l-.01-.01z" />
18+
<path fill="currentColor" d="M11 6a1 1 0 1 1 0 2H5v11h11v-6a1 1 0 1 1 2 0v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2zm9-3a1 1 0 0 1 1 1v5a1 1 0 1 1-2 0V6.414l-8.293 8.293a1 1 0 0 1-1.414-1.414L17.586 5H15a1 1 0 1 1 0-2Z" />
19+
</g>
20+
</svg>
21+
`
22+
};
23+
24+
return h('div', {
25+
innerHTML: ExternalLinkIcon.template,
26+
})
27+
}
28+
})
29+
</script>
30+
31+
<template>
32+
<el-link :href="href" style="text-decoration: none;font-size: 1.2em;" :underline="false">
33+
<slot />
34+
<ExternalLinkIconComponent style="margin-left: 0.25em;"> </ExternalLinkIconComponent>
35+
</el-link>
36+
</template>

docs/.vitepress/theme/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
22
* @Author: weisheng
33
* @Date: 2024-10-12 22:09:33
4-
* @LastEditTime: 2024-11-03 13:26:13
4+
* @LastEditTime: 2024-11-09 23:03:07
55
* @LastEditors: weisheng
66
* @Description:
7-
* @FilePath: \wot-design-uni\docs\.vitepress\theme\index.ts
7+
* @FilePath: /wot-design-uni/docs/.vitepress/theme/index.ts
88
* 记得注释
99
*/
1010
import { h } from 'vue'
@@ -19,6 +19,7 @@ import CustomFooter from './components/CustomFooter.vue'
1919
import SvgImage from './components/SvgImage.vue'
2020
import HomeStar from './components/HomeStar.vue'
2121
import frame from './components/frame.vue'
22+
import ExternalLink from './components/ExternalLink.vue'
2223
import ElementPlus from 'element-plus'
2324
import 'element-plus/dist/index.css'
2425

@@ -36,6 +37,7 @@ export default {
3637
enhanceApp({ app }) {
3738
app.component('SvgImage', SvgImage)
3839
app.component('frame', frame)
40+
app.component('ExternalLink',ExternalLink)
3941
app.use(ElementPlus)
4042
},
4143
}

0 commit comments

Comments
 (0)