Skip to content

Commit 0d03a28

Browse files
committed
feat(theme): 支持按需开启 group-icons 插件
1 parent 08d7c68 commit 0d03a28

File tree

9 files changed

+39
-8
lines changed

9 files changed

+39
-8
lines changed

packages/theme/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Patch Changes
66

7+
- feat: 支持按需开启 group-icons 插件
78
- fix: 一些 SVG 图标 iOS 不渲染
89
- fix: 日期在 iOS 上显示 NaN
910
- fix: 作品页样式塌陷

packages/theme/docs/.vitepress/blog-theme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const blogTheme = getThemeConfig({
1515
locales: {
1616
en: themeEN
1717
},
18+
// groupIcon: false,
1819
// formatShowDate: {
1920
// justNow: '不久前',
2021
// minutesAgo: ' minutes ago',

packages/theme/docs/changelog.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: 更新日志
3-
description: 最近更新(v0.5.5) ⏰ 2025/07/01:系列bug修复
3+
description: 最近更新(v0.5.5) ⏰ 2025/07/03:系列bug修复
44
author: 粥里有勺糖
55
top: 3
66
tag: 日志
@@ -27,10 +27,11 @@ bun install vitepress@latest
2727
```
2828
:::
2929

30-
## 0.5.5 (2025/07/01)
30+
## 0.5.5 (2025/07/03)
3131

3232
### Patch Changes
3333

34+
- feat: 支持按需开启 group-icons 插件
3435
- fix: 一些 SVG 图标 iOS 不渲染
3536
- fix: 日期在 iOS 上显示 NaN
3637
- fix: 作品页样式塌陷

packages/theme/docs/config/component.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ const blogTheme = getThemeConfig({
4747
})
4848
```
4949

50+
也可以关闭这个功能
51+
52+
```ts
53+
const blogTheme = getThemeConfig({
54+
groupIcon: false
55+
})
56+
```
57+
5058
## oml2d - 看板娘集成
5159
* Type:[oml2dOptions](https://oml2d.hacxy.cn/api/interfaces/Options.html)
5260

packages/theme/src/composables/config/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ export namespace Theme {
467467
imageStyle?: ImageStyleConfig
468468
groupIcon?: {
469469
customIcon: Record<string, string>
470-
}
470+
} | false
471471
}
472472

473473
export type FormatShowDate = {

packages/theme/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import UserWorksPage from './components/UserWorks.vue'
3535
// 内置一些特殊的主题色
3636
import './styles/theme/inline-theme.var.css'
3737

38-
// 导入group icons
39-
import 'virtual:group-icons.css'
38+
// 导入group icons,改由自定义插件导入
39+
// import 'virtual:group-icons.css'
4040

4141
export const BlogTheme: Theme = {
4242
...DefaultTheme,

packages/theme/src/utils/node/mdPlugins.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export function getMarkdownPlugins(cfg?: Partial<Theme.BlogConfig>) {
3232
markdownPlugin.push(timeline)
3333
}
3434

35-
markdownPlugin.push(groupIconMdPlugin)
35+
if (cfg?.groupIcon !== false) {
36+
markdownPlugin.push(groupIconMdPlugin)
37+
}
3638

3739
return markdownPlugin
3840
}

packages/theme/src/utils/node/vitePlugins.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,29 @@ export function getVitePlugins(cfg: Partial<Theme.BlogConfig> = {}) {
5656
}
5757

5858
// 内置支持 group icon
59-
60-
plugins.push(groupIconVitePlugin(cfg?.groupIcon))
59+
if (cfg?.groupIcon !== false) {
60+
plugins.push(patchGroupIconPlugin())
61+
plugins.push(groupIconVitePlugin(cfg?.groupIcon))
62+
}
6163

6264
return plugins
6365
}
6466

67+
export function patchGroupIconPlugin() {
68+
return {
69+
name: '@sugarat/theme-plugin-patch-group-icon',
70+
enforce: 'pre',
71+
transform(code: string, id: string) {
72+
// 匹配 theme/index.ts 或 theme/index.js 文件
73+
if (id.match(/[\/\\]theme[\/\\]index\.(ts|js)$/)) {
74+
// 在文件顶部插入 import 语句
75+
return `import 'virtual:group-icons.css'\n${code}`
76+
}
77+
return code
78+
}
79+
}
80+
}
81+
6582
export function registerVitePlugins(vpCfg: any, plugins: any[]) {
6683
vpCfg.vite = {
6784
plugins,

template/vitepress-plugin-slot-inject-template/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "vitepress-plugin-slot-inject-template",
33
"version": "0.1.0",
4+
"private": true,
45
"description": "vitepress plugin, slot template",
56
"author": "sugar",
67
"license": "MIT",

0 commit comments

Comments
 (0)