This commit is contained in:
guochunsi
2025-12-31 17:40:01 +08:00
parent 6d94e91b70
commit 74c06bb8a0
713 changed files with 115034 additions and 46 deletions

View File

@@ -51,23 +51,41 @@ const getAwesomeIconfont = () => {
let sheetsList = [] as any[];
let sheetsIconList = [] as any[];
for (let i = 0; i < styles.length; i++) {
if (styles[i].href && styles[i].href.indexOf('font-awesome') > -1) {
// 支持检测 fontawesome 和 fortawesome
if (styles[i].href && (styles[i].href.indexOf('fontawesome') > -1 || styles[i].href.indexOf('fortawesome') > -1)) {
sheetsList.push(styles[i]);
}
}
for (let i = 0; i < sheetsList.length; i++) {
for (let j = 0; j < sheetsList[i].cssRules.length; j++) {
if (
sheetsList[i].cssRules[j].selectorText &&
sheetsList[i].cssRules[j].selectorText.indexOf('.fa-') === 0 &&
sheetsList[i].cssRules[j].selectorText.indexOf(',') === -1
) {
if (/::before/.test(sheetsList[i].cssRules[j].selectorText)) {
sheetsIconList.push(
`${sheetsList[i].cssRules[j].selectorText.substring(1, sheetsList[i].cssRules[j].selectorText.length).replace(/\:\:before/gi, '')}`
);
try {
for (let j = 0; j < sheetsList[i].cssRules.length; j++) {
const rule = sheetsList[i].cssRules[j];
if (rule.selectorText) {
// 支持 Font Awesome 7.x 新格式:.fa-solid, .fa-regular, .fa-brands, .fa-xxx
// 也支持旧格式:.fa-xxx
if (
(rule.selectorText.indexOf('.fa-solid') === 0 ||
rule.selectorText.indexOf('.fa-regular') === 0 ||
rule.selectorText.indexOf('.fa-brands') === 0 ||
rule.selectorText.indexOf('.fa-') === 0) &&
rule.selectorText.indexOf(',') === -1
) {
if (/::before/.test(rule.selectorText)) {
const iconClass = rule.selectorText
.substring(1, rule.selectorText.length)
.replace(/\:\:before/gi, '');
// 如果是新格式fa-solid fa-xxx只取图标名部分
const iconName = iconClass.replace(/^(fa-solid|fa-regular|fa-brands)\s+/, '');
if (iconName && !sheetsIconList.includes(iconName)) {
sheetsIconList.push(iconName);
}
}
}
}
}
} catch (e) {
// 跨域样式表可能无法访问,忽略错误
continue;
}
}
if (sheetsIconList.length > 0) resolve(sheetsIconList.reverse());