Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
"react": "^19.2.3",
"react-dom": "^19.2.3",
"shiki": "^4.0.1",
"simple-icons": "^16.2.0",
"svelte": "^5.46.1",
"tailwind-merge": "^3.4.0",
"tailwindcss": "^4.1.18",
Expand Down
62 changes: 5 additions & 57 deletions src/components/ui/icon/icon.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,23 @@ interface Props extends Omit<HTMLAttributes<'svg'>, 'name' | 'href'> {
const { name, href, ...rest } = Astro.props;

const hrefMap = {
'x.com': 'x',
twitter: 'twitter',
facebook: 'facebook',
instagram: 'instagram',
pinterest: 'pinterest',
youtube: 'youtube',
tiktok: 'tiktok',
snapchat: 'snapchat',
reddit: 'reddit',
tumblr: 'tumblr',
'wa.me': 'whatsapp',
telegram: 'telegram',
discord: 'discord',
vimeo: 'vimeo',
flickr: 'flickr',
yelp: 'yelp',
spotify: 'spotify',
behance: 'behance',
dribbble: 'dribbble',
soundcloud: 'soundcloud',
github: 'github',
twitch: 'twitch',
'tel:': 'phone',
'mailto:': 'mail',
'maps.app.goo.gl': 'map-pin',
linkedin: 'linkedin',
} as const;

const icons = import.meta.glob([
'node_modules/lucide-static/icons/*.svg',
'node_modules/simple-icons/icons/*.svg',
]);
const icons = import.meta.glob('node_modules/lucide-static/icons/*.svg');

// Get the right path from the icons glob
const foundPath = () => {
let foundPath: string | undefined = undefined;
// For x.com, we use the simple-icons X instead of the lucide-static X, since they overlap
if (name === 'x.com') {
foundPath = '/node_modules/simple-icons/icons/x.svg';
} else if (name) {
foundPath = Object.keys(icons).find((key) => key.includes(`/${name}.svg`));
if (name) {
return Object.keys(icons).find((key) => key.includes(`/${name}.svg`));
} else if (href) {
const hrefKey = Object.keys(hrefMap).find((key) => href.toString().includes(key)) || name;
const hrefValue = hrefMap[hrefKey as keyof typeof hrefMap];
const foundPath = Object.keys(icons)
// If href, reverse so that simple-icons takes precedence
.reverse()
.find((key) => key.includes(`/${hrefValue}.svg`));
return foundPath;
return Object.keys(icons).find((key) => key.includes(`/${hrefValue}.svg`));
}
// Else return the found path with lucide-icons taking precedence
return foundPath;
};

const foundModule = foundPath() && icons[foundPath() as keyof typeof icons];
Expand All @@ -69,21 +34,4 @@ const module = foundModule && ((await foundModule()) as any);
const Comp = module?.default;
---

{
Comp && foundPath()?.includes('simple-icons') && (
<Comp
height={24}
width={24}
fill="currentColor"
class="size-[1em] text-base"
aria-hidden="true"
{...rest}
/>
)
}

{
Comp && foundPath()?.includes('lucide-static') && (
<Comp height={24} width={24} class="size-[1em] text-base" aria-hidden="true" {...rest} />
)
}
{Comp && <Comp height={24} width={24} class="size-[1em] text-base" aria-hidden="true" {...rest} />}
Loading