Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
fix(components): fix iconPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Jun 5, 2022
1 parent 4499f14 commit 5f1ef7f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
2 changes: 0 additions & 2 deletions packages/components/src/client/components/FontIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -77,6 +78,10 @@ export const componentPlugin: Plugin<ComponentOptions> = (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"),
Expand Down
18 changes: 18 additions & 0 deletions packages/components/src/node/utils.ts
Original file line number Diff line number Diff line change
@@ -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 "";
};
1 change: 1 addition & 0 deletions packages/components/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ declare global {
const EXTERNAL_LINK_LOCALES: ExternalLinkLocaleConfig;
const PAGE_INFO_LOCALES: PageInfoLocaleConfig;
const PAGINATION_LOCALES: PaginationLocaleConfig;
const ICON_PREFIX: string;
}
18 changes: 18 additions & 0 deletions packages/components/src/types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ export interface ComponentOptions {
*/
externalLinkLocales?: LocaleConfig<ExternalLinkLocaleData>;

/**
* 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
*
Expand Down

0 comments on commit 5f1ef7f

Please sign in to comment.