Skip to content
Merged
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
28 changes: 27 additions & 1 deletion src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default defineNuxtPlugin({
resources.push(options.iconifyApiEndpoint!)
}

async function customIconLoader(icons: string[], prefix: string): Promise<IconifyJSON | null> {
async function loadCustomIconsChunk(icons: string[], prefix: string): Promise<IconifyJSON | null> {
try {
const data = await requestFetch(resources[0] + '/' + prefix + '.json', {
query: {
Expand All @@ -56,6 +56,32 @@ export default defineNuxtPlugin({
}
}

async function customIconLoader(icons: string[], prefix: string): Promise<IconifyJSON | null> {
// Split large lists into several requests to stay under URL length limits (431 / 414)
const chunks: string[][] = [[]]
let length = 0
for (const name of icons) {
const nameLength = encodeURIComponent(name).length
if (length + nameLength > 2000 && chunks.at(-1)!.length) {
chunks.push([])
length = 0
}
chunks.at(-1)!.push(name)
length += nameLength + 1
}
const results = (await Promise.all(chunks.map(chunk => loadCustomIconsChunk(chunk, prefix))))
.filter((data): data is IconifyJSON => !!data)
if (!results.length)
return null
// Keep collection-level properties (width, height, ...) from the responses
return results.reduce((acc, data) => ({
...acc,
...data,
icons: { ...acc.icons, ...data.icons },
aliases: { ...acc.aliases, ...data.aliases },
}))
}

addAPIProvider('', { resources })

// Register custom collections handlers
Expand Down
Loading