Skip to content

Commit

Permalink
Merge branch 'canary' into metadata/auto-metabase
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Feb 20, 2023
2 parents ab93407 + 5cb6925 commit d35aa40
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
61 changes: 61 additions & 0 deletions packages/next/src/lib/metadata/resolve-metadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { accumulateMetadata, MetadataItems } from './resolve-metadata'
import { Metadata } from './types/metadata-interface'

describe('accumulateMetadata', () => {
describe('typing', () => {
Expand Down Expand Up @@ -48,4 +49,64 @@ describe('accumulateMetadata', () => {
})
})
})

describe('openGraph', () => {
it('should convert string or URL images field to array, not only for basic og type', async () => {
const items: [Metadata[], Metadata][] = [
[
[{ openGraph: { type: 'article', images: 'https://test.com' } }],
{ openGraph: { images: ['https://test.com'] } },
],
[
[{ openGraph: { type: 'book', images: 'https://test.com' } }],
{ openGraph: { images: ['https://test.com'] } },
],
[
[
{
openGraph: {
type: 'music.song',
images: new URL('https://test.com'),
},
},
],
{ openGraph: { images: [new URL('https://test.com')] } },
],
[
[
{
openGraph: {
type: 'music.playlist',
images: { url: 'https://test.com' },
},
},
],
{ openGraph: { images: [{ url: 'https://test.com' }] } },
],
[
[
{
openGraph: {
type: 'music.radio_station',
images: 'https://test.com',
},
},
],
{ openGraph: { images: ['https://test.com'] } },
],
[
[{ openGraph: { type: 'video.movie', images: 'https://test.com' } }],
{ openGraph: { images: ['https://test.com'] } },
],
]

items.forEach(async (item) => {
const [configuredMetadata, result] = item
const metadata = await accumulateMetadata(
configuredMetadata.map((m) => [m, null])
)
expect(metadata).toMatchObject(result)
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const OgTypFields = {
'phoneNumbers',
'faxNumbers',
'alternateLocale',
'images',
'audio',
'videos',
],
Expand Down Expand Up @@ -69,6 +68,7 @@ export function resolveOpenGraph(
}
}
}

resolved.images = resolveAsArrayOrUndefined(og.images)?.map((item) => {
if (isStringOrURL(item))
return {
Expand Down

0 comments on commit d35aa40

Please sign in to comment.