Skip to content

Commit 767fd25

Browse files
authored
Refactor icon name and category handling logic
1 parent c490ed9 commit 767fd25

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

config/var/www/admin/control-panel/external-services/external-services.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -880,19 +880,24 @@ export class ExternalServicesManager {
880880
let iconName = null;
881881

882882
for (const part of parts) {
883-
// Font Awesome shorthand style prefixes: r=regular, s=solid, b=brands, d=duotone, l=light, t=thin (far/fas/fab/fad/fal/fat)
883+
// Font Awesome style prefixes: shorthand (far/fas/fab/fad/fal/fat) and longhand (fa-regular/fa-solid/fa-brands/fa-duotone/fa-light/fa-thin)
884884
if (/^fa[rsbdlt]$/.test(part) || /^fa-(solid|regular|brands|light|duotone|thin)$/.test(part)) {
885885
stylePrefix = part;
886886
continue;
887887
}
888888

889-
if (!iconName && /^fa-[a-z0-9-]+$/.test(part) && !FA_ICON_MODIFIER_PATTERN.test(part)) {
889+
if (!iconName && /^fa-[a-z0-9]+(?:-[a-z0-9]+)*$/.test(part) && !FA_ICON_MODIFIER_PATTERN.test(part)) {
890890
iconName = part;
891891
}
892892
}
893893

894894
if (!iconName) {
895-
iconName = sanitizeFaIconSuffix(value);
895+
const iconCandidates = parts.filter((part) =>
896+
!/^fa[rsbdlt]$/.test(part) &&
897+
!/^fa-(solid|regular|brands|light|duotone|thin)$/.test(part) &&
898+
!FA_ICON_MODIFIER_PATTERN.test(part)
899+
);
900+
iconName = sanitizeFaIconSuffix(iconCandidates.length ? iconCandidates[iconCandidates.length - 1] : "");
896901
}
897902

898903
return { stylePrefix, iconName };
@@ -1403,9 +1408,9 @@ export class ExternalServicesManager {
14031408

14041409
serviceKeys.forEach((key) => {
14051410
const definition = SERVICE_DEFINITIONS[key] || {};
1406-
const category = typeof definition.category === 'string' && definition.category.trim()
1407-
? definition.category.trim()
1408-
: 'Uncategorized';
1411+
const rawCategory = definition.category;
1412+
const trimmedCategory = typeof rawCategory === 'string' ? rawCategory.trim() : '';
1413+
const category = trimmedCategory || 'Uncategorized';
14091414

14101415
if (!servicesByCategory.has(category)) {
14111416
servicesByCategory.set(category, []);

0 commit comments

Comments
 (0)