Skip to content

Commit

Permalink
Merge branch 'canary' into add/jest-module-mapping-from-tsconfig-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnDaly authored Feb 28, 2023
2 parents 89561ba + d0ba800 commit 943d651
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
14 changes: 14 additions & 0 deletions packages/next/src/lib/metadata/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Viewport } from './types/extra-types'
import type { Icons } from './types/metadata-types'

export const ViewPortKeys: { [k in keyof Viewport]: string } = {
width: 'width',
height: 'height',
initialScale: 'initial-scale',
minimumScale: 'minimum-scale',
maximumScale: 'maximum-scale',
viewportFit: 'viewport-fit',
interactiveWidget: 'interactive-widget',
} as const

export const IconKeys: (keyof Icons)[] = ['icon', 'shortcut', 'apple', 'other']
3 changes: 2 additions & 1 deletion packages/next/src/lib/metadata/resolve-metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ describe('accumulateMetadata', () => {
initialScale: 1,
minimumScale: 1,
maximumScale: 1,
viewportFit: 'cover',
interactiveWidget: 'overlays-content',
},
},
Expand All @@ -203,7 +204,7 @@ describe('accumulateMetadata', () => {
const metadata = await accumulateMetadata(metadataItems)
expect(metadata).toMatchObject({
viewport:
'width=device-width, height=device-height, initial-scale=1, minimum-scale=1, maximum-scale=1, interactive-widget=overlays-content',
'width=device-width, height=device-height, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover, interactive-widget=overlays-content',
})
})
})
Expand Down
15 changes: 3 additions & 12 deletions packages/next/src/lib/metadata/resolvers/resolve-basics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@ import type {
import type { Viewport } from '../types/extra-types'
import { resolveAsArrayOrUndefined } from '../generate/utils'
import { resolveUrl, resolveUrlValuesOfObject } from './resolve-url'

const viewPortKeys = {
width: 'width',
height: 'height',
initialScale: 'initial-scale',
minimumScale: 'minimum-scale',
maximumScale: 'maximum-scale',
interactiveWidget: 'interactive-widget',
viewportFit: 'viewport-fit',
} as const
import { ViewPortKeys } from '../constants'

export const resolveThemeColor: FieldResolver<'themeColor'> = (themeColor) => {
if (!themeColor) return null
Expand All @@ -43,11 +34,11 @@ export const resolveViewport: FieldResolver<'viewport'> = (viewport) => {
resolved = viewport
} else if (viewport) {
resolved = ''
for (const viewportKey_ in viewPortKeys) {
for (const viewportKey_ in ViewPortKeys) {
const viewportKey = viewportKey_ as keyof Viewport
if (viewport[viewportKey]) {
if (resolved) resolved += ', '
resolved += `${viewPortKeys[viewportKey]}=${viewport[viewportKey]}`
resolved += `${ViewPortKeys[viewportKey]}=${viewport[viewportKey]}`
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions packages/next/src/lib/metadata/resolvers/resolve-icons.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import type { ResolvedMetadata } from '../types/metadata-interface'
import type { Icon, IconDescriptor, Icons } from '../types/metadata-types'
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
}

const IconKeys = ['icon', 'shortcut', 'apple', 'other'] as (keyof Icons)[]

export const resolveIcons: FieldResolver<'icons'> = (icons) => {
if (!icons) {
return null
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/lib/metadata/types/extra-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export type Viewport = {
initialScale?: number
minimumScale?: number
maximumScale?: number
viewportFit?: 'auto' | 'cover' | 'contain'
interactiveWidget?: 'resizes-visual' | 'resizes-content' | 'overlays-content'
}

Expand Down

0 comments on commit 943d651

Please sign in to comment.