Skip to content

Commit 6b2571b

Browse files
committed
fix(schema-org): LocalBusiness extends Organization for Logo Rich Results
Fixes #270
1 parent 2cc88b7 commit 6b2571b

File tree

7 files changed

+38
-27
lines changed

7 files changed

+38
-27
lines changed

packages/schema-org/src/nodes/Article/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ describe('defineArticle', () => {
378378
"url": "https://example.com/test.png",
379379
},
380380
{
381-
"@id": "#organization",
381+
"@id": "https://example.com/#organization",
382382
"@type": "Organization",
383383
"logo": "https://example.com/test.png",
384384
"name": "Identity",

packages/schema-org/src/nodes/LocalBusiness/index.test.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ describe('defineLocalBusiness', () => {
4848
"streetAddress": "123 st",
4949
},
5050
"currenciesAccepted": "AUD",
51-
"logo": {
52-
"@id": "https://example.com/#logo",
53-
"@type": "ImageObject",
54-
"caption": "test",
55-
"contentUrl": "https://example.com/logo.png",
56-
"inLanguage": "en-AU",
57-
"url": "https://example.com/logo.png",
58-
},
5951
"name": "test",
6052
"openingHoursSpecification": [
6153
{
@@ -76,6 +68,27 @@ describe('defineLocalBusiness', () => {
7668
],
7769
"url": "https://example.com/",
7870
},
71+
{
72+
"@id": "https://example.com/#/schema/image/acd40d1",
73+
"@type": "ImageObject",
74+
"caption": "test",
75+
"contentUrl": "https://example.com/logo.png",
76+
"inLanguage": "en-AU",
77+
"url": "https://example.com/logo.png",
78+
},
79+
{
80+
"@id": "https://example.com/#organization",
81+
"@type": "Organization",
82+
"address": {
83+
"@type": "PostalAddress",
84+
"addressCountry": "Australia",
85+
"postalCode": "2000",
86+
"streetAddress": "123 st",
87+
},
88+
"logo": "https://example.com/logo.png",
89+
"name": "test",
90+
"url": "https://example.com/",
91+
},
7992
]
8093
`)
8194
})

packages/schema-org/src/nodes/LocalBusiness/index.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import {
22
IdentityId,
3-
prefixId,
43
resolveDefaultType,
5-
setIfEmpty,
64
} from '../../utils'
75
import type { Organization } from '../Organization'
86
import type { OpeningHoursSpecification } from '../OpeningHours'
97
import { openingHoursResolver } from '../OpeningHours'
10-
import { imageResolver } from '../Image'
118
import type { NodeRelations } from '../../types'
12-
import { defineSchemaOrgResolver, resolveRelation } from '../../core'
9+
import { defineSchemaOrgResolver, resolveNode, resolveRelation } from '../../core'
1310
import { addressResolver } from '../PostalAddress'
11+
import { organizationResolver } from '../Organization'
1412

1513
type ValidLocalBusinessSubTypes = 'AnimalShelter' |
1614
'ArchiveOrganization' |
@@ -107,15 +105,9 @@ export const localBusinessResolver = defineSchemaOrgResolver<LocalBusiness>({
107105

108106
node.address = resolveRelation(node.address, ctx, addressResolver)
109107
node.openingHoursSpecification = resolveRelation(node.openingHoursSpecification, ctx, openingHoursResolver)
110-
node.logo = resolveRelation(node.logo, ctx, imageResolver, {
111-
afterResolve(logo) {
112-
const hasLogo = !!ctx.find('#logo')
113-
if (!hasLogo)
114-
logo['@id'] = prefixId(ctx.meta.host, '#logo')
115108

116-
setIfEmpty(logo, 'caption', node.name)
117-
},
118-
})
119-
return node
109+
node = resolveNode({ ...node }, ctx, organizationResolver) as LocalBusiness
110+
organizationResolver.resolveRootNode!(node, ctx)
111+
return node as LocalBusiness
120112
},
121113
})

packages/schema-org/src/nodes/Organization/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('defineOrganization', () => {
4242
"url": "https://example.com/logo.png",
4343
},
4444
{
45-
"@id": "#organization",
45+
"@id": "https://example.com/#organization",
4646
"@type": "Organization",
4747
"address": {
4848
"@type": "PostalAddress",

packages/schema-org/src/nodes/Organization/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,18 @@ export const organizationResolver
9696

9797
// push a separate node that will just be used for the Logo rich result
9898
ctx.nodes.push({
99-
...node,
99+
// we want to make a simple node that has the essentials, this will allow parent nodes to inject
100+
// as well without inserting invalid data (i.e LocalBusiness operatingHours)
101+
'@type': 'Organization',
102+
'name': node.name,
103+
'url': node.url,
104+
'sameAs': node.sameAs,
105+
// 'image': idReference(logoNode),
106+
'address': node.address,
100107
// needs to be a URL
101108
'logo': resolveRelation(node.logo, ctx, imageResolver, { root: false }).url,
102109
'_priority': -1,
103-
'@id': '#organization', // avoid the id so nothing can link to it
110+
'@id': prefixId(ctx.meta.host, '#organization'), // avoid the id so nothing can link to it
104111
})
105112
}
106113
delete node.logo

packages/schema-org/src/nodes/WebPage/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ describe('defineWebPage', () => {
292292
"url": "https://example.com/logo.png",
293293
},
294294
{
295-
"@id": "#organization",
295+
"@id": "https://example.com/#organization",
296296
"@type": "Organization",
297297
"logo": "https://example.com/logo.png",
298298
"name": "Harlan Wilton",

test/schema.org/ssr/ids.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ describe('schema.org ssr ids', () => {
2121
}),
2222
])
2323

24-
2524
const tags = await ssrHead.resolveTags()
2625
const id = JSON.parse(tags[0].innerHTML!)['@graph'][0]['@id']
2726
expect(id).toMatchInlineSnapshot('"https://example.com/#foo"')

0 commit comments

Comments
 (0)