Skip to content

Commit c0ddf10

Browse files
authoredMar 5, 2025··
fix(schema.org): avoid appending trailing slash on @id's (#511)
Fixes #469
1 parent e7a6e2b commit c0ddf10

File tree

7 files changed

+64
-64
lines changed

7 files changed

+64
-64
lines changed
 

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('defineArticle', () => {
7070
expect(client).toMatchInlineSnapshot(`
7171
[
7272
{
73-
"@id": "https://example.com/test/#article",
73+
"@id": "https://example.com/test#article",
7474
"@type": "Article",
7575
"dateModified": "2021-11-10T10:10:10.000Z",
7676
"datePublished": "2021-11-10T10:10:10.000Z",
@@ -436,7 +436,7 @@ describe('defineArticle', () => {
436436

437437
expect(client[2]).toMatchInlineSnapshot(`
438438
{
439-
"@id": "https://kootingalpecancompany.com/pecan-tree-kootingal/#article",
439+
"@id": "https://kootingalpecancompany.com/pecan-tree-kootingal#article",
440440
"@type": "Article",
441441
"articleSection": [
442442
"Organic pecans, activated pecans, single source, Australian organic pecans",
@@ -453,7 +453,7 @@ describe('defineArticle', () => {
453453
},
454454
"inLanguage": "en-US",
455455
"isPartOf": {
456-
"@id": "https://kootingalpecancompany.com/pecan-tree-kootingal/#webpage",
456+
"@id": "https://kootingalpecancompany.com/pecan-tree-kootingal#webpage",
457457
},
458458
"keywords": [
459459
"certified organic pecans",
@@ -463,7 +463,7 @@ describe('defineArticle', () => {
463463
"Pecan tree",
464464
],
465465
"mainEntityOfPage": {
466-
"@id": "https://kootingalpecancompany.com/pecan-tree-kootingal/#webpage",
466+
"@id": "https://kootingalpecancompany.com/pecan-tree-kootingal#webpage",
467467
},
468468
"publisher": {
469469
"@id": "https://kootingalpecancompany.com/#identity",

‎packages/schema-org/src/nodes/Question/index.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@ describe('defineQuestion', () => {
2424
expect(graphNodes).toMatchInlineSnapshot(`
2525
[
2626
{
27-
"@id": "https://example.com/frequently-asked-questions/#webpage",
27+
"@id": "https://example.com/frequently-asked-questions#webpage",
2828
"@type": [
2929
"WebPage",
3030
"FAQPage",
3131
],
3232
"mainEntity": [
3333
{
34-
"@id": "https://example.com/frequently-asked-questions/#/schema/question/1dbbae0",
34+
"@id": "https://example.com/frequently-asked-questions#/schema/question/1dbbae0",
3535
},
3636
{
37-
"@id": "https://example.com/frequently-asked-questions/#/schema/question/39eca17",
37+
"@id": "https://example.com/frequently-asked-questions#/schema/question/39eca17",
3838
},
3939
],
4040
"name": "FAQ",
4141
"url": "https://example.com/frequently-asked-questions",
4242
},
4343
{
44-
"@id": "https://example.com/frequently-asked-questions/#/schema/question/1dbbae0",
44+
"@id": "https://example.com/frequently-asked-questions#/schema/question/1dbbae0",
4545
"@type": "Question",
4646
"acceptedAnswer": {
4747
"@type": "Answer",
@@ -51,7 +51,7 @@ describe('defineQuestion', () => {
5151
"name": "How long is a piece of string?",
5252
},
5353
{
54-
"@id": "https://example.com/frequently-asked-questions/#/schema/question/39eca17",
54+
"@id": "https://example.com/frequently-asked-questions#/schema/question/39eca17",
5555
"@type": "Question",
5656
"acceptedAnswer": {
5757
"@type": "Answer",

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

+32-32
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ describe('defineWebPage', () => {
5252
expect(webPage?.name).toEqual('headline')
5353

5454
expect(webPage).toMatchInlineSnapshot(`
55-
{
56-
"@id": "https://example.com/test/#webpage",
57-
"@type": "WebPage",
58-
"description": "description",
59-
"name": "headline",
60-
"potentialAction": [
61-
{
62-
"@type": "ReadAction",
63-
"target": [
64-
"https://example.com/test",
65-
],
66-
},
67-
],
68-
"url": "https://example.com/test",
69-
}
70-
`)
55+
{
56+
"@id": "https://example.com/test#webpage",
57+
"@type": "WebPage",
58+
"description": "description",
59+
"name": "headline",
60+
"potentialAction": [
61+
{
62+
"@type": "ReadAction",
63+
"target": [
64+
"https://example.com/test",
65+
],
66+
},
67+
],
68+
"url": "https://example.com/test",
69+
}
70+
`)
7171
}, {
7272
path: '/test',
7373
title: 'headline',
@@ -155,23 +155,23 @@ describe('defineWebPage', () => {
155155
const webpage = await findNode<WebPage>(head, PrimaryWebPageId)
156156

157157
expect(webpage).toMatchInlineSnapshot(`
158-
{
159-
"@id": "https://example.com/our-pages/about-us/#webpage",
160-
"@type": [
161-
"WebPage",
162-
"AboutPage",
158+
{
159+
"@id": "https://example.com/our-pages/about-us#webpage",
160+
"@type": [
161+
"WebPage",
162+
"AboutPage",
163+
],
164+
"name": "Webpage",
165+
"potentialAction": {
166+
"@type": "ReadAction",
167+
"target": [
168+
"https://example.com/our-pages/about-us",
169+
"test",
163170
],
164-
"name": "Webpage",
165-
"potentialAction": {
166-
"@type": "ReadAction",
167-
"target": [
168-
"https://example.com/our-pages/about-us",
169-
"test",
170-
],
171-
},
172-
"url": "https://example.com/our-pages/about-us",
173-
}
174-
`)
171+
},
172+
"url": "https://example.com/our-pages/about-us",
173+
}
174+
`)
175175
}, {
176176
path: '/our-pages/about-us',
177177
})

‎packages/schema-org/src/utils/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function prefixId(url: string, id: Id | string) {
8787
return id as Id
8888
if (!id.includes('#'))
8989
id = `#${id}`
90-
return withBase(id, url) as Id
90+
return `${url || ''}${id}` as Id
9191
}
9292

9393
export function trimLength(val: string | undefined, length: number) {

‎packages/schema-org/test/e2e/basic.test.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('schema.org e2e', () => {
103103
"@context": "https://schema.org",
104104
"@graph": [
105105
{
106-
"@id": "/about/#webpage",
106+
"@id": "/about#webpage",
107107
"name": "About",
108108
"url": "/about",
109109
"@type": [
@@ -132,7 +132,7 @@ describe('schema.org e2e', () => {
132132
"@context": "https://schema.org",
133133
"@graph": [
134134
{
135-
"@id": "/about/#webpage",
135+
"@id": "/about#webpage",
136136
"name": "About",
137137
"url": "/about",
138138
"@type": [
@@ -178,18 +178,18 @@ describe('schema.org e2e', () => {
178178
"@context": "https://schema.org",
179179
"@graph": [
180180
{
181-
"@id": "https://example.com/#identity",
181+
"@id": "https://example.com#identity",
182182
"@type": "Organization",
183183
"name": "test",
184184
"url": "https://example.com"
185185
},
186186
{
187-
"@id": "https://example.com/#website",
187+
"@id": "https://example.com#website",
188188
"@type": "WebSite",
189189
"name": "test",
190190
"url": "https://example.com",
191191
"publisher": {
192-
"@id": "https://example.com/#identity"
192+
"@id": "https://example.com#identity"
193193
}
194194
}
195195
]
@@ -229,23 +229,23 @@ describe('schema.org e2e', () => {
229229
"@context": "https://schema.org",
230230
"@graph": [
231231
{
232-
"@id": "https://example.com/about/#webpage",
232+
"@id": "https://example.com/about#webpage",
233233
"url": "https://example.com/about",
234234
"@type": [
235235
"WebPage",
236236
"FAQPage"
237237
],
238238
"mainEntity": [
239239
{
240-
"@id": "https://example.com/about/#/schema/question/ab1c398"
240+
"@id": "https://example.com/about#/schema/question/ab1c398"
241241
},
242242
{
243-
"@id": "https://example.com/about/#/schema/question/6396da9"
243+
"@id": "https://example.com/about#/schema/question/6396da9"
244244
}
245245
]
246246
},
247247
{
248-
"@id": "https://example.com/about/#/schema/question/ab1c398",
248+
"@id": "https://example.com/about#/schema/question/ab1c398",
249249
"@type": "Question",
250250
"name": "What is your return policy?",
251251
"acceptedAnswer": {
@@ -254,7 +254,7 @@ describe('schema.org e2e', () => {
254254
}
255255
},
256256
{
257-
"@id": "https://example.com/about/#/schema/question/6396da9",
257+
"@id": "https://example.com/about#/schema/question/6396da9",
258258
"@type": "Question",
259259
"name": "What is something else?",
260260
"acceptedAnswer": {

‎packages/schema-org/test/e2e/no-plugin.test.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('schema.org e2e no plugin', () => {
9292
"@context": "https://schema.org",
9393
"@graph": [
9494
{
95-
"@id": "/about/#webpage",
95+
"@id": "/about#webpage",
9696
"name": "About",
9797
"url": "/about",
9898
"@type": [
@@ -121,7 +121,7 @@ describe('schema.org e2e no plugin', () => {
121121
"@context": "https://schema.org",
122122
"@graph": [
123123
{
124-
"@id": "/about/#webpage",
124+
"@id": "/about#webpage",
125125
"name": "About",
126126
"url": "/about",
127127
"@type": [
@@ -170,18 +170,18 @@ describe('schema.org e2e no plugin', () => {
170170
"@context": "https://schema.org",
171171
"@graph": [
172172
{
173-
"@id": "https://example.com/#identity",
173+
"@id": "https://example.com#identity",
174174
"@type": "Organization",
175175
"name": "test",
176176
"url": "https://example.com"
177177
},
178178
{
179-
"@id": "https://example.com/#website",
179+
"@id": "https://example.com#website",
180180
"@type": "WebSite",
181181
"name": "test",
182182
"url": "https://example.com",
183183
"publisher": {
184-
"@id": "https://example.com/#identity"
184+
"@id": "https://example.com#identity"
185185
}
186186
}
187187
]
@@ -222,23 +222,23 @@ describe('schema.org e2e no plugin', () => {
222222
"@context": "https://schema.org",
223223
"@graph": [
224224
{
225-
"@id": "https://example.com/about/#webpage",
225+
"@id": "https://example.com/about#webpage",
226226
"url": "https://example.com/about",
227227
"@type": [
228228
"WebPage",
229229
"FAQPage"
230230
],
231231
"mainEntity": [
232232
{
233-
"@id": "https://example.com/about/#/schema/question/ab1c398"
233+
"@id": "https://example.com/about#/schema/question/ab1c398"
234234
},
235235
{
236-
"@id": "https://example.com/about/#/schema/question/6396da9"
236+
"@id": "https://example.com/about#/schema/question/6396da9"
237237
}
238238
]
239239
},
240240
{
241-
"@id": "https://example.com/about/#/schema/question/ab1c398",
241+
"@id": "https://example.com/about#/schema/question/ab1c398",
242242
"@type": "Question",
243243
"name": "What is your return policy?",
244244
"acceptedAnswer": {
@@ -247,7 +247,7 @@ describe('schema.org e2e no plugin', () => {
247247
}
248248
},
249249
{
250-
"@id": "https://example.com/about/#/schema/question/6396da9",
250+
"@id": "https://example.com/about#/schema/question/6396da9",
251251
"@type": "Question",
252252
"name": "What is something else?",
253253
"acceptedAnswer": {

‎packages/schema-org/test/ssr/ids.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('schema.org ssr ids', () => {
2626

2727
const tags = await ssrHead.resolveTags()
2828
const id = JSON.parse(tags[0].innerHTML!)['@graph'][0]['@id']
29-
expect(id).toMatchInlineSnapshot(`"https://example.com/#/schema/web-page/#foo"`)
29+
expect(id).toMatchInlineSnapshot(`"https://example.com#/schema/web-page/#foo"`)
3030
})
3131
it('allows ids with custom domains', async () => {
3232
const ssrHead = createHead({
@@ -139,7 +139,7 @@ describe('schema.org ssr ids', () => {
139139
],
140140
},
141141
{
142-
"@id": "https://example.com/#webpage",
142+
"@id": "https://example.com#webpage",
143143
"@type": "WebPage",
144144
"isPartOf": {
145145
"@id": "https://example.com/en#website",

0 commit comments

Comments
 (0)
Please sign in to comment.