Skip to content

Commit 519c943

Browse files
committed
feat: add common markdown transform projects
1 parent 4cb4b9a commit 519c943

File tree

16 files changed

+329
-171
lines changed

16 files changed

+329
-171
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@
4646
"scss",
4747
"pcss",
4848
"postcss"
49-
]
49+
],
50+
"typescript.tsdk": "node_modules/typescript/lib"
5051
}

docs/.vitepress/components.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export {}
99
declare module 'vue' {
1010
export interface GlobalComponents {
1111
DemoDocsProjectList: typeof import('./theme/components/demo/DemoDocsProjectList.vue')['default']
12+
DocsProjectCard: typeof import('./../../packages/docs/client/components/DocsProjectCard.vue')['default']
13+
DocsProjectList: typeof import('./../../packages/docs/client/components/DocsProjectList.vue')['default']
1214
GitHubBadge: typeof import('./theme/components/GitHubBadge.vue')['default']
1315
SiteLinkBadge: typeof import('./theme/components/SiteLinkBadge.vue')['default']
16+
StatusBadge: typeof import('./theme/components/StatusBadge.vue')['default']
1417
}
1518
}

docs/.vitepress/config/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default defineConfig({
3434
{
3535
text: '应用项目',
3636
items: [
37+
{ text: 'Girid - 动画角色印象表', link: '/projects/girid' },
3738
{ text: 'Web Resume 简历', link: '/projects/web-resume' },
3839
{ text: '哔哩哔哩封面生成器', link: '/projects/bilibili-cover-generator' },
3940
],
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import type { Plugin } from 'vite'
2+
// node import
3+
import { replacer } from '../../../packages/docs/utils'
4+
5+
export function MarkdownTransform(): Plugin {
6+
return {
7+
name: 'yyj-docs:md-transform',
8+
enforce: 'pre',
9+
async transform(code, id) {
10+
if (!id.match(/\.md\b/)) {
11+
return null
12+
}
13+
14+
// 满足 /projects/*.md 的条件
15+
if (id.match(/\/projects\//)) {
16+
// const [projectsPath, _name] = id.split('/')
17+
// const name = _name.toLowerCase().slice(0, -3)
18+
19+
const frontmatterEnds = code.indexOf('---\n\n')
20+
const firstHeader = code.search(/\n#{2,6}\s.+/)
21+
const slideIndex = firstHeader < 0
22+
? (
23+
(frontmatterEnds < 0)
24+
? 0
25+
: frontmatterEnds + 4)
26+
: firstHeader
27+
28+
const { footer, header } = getProjectMarkdown()
29+
if (header) {
30+
code = code.slice(0, slideIndex) + header + code.slice(slideIndex)
31+
}
32+
33+
if (footer) {
34+
code = replacer(code, footer, 'footer', 'tail')
35+
}
36+
37+
return code
38+
}
39+
40+
// code =
41+
},
42+
}
43+
}
44+
45+
/**
46+
* 包裹项目介绍的 Markdown 额外信息
47+
*
48+
* 根据 frontmatter 中字段生成
49+
*/
50+
export function getProjectMarkdown() {
51+
const projectInfo = `
52+
# {{ $frontmatter.title }}
53+
54+
> {{ $frontmatter.description }}
55+
56+
当前状态:<StatusBadge :status="$frontmatter.status" />
57+
58+
<SiteLinkBadge :link="$frontmatter.link" />
59+
<GitHubBadge :repo="$frontmatter.repo" />
60+
`
61+
62+
const footer = ''
63+
const header = `${projectInfo}\n`
64+
65+
return {
66+
footer,
67+
header,
68+
}
69+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script setup lang="ts">
2+
import type { DocsProjectItem } from '../../types'
3+
import { computed } from 'vue'
4+
5+
const props = defineProps<{
6+
status: DocsProjectItem['status']
7+
}>()
8+
9+
const type = computed(() => {
10+
switch (props.status) {
11+
case 'dev':
12+
return 'warning'
13+
case 'prod':
14+
return 'tip'
15+
default:
16+
return 'info'
17+
}
18+
})
19+
</script>
20+
21+
<template>
22+
<Badge :type="type">
23+
{{ status }}
24+
</Badge>
25+
</template>

docs/.vitepress/types/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export interface DocsProjectItem {
2+
/**
3+
* 项目标题
4+
*/
5+
title: string
6+
/**
7+
* 项目描述
8+
*/
9+
description: string
10+
/**
11+
* 项目状态
12+
*/
13+
status: 'dev' | 'prod'
14+
/**
15+
* 项目仓库
16+
*
17+
* YunYouJun/docs -> https://github.com/YunYouJun/docs
18+
*/
19+
repo: string
20+
/**
21+
* 项目链接
22+
*/
23+
link: string
24+
}

docs/projects/bilibili-cover-generator.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
---
2+
title: 哔哩哔哩封面生成器
23
status: dev
34
repo: YunYouJun/bilibili-cover-generator
45
link: https://bilibili-cover-generator.yunyoujun.cn
56
---
67

7-
# 哔哩哔哩封面生成器
8-
9-
当前状态:<Badge type="warning">{{ $frontmatter.status }}</Badge>
10-
11-
<SiteLinkBadge :link="$frontmatter.link" />
12-
<GitHubBadge :repo="$frontmatter.repo" />
13-
148
## 背景
159

1610
我计划尝试在 B 站上投稿视频,并拟定了多个主题。

docs/projects/girid.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Girid - 动画角色印象表
3+
description: ❤ 动画角色喜好表生成器
4+
status: prod
5+
repo: YunYouJun/girid
6+
link: https://girid.yunyoujun.cn
7+
---
8+
9+
## Thanks
10+
11+
[YunYouJun/girid](https://github.com/YunYouJun/girid) inspired by [itorr/anime-grid](https://github.com/itorr/anime-grid).

docs/projects/web-resume.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
---
2+
title: Web Resume 简历生成器
3+
description: Web 端可打印为 PDF 的简历
24
status: prod
35
repo: YunYouJun/web-resume
46
link: https://web-resume.yunyoujun.cn/
57
---
68

7-
# Web Resume 简历生成器
8-
9-
> Web 端可打印为 PDF 的简历
10-
11-
当前状态:<Badge type="info">{{ $frontmatter.status }}</Badge>
12-
13-
<SiteLinkBadge :link="$frontmatter.link" />
14-
<GitHubBadge :repo="$frontmatter.repo" />
15-
169
## 使用
1710

1811
### 在线使用

docs/vite.config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { defineConfig } from 'vite'
2+
23
import { getViteConfig } from '../packages/docs/node'
4+
import { MarkdownTransform } from './.vitepress/plugins/markdownTransform'
35

46
const viteConfig = getViteConfig({})
57

6-
export default defineConfig({
7-
...viteConfig,
8+
viteConfig.plugins!.push(MarkdownTransform())
89

10+
export default defineConfig({
911
resolve: {
1012
alias: {
11-
'@yunyoujun/docs': '../packages/docs/index.ts',
13+
'@yunyoujun/docs': '../packages/docs/node/index.ts',
1214
},
1315
},
16+
17+
...viteConfig,
1418
})

0 commit comments

Comments
 (0)