Skip to content

Commit 1562010

Browse files
committedNov 14, 2024
fix: add custom collections prefixes to runtime config
1 parent 7c03b9b commit 1562010

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed
 

‎playground/components/ShowcaseFixture.vue

+10-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,16 @@ defineProps<{
8282
Custom icons with `prefix: ''` from local fs:
8383
<Icon
8484
name="nuxt-v3"
85-
size="64"
85+
size="32"
86+
:mode
87+
:customize
88+
/>
89+
</p>
90+
<p>
91+
Custom icons with `prefix: 'custom-parts'` from local fs:
92+
<Icon
93+
name="custom-parts-nuxt-v3"
94+
size="32"
8695
:mode
8796
:customize
8897
/>
Loading

‎playground/nuxt.config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export default defineNuxtConfig({
4141
prefix: 'custom1',
4242
dir: './icons/custom1',
4343
},
44+
{
45+
prefix: 'custom-parts',
46+
dir: './icons/custom-parts',
47+
},
4448
{
4549
prefix: '',
4650
dir: './icons/no-prefix',

‎src/context.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,22 @@ export class NuxtIconModuleContext {
2020
) {}
2121

2222
getRuntimeCollections(runtimeOptions: NuxtIconRuntimeOptions): string[] {
23-
return runtimeOptions.fallbackToApi
23+
const resolved = runtimeOptions.fallbackToApi
2424
? collectionNames
2525
: typeof this.options.serverBundle === 'string'
2626
? collectionNames
2727
: this.options.serverBundle
2828
? this.options.serverBundle.collections
2929
?.map(c => typeof c === 'string' ? c : c.prefix) || []
3030
: []
31+
32+
// Include custom collections prefixes
33+
for (const collection of this.options.customCollections || []) {
34+
if (collection.prefix && !resolved.includes(collection.prefix))
35+
resolved.push(collection.prefix)
36+
}
37+
38+
return resolved
3139
}
3240

3341
private _customCollections: IconifyJSON[] | Promise<IconifyJSON[]> | undefined

0 commit comments

Comments
 (0)
Please sign in to comment.