Skip to content

Commit 9adbcd8

Browse files
author
undefined
committed
update
1 parent 2b8497a commit 9adbcd8

File tree

7 files changed

+111
-38
lines changed

7 files changed

+111
-38
lines changed

plugin/md/markdownToVue.ts

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export function createMarkdownToVueRenderFn(
5656
headers: data.headers,
5757
relativePath,
5858
content: escapeHtml(content),
59+
html,
5960
// TODO use git timestamp?
6061
lastUpdated: Math.round(fs.statSync(file).mtimeMs),
6162
};

src/components/DemoBox.vue

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<slot />
55
</section>
66
<section class="code-box-meta markdown">
7-
<div class="code-box-title">{{ title }}</div>
7+
<div class="code-box-title">
8+
<a :href="`#${sectionId}`">{{ title }}</a>
9+
</div>
810
<div class="code-box-description">
911
<slot v-if="isZhCN" name="description" />
1012
<slot v-else name="us-description" />
@@ -69,7 +71,7 @@
6971
<script lang="ts">
7072
import { GlobalConfig } from '@/App.vue';
7173
import { GLOBAL_CONFIG } from '@/SymbolKey';
72-
import { computed, defineComponent, inject, ref } from 'vue';
74+
import { computed, defineComponent, inject, onMounted, ref } from 'vue';
7375
import { CheckOutlined, SnippetsOutlined } from '@ant-design/icons-vue';
7476
export default defineComponent({
7577
props: {
@@ -89,6 +91,8 @@ export default defineComponent({
8991
.join('-')
9092
.replace('.vue', '')}`;
9193
});
94+
const addDemosInfo: any = inject('addDemosInfo');
95+
9296
const globalConfig = inject<GlobalConfig>(GLOBAL_CONFIG);
9397
const title = computed(
9498
() => props.jsfiddle?.title[globalConfig.isZhCN.value ? 'zh-CN' : 'en-US'],
@@ -116,6 +120,12 @@ export default defineComponent({
116120
'highlight-wrapper-expand': codeExpand.value,
117121
};
118122
});
123+
onMounted(() => {
124+
addDemosInfo({
125+
href: `#${sectionId.value}`,
126+
title,
127+
});
128+
});
119129
return {
120130
theme: 'light',
121131
type,

src/docs/button/demo/index.vue

+12-21
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
<template>
2-
<div>
3-
<demo-sort>
4-
<basic />
5-
<disabled />
6-
<ghost />
7-
<icon />
8-
<loading />
9-
<multiple />
10-
<size />
11-
<block />
12-
</demo-sort>
13-
</div>
2+
<demo-sort>
3+
<basic />
4+
<disabled />
5+
<ghost />
6+
<icon />
7+
<loading />
8+
<multiple />
9+
<size />
10+
<block />
11+
</demo-sort>
1412
</template>
1513
<script lang="ts">
1614
import Basic from './basic.vue';
@@ -26,15 +24,8 @@ import US from '../index.en-US.md';
2624
import { defineComponent } from 'vue';
2725
2826
export default defineComponent({
29-
// category: 'Components',
30-
// type: 'General',
31-
// zhType: '通用',
32-
// title: 'Button',
33-
// subtitle: '按钮',
34-
pageData: {
35-
cn: CN.pageData,
36-
us: US.pageData,
37-
},
27+
CN,
28+
US,
3829
components: {
3930
Basic,
4031
Disabled,

src/layouts/Demo.vue

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<template>
2+
<article class="markdown">
3+
<section class="markdown">
4+
<h1>
5+
{{ frontmatter.title }}
6+
<span v-if="isZhCN" class="subtitle">{{ frontmatter.subtitle }}</span>
7+
</h1>
8+
<section class="markdown" v-html="description"></section>
9+
</section>
10+
<section class="markdown">
11+
<h2>{{ $t('app.component.examples') }}</h2>
12+
</section>
13+
<slot />
14+
<section class="markdown api-container" v-html="api"></section>
15+
</article>
16+
</template>
17+
<script lang="ts">
18+
import { defineComponent, computed } from 'vue';
19+
export default defineComponent({
20+
name: 'Demo',
21+
props: ['pageData', 'isZhCN'],
22+
setup(props) {
23+
const frontmatter = computed(() => props?.pageData?.frontmatter || {});
24+
const docHtml = computed(() => {
25+
return props?.pageData?.html || '';
26+
});
27+
const description = computed(() => {
28+
return docHtml.value.split('<h2 id="api">API</h2>')[0];
29+
});
30+
const api = computed(() => {
31+
return `
32+
<h2 id="API"><span>API</span><a href="#API" class="anchor">#</a></h2>
33+
${docHtml.value.split('<h2 id="api">API</h2>')[1]}
34+
`;
35+
});
36+
return { frontmatter, description, api };
37+
},
38+
});
39+
</script>
40+
<style lang="less" scoped></style>

src/layouts/index.vue

+45-11
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
</template>
1919
<a-col :xxl="20" :xl="19" :lg="18" :md="18" :sm="24" :xs="24">
2020
<section :class="mainContainerClass">
21-
<router-view />
21+
<Demo v-if="isDemo" :pageData="pageData" :isZhCN="isZhCN">
22+
<component :is="matchCom" />
23+
</Demo>
24+
<router-view v-else />
2225
<a-affix v-if="headers.length" class="toc-affix" :offsetTop="20">
2326
<a-anchor>
2427
<a-anchor-link
2528
v-for="h in headers"
2629
:key="h.title"
27-
:href="`#${h.title}`"
30+
:href="h.href || `#${h.title}`"
2831
:title="h.title"
2932
></a-anchor-link>
3033
</a-anchor>
@@ -39,18 +42,20 @@
3942
<script lang="ts">
4043
import { GlobalConfig } from '@/App.vue';
4144
import { GLOBAL_CONFIG } from '@/SymbolKey';
42-
import { defineComponent, inject, computed } from 'vue';
45+
import { defineComponent, inject, computed, ref, provide, watch } from 'vue';
4346
import { useRoute, useRouter } from 'vue-router';
4447
import Header from './header/index.vue';
4548
import Footer from './Footer.vue';
4649
import Menu from './Menu.vue';
4750
import PrevAndNext from './PrevAndNext.vue';
51+
import Demo from './Demo.vue';
4852
export default defineComponent({
4953
name: 'Layout',
5054
setup() {
5155
const route = useRoute();
5256
const router = useRouter();
5357
const routes = router.getRoutes();
58+
const globalConfig = inject<GlobalConfig>(GLOBAL_CONFIG);
5459
const menus = computed(() => {
5560
const path = route.path;
5661
const category = path.split('/')[1];
@@ -59,6 +64,19 @@ export default defineComponent({
5964
.map(r => ({ ...r.meta, path: r.path.split(':lang')[0] }));
6065
});
6166
67+
const demos = ref([]);
68+
69+
provide('addDemosInfo', info => {
70+
demos.value.push(info);
71+
});
72+
73+
watch(
74+
() => route.path,
75+
() => {
76+
demos.value.length = 0;
77+
},
78+
);
79+
6280
const activeMenuItem = computed(() => {
6381
return route.path.split('-cn')[0];
6482
});
@@ -74,25 +92,41 @@ export default defineComponent({
7492
const matchCom = computed(() => {
7593
return route.matched[route.matched.length - 1]?.components?.default as any;
7694
});
77-
console.log(matchCom);
95+
const isZhCN = globalConfig.isZhCN;
96+
const pageData = computed(() =>
97+
isDemo.value
98+
? matchCom.value[isZhCN.value ? 'CN' : 'US']?.pageData
99+
: matchCom.value?.pageData,
100+
);
78101
const headers = computed(() => {
79-
return (matchCom.value?.pageData?.headers || []).filter(h => h.level === 2);
102+
if (isDemo.value) {
103+
return [...demos.value, { title: 'API', href: '#API' }];
104+
} else {
105+
return (pageData.value?.headers || []).filter(h => h.level === 2);
106+
}
80107
});
81-
const globalConfig = inject<GlobalConfig>(GLOBAL_CONFIG);
82-
return {
83-
isMobile: globalConfig.isMobile,
84-
isZhCN: globalConfig.isZhCN,
85-
mainContainerClass: {
108+
109+
const mainContainerClass = computed(() => {
110+
return {
86111
'main-container': true,
87112
'main-container-component': isDemo.value,
88-
},
113+
};
114+
});
115+
return {
116+
isMobile: globalConfig.isMobile,
117+
isZhCN,
118+
mainContainerClass,
89119
menus,
90120
currentMenuIndex,
91121
activeMenuItem,
92122
headers,
123+
isDemo,
124+
matchCom,
125+
pageData,
93126
};
94127
},
95128
components: {
129+
Demo,
96130
Header,
97131
Footer,
98132
Menu,

src/router/index.js

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ const routes = [
88
{
99
path: '/components',
1010
component: Layout,
11-
props: route => {
12-
const name = route.path.split('/components/')[1].split('/')[0];
13-
return { name, showDemo: true };
14-
},
1511
children: [
1612
{
1713
path: 'overview:lang(.*)',

typings/shared.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface PageData {
3131
frontmatter: Record<string, any>;
3232
lastUpdated: number;
3333
content?: string;
34+
html?: string;
3435
}
3536

3637
export interface Header {

0 commit comments

Comments
 (0)