mirror of https://github.com/iconify/api.git
feat: import icon sets from 'icons' directory, env variable to control Iconify icon sets import
This commit is contained in:
parent
6e9abebfe5
commit
6c613eeba6
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Icons
|
||||||
|
|
||||||
|
This directory contains custom icon sets and icons.
|
||||||
|
|
||||||
|
## Icon sets
|
||||||
|
|
||||||
|
Icon sets are stored in IconifyJSON format.
|
||||||
|
|
||||||
|
You can use Iconify Tools to create icon sets. See [Iconify Tools documentation](https://docs.iconify.design/tools/tools2/).
|
||||||
|
|
||||||
|
Each icon set has prefix. For icon set to be imported, filename must match icon set prefix, for example, `line-md.json` for icon set with `line-md` prefix.
|
||||||
|
|
||||||
|
Icon sets that have `info` property and are not marked as hidden, appear in icon sets list and search results (unless those features are disabled).
|
||||||
|
If you want icon set to be hidden, all you have to do is not add `info` property when creating icon set or remove it.
|
||||||
|
|
||||||
|
## Icons
|
||||||
|
|
||||||
|
TODO
|
||||||
|
|
||||||
|
Currently not supported yet. Create icon sets instead.
|
||||||
|
|
||||||
|
## Conflicts
|
||||||
|
|
||||||
|
If API serves both custom and Iconify icon sets, it is possible to have conflicting names. If 2 icon sets with identical prefix exist in both sources, custom icon set will be used.
|
||||||
|
|
||||||
|
To disable Iconify icon sets, set env variable `ICONIFY_SOURCE` to `none`. You can use `.env` file in root directory.
|
||||||
|
|
@ -20,8 +20,8 @@ export async function getImporters(): Promise<Importer[]> {
|
||||||
*
|
*
|
||||||
* Uses pre-configured importers. See `importers` sub-directory
|
* Uses pre-configured importers. See `importers` sub-directory
|
||||||
*/
|
*/
|
||||||
type IconifyIconSetsOptions = 'full' | 'split' | false;
|
type IconifyIconSetsOptions = 'full' | 'split' | 'none';
|
||||||
const iconifyIconSets = 'full' as IconifyIconSetsOptions;
|
const iconifyIconSets = (process.env['ICONIFY_SOURCE'] || 'full') as IconifyIconSetsOptions;
|
||||||
|
|
||||||
switch (iconifyIconSets) {
|
switch (iconifyIconSets) {
|
||||||
case 'full':
|
case 'full':
|
||||||
|
|
@ -34,11 +34,14 @@ export async function getImporters(): Promise<Importer[]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add custom icons from `json` directory
|
* Add custom icons from `icons` directory
|
||||||
*/
|
*/
|
||||||
if (await directoryExists('json')) {
|
if (await directoryExists('icons')) {
|
||||||
importers.push(
|
importers.push(
|
||||||
createJSONDirectoryImporter(new DirectoryDownloader<ImportedData>('json'), {
|
createJSONDirectoryImporter(new DirectoryDownloader<ImportedData>('icons'), {
|
||||||
|
// Skip icon sets with mismatched prefix
|
||||||
|
ignoreInvalidPrefix: false,
|
||||||
|
|
||||||
// Filter icon sets. Returns true if icon set should be included, false if not.
|
// Filter icon sets. Returns true if icon set should be included, false if not.
|
||||||
filter: (prefix) => {
|
filter: (prefix) => {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import { prependSlash } from '../../misc/files';
|
||||||
|
|
||||||
export interface IconSetJSONOptions {
|
export interface IconSetJSONOptions {
|
||||||
// Ignore bad prefix?
|
// Ignore bad prefix?
|
||||||
|
// false -> skip icon sets with mismatched prefix
|
||||||
|
// true -> import icon set with mismatched prefix
|
||||||
ignoreInvalidPrefix?: boolean;
|
ignoreInvalidPrefix?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -26,9 +28,12 @@ export async function importIconSetFromJSON(
|
||||||
}
|
}
|
||||||
if (data.prefix !== prefix) {
|
if (data.prefix !== prefix) {
|
||||||
if (!options.ignoreInvalidPrefix) {
|
if (!options.ignoreInvalidPrefix) {
|
||||||
console.error(
|
if (options.ignoreInvalidPrefix === void 0) {
|
||||||
`Error loading "${prefix}" icon set: bad prefix (enable ignoreInvalidPrefix option in importer to skip this check)`
|
// Show warning if option is not set
|
||||||
);
|
console.error(
|
||||||
|
`Error loading "${prefix}" icon set: bad prefix (enable ignoreInvalidPrefix option in importer to import icon set)`
|
||||||
|
);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
data.prefix = prefix;
|
data.prefix = prefix;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue