Skip to content

Commit b869cd7

Browse files
committed
feat: 增加演示Demo展示入口,优化配置文件
1 parent e0ed815 commit b869cd7

File tree

5 files changed

+59
-32
lines changed

5 files changed

+59
-32
lines changed

.vitepress/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ export default defineConfig({
140140
rewrites: {
141141
':packages/:pkg/README.md': ':packages/:pkg/index.md',
142142
':packages/:pkg/CHANGELOG.md': 'changelogs/:pkg/changelog.md',
143+
':apps/:pkg/README.md': ':apps/:pkg/index.md',
144+
':apps/:pkg/CHANGELOG.md': 'changelogs/:pkg/changelog.md',
143145
'CHANGELOG.md': 'changelogs/core-x/changelog.md',
144146
'README.md': 'index.md',
145147
},
@@ -148,6 +150,7 @@ export default defineConfig({
148150
resolve: {
149151
alias: {
150152
'@packages': path.resolve(__dirname, '../packages'),
153+
'@apps': path.resolve(__dirname, '../apps'),
151154
},
152155
},
153156
plugins: [

.vitepress/sidebar.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum ProjectId {
88
Nest = 'Nest.js框架',
99
Blog = '博客工具',
1010
Infra = '工程化',
11+
Demo = '演示Demo',
1112
}
1213

1314
/**
@@ -61,24 +62,47 @@ export const sidebarConfig: DefaultTheme.SidebarItem[] = [
6162
{ text: '@142vip/vuepress', link: '/packages/vuepress/index.md' },
6263
],
6364
},
65+
{
66+
text: `🎮 ${ProjectId.Demo}`,
67+
items: [
68+
{ text: 'vitepress-demo', link: '/apps/vitepress-demo/index.md' },
69+
{ text: 'vuepress-demo', link: '/apps/vuepress-demo/index.md' },
70+
],
71+
},
6472
]
6573

6674
/**
6775
* 获取基本包信息
6876
* - 注意目录格式,例如:@packages/utils
6977
*/
7078
async function getBasePkgJSON(pkgDirName: string) {
79+
// 参考格式:@packages/xxx @apps/xxx
80+
7181
const pkgJSON = await import(`@packages/${pkgDirName}/package.json`)
7282
return pick(pkgJSON, ['name', 'description', 'version', 'private'])
7383
}
7484

85+
/**
86+
* 获取apps目录下的模块
87+
* - @apps/vitepress-demo
88+
*/
89+
async function getAppsPkgJSON(pkgDirName: string) {
90+
// 参考格式:@packages/xxx @apps/xxx
91+
const pkgJSON = await import(`@apps/${pkgDirName}/package.json`)
92+
return pick(pkgJSON, ['name', 'description', 'version', 'private'])
93+
}
94+
7595
/**
7696
* 动态获取模块信息
7797
* - 注意:遍历侧边栏
7898
*/
7999
export async function getCoreProjectData(): Promise<VipProject[]> {
80100
const coreProjects: VipProject[] = []
81101
for (const { items, text } of sidebarConfig) {
102+
// 过滤掉apps下的模块
103+
if (text?.includes(ProjectId.Demo)) {
104+
continue
105+
}
82106
for (const { text: pkgName } of items) {
83107
const pkgDirName = pkgName.split('@142vip/')[1]
84108
const basePkg = await getBasePkgJSON(`${pkgDirName}`)
@@ -95,14 +119,36 @@ export async function getCoreProjectData(): Promise<VipProject[]> {
95119
return coreProjects
96120
}
97121

122+
/**
123+
* demo项目
124+
*/
125+
export async function getExampleDemoTableData() {
126+
const pkgNames = ['vuepress-demo', 'vitepress-demo']
127+
128+
const exampleDemos = []
129+
for (const pkgDirName of pkgNames) {
130+
const pkg = await getAppsPkgJSON(`${pkgDirName}`)
131+
exampleDemos.push({
132+
...pkg,
133+
private: true,
134+
id: '🤡',
135+
changelog: `../apps/${pkgDirName}/changelog.html`,
136+
readme: `../apps/${pkgDirName}/index.html`,
137+
sourceCode: `https://github.com/142vip/core-x/tree/main/apps/${pkgDirName}/`,
138+
})
139+
}
140+
return exampleDemos
141+
}
142+
98143
/**
99144
* 根据侧边栏获取变更日志侧边栏
100145
*/
101146
export function getChangelogsSidebar() {
102147
const changelogsSidebar: DefaultTheme.SidebarItem[] = []
103148
for (const { items } of sidebarConfig) {
104149
for (const { text: pkgName } of items) {
105-
const pkgDirName = pkgName.split('@142vip/')[1]
150+
// 兼容apps目录
151+
const pkgDirName = pkgName?.includes('@142vip') ? pkgName.split('@142vip/')[1] : pkgName
106152
changelogsSidebar.push({
107153
text: pkgName,
108154
link: `/changelogs/${pkgDirName}/changelog.md`,

.vitepress/theme/components/HomePage.vue

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import {
88
} from '@142vip/vitepress/components'
99
import { useData } from 'vitepress'
1010
import { ElImage } from 'element-plus'
11-
import { getCoreProjectData } from '../../sidebar'
12-
import vuepressDemo from '../../../apps/vuepress-demo/package.json'
11+
import { getCoreProjectData, getExampleDemoTableData } from '../../sidebar'
1312
1413
const { isDark } = useData()
15-
const tableData = ref<any[]>([])
14+
const coreProjectTableData = ref<any[]>([])
1615
const exampleDemoTableData = ref()
1716
1817
defineComponent({
@@ -21,38 +20,20 @@ defineComponent({
2120
},
2221
})
2322
24-
function pick<T, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {
25-
const result: any = {}
26-
for (const key of keys) {
27-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
28-
result[key] = obj[key]
29-
}
30-
}
31-
return result as Pick<T, K>
32-
}
33-
3423
/**
3524
* 异步加载表格数据
3625
*/
3726
onMounted(async () => {
38-
tableData.value = await getCoreProjectData()
39-
exampleDemoTableData.value = [
40-
{
41-
...pick(vuepressDemo, ['name', 'description', 'version', 'private']),
42-
id: '🤡',
43-
changelog: '../apps/vuepress-demo/changelog.html',
44-
readme: '../apps/vuepress-demo/index.html',
45-
sourceCode: ``,
46-
},
47-
]
27+
coreProjectTableData.value = await getCoreProjectData()
28+
exampleDemoTableData.value = await getExampleDemoTableData()
4829
})
4930
</script>
5031

5132
<!-- 首页 -->
5233
<template>
5334
<section id="version-table">
54-
<VipProjectTable :data="exampleDemoTableData" title="示例项目" />
55-
<VipProjectTable :data="tableData" title="开源模块" />
35+
<VipProjectTable :data="exampleDemoTableData" title="演示Demo" />
36+
<VipProjectTable :data="coreProjectTableData" title="开源模块" />
5637
</section>
5738

5839
<VipTeam />

apps/vitepress-demo/CHANGELOG.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ All notable changes to this project will be documented in this file. See [commit
44

55
<!-- #region recent-alpha -->
66

7-
8-
9-
<!-- #endregion recent-alpha -->
10-
117
## v0.0.1-alpha.1 (2024-10-17)
128

139
### ✨ Features
1410

1511
- 增加`vitepress-demo`演示模块,简化`@142vip/vitepress`模块使用配置 &nbsp;-&nbsp; by **chufan** [<samp>(f6797)</samp>](https://github.com/142vip/core-x/commit/f679759)
1612

17-
**Release New Version v0.0.1-alpha.1 [👉 View New Package On NPM](https://www.npmjs.com/package/vitepress-demo)**
13+
**Release New Version v0.0.1-alpha.1 [👉 View New Package On NPM](https://www.npmjs.com/package/vitepress-demo)**
14+
15+
<!-- #endregion recent-alpha -->

apps/vuepress-demo/vuepress.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export default defineUserConfig({
3838
return str
3939
},
4040
},
41-
// md doc formatter headerDepth
4241
headers: {
4342
level: [2, 3, 4],
4443
},

0 commit comments

Comments
 (0)