Skip to content

Commit 8b14f29

Browse files
committed
perf: use Iconify for Vue
1 parent 85ba483 commit 8b14f29

File tree

14 files changed

+62
-26
lines changed

14 files changed

+62
-26
lines changed

packages/demo/.vitepress/config.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ export default defineConfigWithTheme<ThemeConfig>({
1616
'/posts/orange/': 'auto',
1717
'/posts/': 'auto',
1818
'/config/': 'auto',
19-
'/guide/': 'auto'
19+
'/guide/': 'auto',
20+
'/guide/apple/': [
21+
{
22+
text: 'apple-1',
23+
link: '/guide/apple/1.md',
24+
icon: 'i-vscode-icons-file-type-vite'
25+
}
26+
]
2027
},
2128
socialLinks: [
2229
{ icon: 'github', link: 'https://github.com/hacxy/vitepress-theme-mild' }

packages/demo/guide/apple/1.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
4+
# apple

packages/demo/guide/one.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
sidebar:
3+
sort: 1
4+
---

packages/demo/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"preview": "vitepress preview"
1414
},
1515
"devDependencies": {
16+
"@iconify-json/vscode-icons": "^1.2.10",
1617
"vitepress": "^1.6.1",
1718
"vitepress-theme-mild": "workspace:*"
1819
}

packages/docs/.vitepress/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default defineConfigWithTheme<ThemeConfig>({
6868
],
6969
sidebar: {
7070
'/guide/': 'auto',
71-
'/config/': 'auto'
71+
'/config/': 'auto',
7272
},
7373
footer: {
7474
message: 'MIT Licensed',

packages/theme/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"dependencies": {
3838
"@css-render/vue3-ssr": "^0.15.14",
3939
"@giscus/vue": "^3.1.1",
40+
"@iconify/vue": "^4.3.0",
4041
"@nanostores/vue": "^0.11.0",
4142
"@shikijs/vitepress-twoslash": "^1.24.3",
4243
"@vueuse/core": "^12.0.0",

packages/theme/src/client/components/ArticlesList.vue

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<script lang="ts" setup>
22
import type { ArticlesData } from '../datas/base.data.js';
3+
import { Icon } from '@iconify/vue';
34
import { NIcon, NList, NListItem, NSpace, NTag, NThing, NTime } from 'naive-ui';
45
import { useRouter } from 'vitepress';
5-
import IconCalendar from './icons/IconCalendar.vue';
6-
import IconClock from './icons/IconClock.vue';
7-
import IconWords from './icons/IconWords.vue';
86
97
const props = defineProps<{ listData: ArticlesData[], title?: string }>();
108
const router = useRouter();
@@ -47,17 +45,17 @@ const router = useRouter();
4745
<div class="VMArticleInfo">
4846
<div class="VMArticleInfoLeft">
4947
<div class="text">
50-
<IconCalendar />
48+
<Icon icon="mdi:calendar-edit-outline" />
5149
<span>
5250
<NTime :time="article.date" format="yyyy-MM-dd" />
5351
</span>
5452
</div>
5553
<div class="text">
56-
<IconWords />
54+
<Icon icon="tabler:pencil-minus" />
5755
{{ article.words }} words
5856
</div>
5957
<div class="text">
60-
<IconClock />
58+
<Icon icon="ic:sharp-access-time" />
6159
{{ article.minutes }} min
6260
</div>
6361
</div>

packages/theme/src/client/components/DocsHeaderInfo.vue

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<script lang="ts" setup>
2+
import { Icon } from '@iconify/vue';
23
import { NTime } from 'naive-ui';
34
import { useRoute } from 'vitepress';
45
import { ref, watchEffect } from 'vue';
56
import { useArticleListStore } from '../store/article';
6-
import IconCalendar from './icons/IconCalendar.vue';
7-
import IconClock from './icons/IconClock.vue';
8-
import IconWords from './icons/IconWords.vue';
97
108
const { articleList } = useArticleListStore();
119
const docsHeaderInfo = ref<{ words: number, minutes: number, date: number }>();
@@ -19,15 +17,15 @@ watchEffect(() => {
1917
<template>
2018
<div class="VMDocsHeaderInfo">
2119
<div class="info">
22-
<IconCalendar />
20+
<Icon icon="mdi:calendar-edit-outline" />
2321
<NTime :time="docsHeaderInfo?.date" format="yyyy-MM-dd" />
2422
</div>
2523
<div class="info">
26-
<IconWords />
24+
<Icon icon="tabler:pencil-minus" />
2725
<div>{{ docsHeaderInfo?.words }} words</div>
2826
</div>
2927
<div class="info">
30-
<IconClock />
28+
<Icon icon="ic:sharp-access-time" />
3129
<div>{{ docsHeaderInfo?.minutes }} min</div>
3230
</div>
3331
</div>

packages/theme/src/client/components/Layout.vue

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import LocalNav from './LocalNav.vue';
1212
import Sidebar from './Sidebar.vue';
1313
1414
import('virtual:group-icons.css');
15-
import('virtual:uno.css');
1615
1716
// Init data 不要在其他任何地方调用这个hook 否则会存在性能浪费问题
1817
const { np } = useInitData();

packages/theme/src/client/components/SidebarItem.vue

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<script setup lang="ts">
2-
import type { DefaultTheme } from 'vitepress/theme';
2+
import type { DefaultTheme } from 'vitepress';
33
import { computed } from 'vue';
44
import { useSidebarControl } from '../hooks/useSidebarControl';
55
import VPLink from './Link.vue';
66
77
const props = defineProps<{
8-
item: DefaultTheme.SidebarItem & { hide?: boolean }
8+
item: DefaultTheme.SidebarItem & {
9+
hide?: boolean
10+
icon?: string
11+
}
912
depth: number
1013
}>();
1114
const {

packages/theme/src/client/styles/index.scss

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import './variable.css';
22
@import 'nprogress/nprogress.css';
33
@import './slide-enter.css';
4+
// @import './icons.css';
45

56
.n-image-preview-container {
67
.n-image-preview-toolbar {

packages/theme/src/node/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Plugin, RawConfigExports, SiteConfig } from 'vitepress';
22
import type { ThemeConfig } from '../../types';
33
import { fileURLToPath } from 'node:url';
44
import { transformerTwoslash } from '@shikijs/vitepress-twoslash';
5-
import UnoCSS from 'unocss/vite';
65
import { groupIconMdPlugin, groupIconVitePlugin } from 'vitepress-plugin-group-icons';
76
import { RssPlugin } from 'vitepress-plugin-rss';
87
import { NOT_ARTICLE_LAYOUTS } from '../shared/constants';
@@ -58,7 +57,6 @@ const baseConfig: RawConfigExports<ThemeConfig> = {
5857
plugins: [
5958
groupIconVitePlugin(),
6059
rss(),
61-
UnoCSS() as any
6260
],
6361
build: {
6462
chunkSizeWarningLimit: 2048

packages/theme/types/index.d.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ import type { NProgressOptions } from 'nprogress';
33
import type { DefaultTheme, Theme } from 'vitepress';
44
import type { RSSOptions } from 'vitepress-plugin-rss';
55

6-
export interface SidebarAutoMulti {
7-
[path: string]: 'auto'
6+
export interface SidebarItem extends DefaultTheme.SidebarItem {
7+
icon?: string
88
}
99

10+
export interface SidebarMulti {
11+
[path: string]: SidebarItem[] | { items: SidebarItem[], base: string } | 'auto'
12+
}
13+
14+
export type Sidebar = SidebarItem[] | SidebarMulti;
15+
1016
export interface Comment extends Omit<GiscusProps, 'theme'> {
1117
lightTheme: GiscusTheme
1218
darkTheme: GiscusTheme
@@ -18,7 +24,7 @@ declare interface ThemeConfig extends DefaultThemeConfig {
1824
/**
1925
* The sidebar items.
2026
*/
21-
sidebar?: DefaultTheme.Sidebar | SidebarAutoMulti
27+
sidebar?: Sidebar
2228

2329
/**
2430
* Giscus Comment

pnpm-lock.yaml

+20-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)