|
1 | 1 | import type { PresetWind3Theme } from 'unocss' |
| 2 | +import { dirname, resolve } from 'node:path' |
| 3 | +import { fileURLToPath } from 'node:url' |
2 | 4 | import { createExternalPackageIconLoader } from '@iconify/utils/lib/loader/external-pkg' |
| 5 | +import { FileSystemIconLoader } from '@iconify/utils/lib/loader/node-loaders' |
3 | 6 | import { defineConfig, presetIcons } from 'unocss' |
4 | 7 | import { presetOnmax } from 'unocss-preset-onmax' |
5 | | -import { FileSystemIconLoader } from 'unplugin-icons/loaders' |
6 | 8 | import { presetNimiq } from '../packages/nimiq-css/src/index' |
7 | 9 |
|
| 10 | +const __filename = fileURLToPath(import.meta.url) |
| 11 | +const __dirname = dirname(__filename) |
| 12 | + |
| 13 | +const themeIconsLoader = FileSystemIconLoader(resolve(__dirname, '../packages/nimiq-vitepress-theme/src/assets/icons')) |
| 14 | +const docsIconsLoader = FileSystemIconLoader(resolve(__dirname, './public/assets/icons')) |
| 15 | + |
| 16 | +async function tryLoadIcon(loader: ReturnType<typeof FileSystemIconLoader>, name: string) { |
| 17 | + try { |
| 18 | + return await loader(name) |
| 19 | + } |
| 20 | + catch { |
| 21 | + return null |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +async function localIconLoader(name: string) { |
| 26 | + return (await tryLoadIcon(themeIconsLoader, name)) |
| 27 | + ?? (await tryLoadIcon(docsIconsLoader, name)) |
| 28 | +} |
| 29 | + |
8 | 30 | export default defineConfig<PresetWind3Theme>({ |
9 | 31 | content: { |
10 | 32 | filesystem: ['./.vitepress/config.ts', '../**/**.{vue,md}', './theme/components/**/*.vue', './config.ts'], |
@@ -137,7 +159,7 @@ export default defineConfig<PresetWind3Theme>({ |
137 | 159 | collections: { |
138 | 160 | ...createExternalPackageIconLoader('@iconify-json/tabler'), |
139 | 161 | ...createExternalPackageIconLoader('@iconify-json/simple-icons'), |
140 | | - local: FileSystemIconLoader('public/assets/icons'), |
| 162 | + local: localIconLoader, |
141 | 163 | }, |
142 | 164 | }), |
143 | 165 | ], |
|
0 commit comments