Skip to content

Commit

Permalink
fix: enable node duplicate merging
Browse files Browse the repository at this point in the history
Fixes #21
  • Loading branch information
harlan-zw committed May 26, 2023
1 parent d643bd0 commit b2305f8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/unhead-schema-org/src/core/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { hash } from 'ohash'
import { defu } from 'defu'
import type { Id, SchemaOrgNode } from '../types'
import { resolveAsGraphKey } from '../utils'

Expand Down Expand Up @@ -37,9 +38,11 @@ export function dedupeNodes(nodes: SchemaOrgNode[]) {
...(groupedKeys.primitives || []).sort(),
...(groupedKeys.relations || []).sort(),
]
const newNode = {} as SchemaOrgNode
let newNode = {} as SchemaOrgNode
for (const key of keys)
newNode[key] = n[key]
if (dedupedNodes[nodeKey])
newNode = defu(newNode, dedupedNodes[nodeKey]) as SchemaOrgNode
dedupedNodes[nodeKey] = newNode
}
return Object.values(dedupedNodes)
Expand Down
29 changes: 26 additions & 3 deletions packages/unhead-schema-org/src/nodes/Breadcrumb/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ describe('defineBreadcrumb', async () => {
defineBreadcrumb({
'@id': '#subbreadcrumb',
'itemListElement': [
{ name: 'Some other link', item: '/blog/test' },
{ name: 'Some other link', item: '/blog/foo' },
],
}),

defineBreadcrumb({
'@id': '#subbreadcrumb',
'custom': 'test',
'itemListElement': [
{ name: 'Some other link', item: '/blog/test' },
{ name: 'Some other link', item: '/blog/bar' },
],
}),
])
Expand All @@ -94,6 +94,23 @@ describe('defineBreadcrumb', async () => {
"name": "Some joining page",
"position": 3,
},
{
"@type": "ListItem",
"item": "https://example.com",
"name": "Home",
"position": 1,
},
{
"@type": "ListItem",
"item": "https://example.com/blog",
"name": "Blog",
"position": 2,
},
{
"@type": "ListItem",
"name": "My Article",
"position": 4,
},
],
},
{
Expand All @@ -103,7 +120,13 @@ describe('defineBreadcrumb', async () => {
"itemListElement": [
{
"@type": "ListItem",
"item": "https://example.com/blog/test",
"item": "https://example.com/blog/bar",
"name": "Some other link",
"position": 1,
},
{
"@type": "ListItem",
"item": "https://example.com/blog/foo",
"name": "Some other link",
"position": 1,
},
Expand Down
6 changes: 6 additions & 0 deletions packages/unhead-schema-org/src/nodes/WebPage/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,12 @@ describe('defineWebPage', () => {
"https://example.com/",
],
},
{
"@type": "ReadAction",
"target": [
"https://example.com/",
],
},
],
"url": "https://example.com/",
},
Expand Down
4 changes: 4 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { defineConfig } from 'vite'

export default defineConfig({
test: {
include: [
'packages/**/src/**/*.test.ts',
'test/**/*.test.ts',
],
env: {
NODE_ENV: 'development',
},
Expand Down

1 comment on commit b2305f8

@vercel
Copy link

@vercel vercel bot commented on b2305f8 May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.