Skip to content

Commit

Permalink
handle aliases and hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
stramel committed Nov 24, 2024
1 parent 83230c3 commit 3231e8b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 933 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
"@types/node": "^22.7.0",
"astro": "^5.0.0-beta.9",
"typescript": "^5.6.2",
"vite": "^5.4.8"
"vite": "^6.0.0-beta.6"
}
}
4 changes: 2 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AstroIntegration, ViteUserConfig } from "astro";
import type { AstroIntegration } from "astro";
import { createPlugin } from "./vite-plugin-astro-icon.js";

export default function createIntegration(): AstroIntegration {
Expand All @@ -18,7 +18,7 @@ export default function createIntegration(): AstroIntegration {
experimental: config.experimental,
}),
],
} as ViteUserConfig,
},
});
},
},
Expand Down
18 changes: 14 additions & 4 deletions packages/core/src/utils/icon.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AstroIntegrationLogger } from "astro";
import type { FileCache } from "./cache.js";
import { AstroIconError } from "./error.js";
import { dedupeFetch } from "./fetch.js";
Expand All @@ -7,11 +8,13 @@ interface IconCollection {
info: Record<string, string>;
lastModified: number;
icons: Record<string, IconData>;
aliases: Record<string, IconData>;
}
interface IconData {
body: string;
width?: number;
height?: number;
hidden?: boolean;
}

const ICONIFY_REPO = new URL(
Expand Down Expand Up @@ -55,12 +58,13 @@ async function fetchCollection(
export async function getIconData(
collection: string,
name: string,
{ cache }: { cache: FileCache }
{ cache, logger }: { cache: FileCache; logger: AstroIntegrationLogger }
): Promise<IconData | undefined> {
const collectionData = await fetchCollection(collection, { cache });

const { icons } = collectionData;
if (icons[name] === undefined) {
const { icons, aliases } = collectionData;
const icon = icons[name] ?? aliases[name];
if (icon === undefined) {
const err = new AstroIconError(
`Unable to locate the icon "${collection}:${name}"`
);
Expand All @@ -70,5 +74,11 @@ export async function getIconData(
throw err;
}

return icons[name];
if (icon.hidden) {
logger.warn(
`Deprecation Warning: The icon "${collection}:${name}" has been removed from the icon set.`
);
}

return icon;
}
2 changes: 1 addition & 1 deletion packages/core/src/vite-plugin-astro-icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function createPlugin({
const [collection, icon] = name.split("/");

try {
const data = await getIconData(collection, icon, { cache });
const data = await getIconData(collection, icon, { cache, logger });
if (!data) return;

const {
Expand Down
Loading

0 comments on commit 3231e8b

Please sign in to comment.