From 85fc35f11916b2e3460dd820a5a6cf38113458cf Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Mon, 19 Jan 2026 21:40:47 +0800 Subject: [PATCH] fix(theme): fix multiple icon provider (#826) --- theme/src/client/components/VPIcon.vue | 13 ++++++++++++- theme/src/node/prepare/prepareIcons.ts | 7 ++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/theme/src/client/components/VPIcon.vue b/theme/src/client/components/VPIcon.vue index 936b35d7..7c124f1c 100644 --- a/theme/src/client/components/VPIcon.vue +++ b/theme/src/client/components/VPIcon.vue @@ -29,6 +29,17 @@ const type = computed(() => { return 'svg' } + if (typeof name === 'string') { + if (name.startsWith('iconify')) + return 'iconify' + + if (name.startsWith('iconfont')) + return 'iconfont' + + if (name.startsWith('fontawesome')) + return 'fontawesome' + } + const _provider = provider || __MD_POWER_ICON_PROVIDER__ if (_provider === 'iconfont' || _provider === 'fontawesome') { return _provider @@ -55,7 +66,7 @@ const rect = computed(() => { return { width, height: height || width } }) const binding = computed(() => ({ - name: name as string, + name: (name as string).replace(/^(iconify|iconfont|fontawesome)\s+/, ''), color, size: rect.value, prefix: __MD_POWER_ICON_PREFIX__ as any, diff --git a/theme/src/node/prepare/prepareIcons.ts b/theme/src/node/prepare/prepareIcons.ts index cb51aae0..25860317 100644 --- a/theme/src/node/prepare/prepareIcons.ts +++ b/theme/src/node/prepare/prepareIcons.ts @@ -30,7 +30,7 @@ type IconDataMap = Record const ICON_REGEXP = /<(?:VP)?(Icon|Card|LinkCard|Button)([^>]*)>/g const ICON_NAME_REGEXP = /(?:name|icon|suffix-icon)="([^"]+)"/ const URL_CONTENT_REGEXP = /(url\([\s\S]+\))/ -const ICONIFY_NAME = /^[\w-]+:[\w-]+$/ +const ICONIFY_NAME = /^(?:iconify\s+)?[\w-]+:[\w-]+$/ const JS_FILENAME = 'internal/iconify.js' const CSS_FILENAME = 'internal/iconify.css' @@ -148,6 +148,7 @@ function isIconify(icon: unknown): icon is string { } function withPrefix(icon: string, prefix?: string): string { + icon = icon.replace(/^iconify /, '') if (!prefix) return icon return icon.includes(':') ? icon : `${prefix}:${icon}` @@ -166,7 +167,7 @@ function getIconsWithPage(page: Page, { provider = 'iconify', prefix }: IconOpti const addIcon = (icon: unknown): void => { if (icon && isIconify(icon) && (provider === 'iconify' || icon.startsWith('iconify'))) { - list.push(withPrefix(icon.replace(/^iconify /, ''), prefix)) + list.push(withPrefix(icon, prefix)) } } @@ -240,7 +241,7 @@ function getIconWithThemeConfig(options: ThemeOptions, { provider = 'iconify', p const addIcon = (icon: unknown): string | void => { if (icon && isIconify(icon) && (provider === 'iconify' || icon.startsWith('iconify'))) { - return withPrefix(icon.replace(/^iconify /, ''), prefix) + return withPrefix(icon, prefix) } }