-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix lint fix
- Loading branch information
Showing
13 changed files
with
258 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import type { ResolvedMetadata } from '../types/metadata-interface' | ||
import type { Icon, IconDescriptor } from '../types/metadata-types' | ||
|
||
import React from 'react' | ||
import { resolveAsArrayOrUndefined } from './utils' | ||
|
||
const resolveUrl = (url: string | URL) => | ||
typeof url === 'string' ? url : url.toString() | ||
|
||
function IconDescriptorLink({ icon }: { icon: IconDescriptor }) { | ||
const { url, rel = 'icon', ...props } = icon | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
if (!url) { | ||
throw new Error('`url` in required for descriptor in `metadata.icons`') | ||
} | ||
} | ||
|
||
return <link rel={rel} href={resolveUrl(url)} {...props} /> | ||
} | ||
|
||
function IconLink({ rel, icon }: { rel?: string; icon: Icon }) { | ||
if (typeof icon === 'object' && !(icon instanceof URL)) { | ||
if (rel) icon.rel = rel | ||
return <IconDescriptorLink icon={icon} /> | ||
} else { | ||
const href = resolveUrl(icon) | ||
return <link rel={rel} href={href} /> | ||
} | ||
} | ||
|
||
export function ResolvedIconsMetadata({ | ||
icons, | ||
}: { | ||
icons: ResolvedMetadata['icons'] | ||
}) { | ||
if (!icons) return null | ||
|
||
const shortcutList = resolveAsArrayOrUndefined(icons.shortcut) | ||
const iconList = resolveAsArrayOrUndefined(icons.icon) | ||
const appleList = resolveAsArrayOrUndefined(icons.apple) | ||
const otherList = resolveAsArrayOrUndefined(icons.other) | ||
|
||
return ( | ||
<> | ||
{shortcutList | ||
? shortcutList.map((icon, index) => ( | ||
<IconLink | ||
key={`shortcut-${index}`} | ||
rel="shortcut icon" | ||
icon={icon} | ||
/> | ||
)) | ||
: null} | ||
{iconList | ||
? iconList.map((icon, index) => ( | ||
<IconLink key={`shortcut-${index}`} rel="icon" icon={icon} /> | ||
)) | ||
: null} | ||
{appleList | ||
? appleList.map((icon, index) => ( | ||
<IconLink | ||
key={`apple-${index}`} | ||
rel="apple-touch-icon" | ||
icon={icon} | ||
/> | ||
)) | ||
: null} | ||
{otherList | ||
? otherList.map((icon, index) => ( | ||
<IconDescriptorLink key={`other-${index}`} icon={icon} /> | ||
)) | ||
: null} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export function resolveAsArrayOrUndefined<T = any>( | ||
value: T | T[] | undefined | ||
): undefined | T[] { | ||
if (typeof value === 'undefined' || value === null) { | ||
return undefined | ||
} | ||
if (Array.isArray(value)) { | ||
return value | ||
} | ||
return [value] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export default function page() { | ||
return 'icons' | ||
} | ||
|
||
export const metadata = { | ||
icons: { | ||
icon: [{ url: '/icon.png' }, new URL('/icon.png', 'https://example.com')], | ||
shortcut: ['/shortcut-icon.png'], | ||
apple: [ | ||
{ url: '/apple-icon.png' }, | ||
{ url: '/apple-icon-x3.png', sizes: '180x180', type: 'image/png' }, | ||
], | ||
other: [ | ||
{ | ||
rel: 'apple-touch-icon-precomposed', | ||
url: '/apple-touch-icon-precomposed.png', | ||
}, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default function page() { | ||
return 'icons' | ||
} | ||
|
||
export const metadata = { | ||
icons: { | ||
icon: '/icon.png', | ||
shortcut: '/shortcut-icon.png', | ||
apple: '/apple-icon.png', | ||
other: { | ||
rel: 'apple-touch-icon-precomposed', | ||
url: '/apple-touch-icon-precomposed.png', | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function page() { | ||
return 'icons' | ||
} | ||
|
||
export const metadata = { | ||
icons: '/icon.png', | ||
} |
Oops, something went wrong.