Download next.js/packages/next/src/lib/metadata/resolvers/resolve-icons.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/lib/metadata/resolvers/resolve-icons.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/lib/metadata/resolvers/resolve-icons.ts
-
curl -L -o resolve-icons.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/lib/metadata/resolvers/resolve-icons.ts
1.05 kB
| import type { ResolvedMetadata } from '../types/metadata-interface' | |
| import type { Icon, IconDescriptor } from '../types/metadata-types' | |
| import type { FieldResolver } from '../types/resolvers' | |
| import { resolveAsArrayOrUndefined } from '../generate/utils' | |
| import { isStringOrURL } from './resolve-url' | |
| import { IconKeys } from '../constants' | |
| export function resolveIcon(icon: Icon): IconDescriptor { | |
| if (isStringOrURL(icon)) return { url: icon } | |
| else if (Array.isArray(icon)) return icon | |
| return icon | |
| } | |
| export const resolveIcons: FieldResolver<'icons'> = (icons) => { | |
| if (!icons) { | |
| return null | |
| } | |
| const resolved: ResolvedMetadata['icons'] = { | |
| icon: [], | |
| apple: [], | |
| } | |
| if (Array.isArray(icons)) { | |
| resolved.icon = icons.map(resolveIcon).filter(Boolean) | |
| } else if (isStringOrURL(icons)) { | |
| resolved.icon = [resolveIcon(icons)] | |
| } else { | |
| for (const key of IconKeys) { | |
| const values = resolveAsArrayOrUndefined(icons[key]) | |
| if (values) resolved[key] = values.map(resolveIcon) | |
| } | |
| } | |
| return resolved | |
| } | |