~repos /website
git clone https://pyrossh.dev/repos/website.git
木 Personal website of pyrossh. Built with astrojs, shiki, vite.
53c5f5a3
—
pyrossh 2 weeks ago
fix file icon
- src/components/RecursiveList.astro +1 -5
- src/utils/files.ts +23 -3
src/components/RecursiveList.astro
CHANGED
|
@@ -56,11 +56,7 @@ const { items, repoId, depth = 0 } = Astro.props;
|
|
|
56
56
|
<li class="file" style={`padding-left: ${depth * 1}rem;`}>
|
|
57
57
|
<div class="file-content">
|
|
58
58
|
<div class="file-name">
|
|
59
|
-
<Icon
|
|
60
|
-
|
|
59
|
+
<Icon name={`vscode-icons:${fileType}`} size="18px" />
|
|
61
|
-
size="24px"
|
|
62
|
-
color="hsl(0deg 75% 75%)"
|
|
63
|
-
/>
|
|
64
60
|
<a href={`/repos/${repoId}/files/${item.path}`} rel="nofollow">
|
|
65
61
|
{item.name}
|
|
66
62
|
</a>
|
src/utils/files.ts
CHANGED
|
@@ -87,22 +87,42 @@ export const resolveFolderIcon = (foldername: string) => {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
export const resolveFileIcon = (filename: string, fileExt: string) => {
|
|
90
|
+
const baseName = filename.split('/').pop() || filename;
|
|
91
|
+
|
|
92
|
+
// First check for exact filename matches
|
|
90
93
|
for (const item of fileExtensions.supported) {
|
|
91
|
-
if (item.filename && item.extensions?.includes(
|
|
94
|
+
if (item.filename && item.extensions?.includes(baseName)) {
|
|
92
95
|
return item.icon;
|
|
93
96
|
}
|
|
94
97
|
}
|
|
98
|
+
|
|
99
|
+
// Then check for extension matches (more specific than language extensions)
|
|
95
100
|
for (const item of fileExtensions.supported) {
|
|
96
101
|
if (item.extensions?.includes(fileExt)) {
|
|
97
102
|
return item.icon;
|
|
98
103
|
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Check for language-specific extensions, prioritizing exact language ID matches
|
|
107
|
+
for (const item of fileExtensions.supported) {
|
|
108
|
+
for (const lang of item.languages ?? []) {
|
|
109
|
+
if (lang?.knownExtensions?.includes(fileExt)) {
|
|
110
|
+
const langIds = Array.isArray(lang.ids) ? lang.ids : [lang.ids];
|
|
111
|
+
if (langIds.includes(fileExt)) {
|
|
112
|
+
return item.icon;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Fallback to any language extension match
|
|
119
|
+
for (const item of fileExtensions.supported) {
|
|
99
120
|
for (const lang of item.languages ?? []) {
|
|
100
121
|
if (lang?.knownExtensions?.includes(fileExt)) {
|
|
101
122
|
return item.icon;
|
|
102
123
|
}
|
|
103
124
|
}
|
|
104
125
|
}
|
|
126
|
+
|
|
105
127
|
return fileExtensions.default.file?.icon;
|
|
106
128
|
}
|
|
107
|
-
|
|
108
|
-
console.log(resolveFileIcon('examples/public/index.html', 'html'));
|