diff --git a/packages/components/src/client/components/FontIcon.ts b/packages/components/src/client/components/FontIcon.ts index 0b799752b..a105c9a63 100644 --- a/packages/components/src/client/components/FontIcon.ts +++ b/packages/components/src/client/components/FontIcon.ts @@ -2,8 +2,6 @@ import Vue from "vue"; import type { VNode } from "vue"; -declare const ICON_PREFIX: string; - export interface FontIconProps { icon?: string; color?: string; diff --git a/packages/components/src/node/plugin.ts b/packages/components/src/node/plugin.ts index c9c24903a..218ebb930 100644 --- a/packages/components/src/node/plugin.ts +++ b/packages/components/src/node/plugin.ts @@ -5,6 +5,7 @@ import { paginationLocales, pageInfoLocales, } from "./locales"; +import { getIconPrefix } from "./utils"; import type { Plugin, PluginConfig } from "vuepress-typings"; import type { ComponentOptions } from "../types"; @@ -77,6 +78,10 @@ export const componentPlugin: Plugin = (options, context) => { config: options.paginationLocales, default: paginationLocales, }), + ICON_PREFIX: + typeof options.iconPrefix === "string" + ? options.iconPrefix + : getIconPrefix(options.iconAssets), }), enhanceAppFiles: path.resolve(__dirname, "../client/enhanceAppFile.js"), diff --git a/packages/components/src/node/utils.ts b/packages/components/src/node/utils.ts new file mode 100644 index 000000000..57e234490 --- /dev/null +++ b/packages/components/src/node/utils.ts @@ -0,0 +1,18 @@ +import { Logger } from "vuepress-shared"; + +export const logger = new Logger("vuepress-plugin-components"); + +export const getIconPrefix = (iconAssetsLink = ""): string => { + if ( + iconAssetsLink === "fontawesome" || + iconAssetsLink.match(/^(?:https:)?\/\/kit\.fontawesome\.com\//) + ) + return "fas fa-"; + if ( + iconAssetsLink === "iconfont" || + iconAssetsLink.match(/^(?:https:)?\/\/at\.alicdn\.com\/t\//) + ) + return "iconfont icon-"; + + return ""; +}; diff --git a/packages/components/src/types/index.d.ts b/packages/components/src/types/index.d.ts index a7cb54667..740b34330 100644 --- a/packages/components/src/types/index.d.ts +++ b/packages/components/src/types/index.d.ts @@ -18,4 +18,5 @@ declare global { const EXTERNAL_LINK_LOCALES: ExternalLinkLocaleConfig; const PAGE_INFO_LOCALES: PageInfoLocaleConfig; const PAGINATION_LOCALES: PaginationLocaleConfig; + const ICON_PREFIX: string; } diff --git a/packages/components/src/types/options.d.ts b/packages/components/src/types/options.d.ts index 6185267b2..eb69c3ab0 100644 --- a/packages/components/src/types/options.d.ts +++ b/packages/components/src/types/options.d.ts @@ -58,6 +58,24 @@ export interface ComponentOptions { */ externalLinkLocales?: LocaleConfig; + /** + * Link of font icon asset + * + * 字体图标资源链接 + * + * @description `'iconfont'` and `'font-awesome'` keywords are supported + */ + iconAssets?: string; + + /** + * Class prefix of font icon + * + * 字体图标的 Class 前缀 + * + * @default '' + */ + iconPrefix?: string; + /** * Whether register pageinfo component *