Skip to content

Commit

Permalink
fix: improve icon algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 20, 2024
1 parent c4a31e6 commit 3ee3a0e
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/client/components/FileIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ const props = defineProps<{
filename: string
}>()
const ext = computed(() => {
let file = props.filename
file = file
.replace(/(\?|&)v=[^&]*/, '$1')
.replace(/\?$/, '')
if (file.match(/[\\/]node_modules[\\/]/))
return 'node_modules'
return file.split('.').pop().toLowerCase()
})
const map = {
angular: 'i-catppuccin-angular',
vue: 'i-catppuccin-vue',
Expand All @@ -40,10 +28,29 @@ const map = {
yaml: 'i-catppuccin-yaml',
toml: 'i-catppuccin-toml',
svg: 'i-catppuccin-svg',
node_modules: 'i-catppuccin-folder-node-open',
}
} as Record<string, string>
const icon = computed(() => map[ext.value] || 'i-catppuccin-file')
const icon = computed(() => {
let file = props.filename
file = file
.replace(/(\?|&)v=[^&]*/, '$1')
.replace(/\?$/, '')
if (file.match(/[\\/]node_modules[\\/]/))
return 'i-catppuccin-folder-node-open'
let ext = (file.split('.').pop() || '').toLowerCase()
let icon = map[ext]
if (icon)
return icon
ext = ext.split('?')[0]
icon = map[ext]
if (icon)
return icon
return 'i-catppuccin-file'
})
</script>

<template>
Expand Down

0 comments on commit 3ee3a0e

Please sign in to comment.