forked from microsoft/Solution-Accelerators
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetLinkIcon.ts
More file actions
43 lines (38 loc) · 1.57 KB
/
Copy pathgetLinkIcon.ts
File metadata and controls
43 lines (38 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const fileTypeIconMap: Record<string, string | null> = {
pptx: "/csa-sas-ext-landingpage/icons/PowerPoint.svg",
ppt: "/csa-sas-ext-landingpage/icons/PowerPoint.svg",
xlsx: "/csa-sas-ext-landingpage/icons/Excel.svg",
xls: "/csa-sas-ext-landingpage/icons/Excel.svg",
docx: "/csa-sas-ext-landingpage/icons/Word.svg",
doc: "/csa-sas-ext-landingpage/icons/Word.svg",
pdf: "/csa-sas-ext-landingpage/icons/pdf.svg",
default: null,
};
export const getLinkIcon = (href: string, fileType?: string): string | null => {
try {
if (fileType && fileTypeIconMap[fileType.toLowerCase()]) {
return fileTypeIconMap[fileType.toLowerCase()];
}
// Check for service-specific icons
try {
const urlObj = new URL(href);
const hostname = urlObj.hostname.toLowerCase();
if (hostname.includes('github.com')) return '/csa-sas-ext-landingpage/icons/github.svg';
if (hostname.includes('figma.com')) return '/csa-sas-ext-landingpage/icons/figma.svg';
if (hostname.includes('youtube.com')) return '/csa-sas-ext-landingpage/icons/youtube.svg';
if (hostname.includes('docs.microsoft.com')) return '/csa-sas-ext-landingpage/icons/docs.svg';
if (hostname.includes('learn.microsoft.com')) return '/csa-sas-ext-landingpage/icons/learn.svg';
} catch {
// Ignore URL parsing errors
}
// Check file extension
const extMatch = href.match(/\.(pptx?|xlsx?|docx?|pdf)$/i);
if (extMatch) {
const ext = extMatch[1].toLowerCase();
return fileTypeIconMap[ext] || null;
}
return null;
} catch {
return null;
}
};