-
-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(json-ld): add WebSite component
- Loading branch information
Showing
13 changed files
with
236 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ package-lock.json | |
lib | ||
notes.md | ||
.DS_Store | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { assertSchema } from '@cypress/schema-tools'; | ||
import schemas from '../schemas'; | ||
|
||
describe('WebPage JSON-LD', () => { | ||
it('matches schema', () => { | ||
cy.visit('http://localhost:3000/jsonld/webSite'); | ||
cy.get('head script[type="application/ld+json"]').then(tags => { | ||
const jsonLD = JSON.parse(tags[0].innerHTML); | ||
assertSchema(schemas)('WebSite', '1.0.0')(jsonLD); | ||
}); | ||
}); | ||
|
||
it('renders with all props', () => { | ||
cy.visit('http://localhost:3000/jsonld/webSite'); | ||
cy.get('head script[type="application/ld+json"]').then(tags => { | ||
const jsonLD = JSON.parse(tags[0].innerHTML); | ||
expect(jsonLD).to.deep.equal({ | ||
'@context': 'https://schema.org', | ||
'@type': 'WebSite', | ||
name: 'Example', | ||
alternateName: ['Example Org', 'Example Organization'], | ||
url: 'https://example.org', | ||
publisher: { | ||
'@id': 'https://example.org/#organization', | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
it('renders without a publisher', () => { | ||
cy.visit('http://localhost:3000/jsonld/webSite/withoutPublisher'); | ||
cy.get('head script[type="application/ld+json"]').then(tags => { | ||
const jsonLD = JSON.parse(tags[0].innerHTML); | ||
expect(jsonLD).to.deep.equal({ | ||
'@context': 'https://schema.org', | ||
'@type': 'WebSite', | ||
name: 'Example', | ||
alternateName: ['Example Org', 'Example Organization'], | ||
url: 'https://example.org', | ||
}); | ||
}); | ||
}); | ||
|
||
it('renders with a single alternate name', () => { | ||
cy.visit('http://localhost:3000/jsonld/webSite/withSingleAlternateName'); | ||
cy.get('head script[type="application/ld+json"]').then(tags => { | ||
const jsonLD = JSON.parse(tags[0].innerHTML); | ||
expect(jsonLD).to.deep.equal({ | ||
'@context': 'https://schema.org', | ||
'@type': 'WebSite', | ||
name: 'Example', | ||
alternateName: 'Example Organization', | ||
url: 'https://example.org', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { versionSchemas } from '@cypress/schema-tools'; | ||
|
||
const webSite100 = { | ||
version: { | ||
major: 1, | ||
minor: 0, | ||
patch: 0, | ||
}, | ||
schema: { | ||
type: 'object', | ||
title: 'WebSite', | ||
description: 'An example schema describing JSON-LD for type: WebSite', | ||
properties: { | ||
'@context': { | ||
type: 'string', | ||
description: 'Schema.org context', | ||
}, | ||
'@type': { | ||
type: 'string', | ||
description: 'JSON-LD type: WebSite', | ||
}, | ||
name: { | ||
type: 'string', | ||
description: 'The site name', | ||
}, | ||
url: { | ||
type: 'string', | ||
description: 'The URL of the website', | ||
}, | ||
alternateName: { | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
}, | ||
description: 'One or multiple alternate names for the site', | ||
}, | ||
publisher: { | ||
type: 'object', | ||
properties: { | ||
'@id': { | ||
type: 'string', | ||
description: 'Id of the publisher node', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
example: { | ||
'@context': 'https://schema.org', | ||
'@type': 'WebSite', | ||
url: 'https://example.org', | ||
name: 'Example', | ||
alternateName: ['Example Org', 'Example Organization'], | ||
publisher: { | ||
'@id': 'https://example.org/#organization', | ||
}, | ||
}, | ||
}; | ||
|
||
const webSiteVersions = versionSchemas(webSite100); | ||
export default webSiteVersions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ const allJsonLDPages = [ | |
'videoGame', | ||
'webPage', | ||
'webPage2', | ||
'webSite', | ||
]; | ||
|
||
const Home = () => ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import { WebSiteJsonLd } from '../../../..'; | ||
|
||
function WebPage() { | ||
return ( | ||
<> | ||
<h1>WebSite</h1> | ||
<WebSiteJsonLd | ||
name="Example" | ||
alternateName={['Example Org', 'Example Organization']} | ||
url="https://example.org" | ||
publisher={{ | ||
id: 'https://example.org/#organization', | ||
}} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default WebPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { WebSiteJsonLd } from '../../../..'; | ||
|
||
function WebPage() { | ||
return ( | ||
<> | ||
<h1>WebSite</h1> | ||
<WebSiteJsonLd | ||
name="Example" | ||
alternateName="Example Organization" | ||
url="https://example.org" | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default WebPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { WebSiteJsonLd } from '../../../..'; | ||
|
||
function WebPage() { | ||
return ( | ||
<> | ||
<h1>WebSite</h1> | ||
<WebSiteJsonLd | ||
name="Example" | ||
alternateName={['Example Org', 'Example Organization']} | ||
url="https://example.org" | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default WebPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
|
||
import { JsonLd, JsonLdProps } from './jsonld'; | ||
import { WebSitePublisher } from '../types'; | ||
import { setWebSitePublisher } from '../utils/schema/setWebSitePublisher'; | ||
|
||
export interface WebSiteJsonLdProps extends JsonLdProps { | ||
name: string; | ||
url?: string; | ||
alternateName?: string | string[]; | ||
publisher?: WebSitePublisher; | ||
} | ||
|
||
function WebSiteJsonLd({ | ||
type = 'WebSite', | ||
keyOverride, | ||
publisher, | ||
...rest | ||
}: WebSiteJsonLdProps) { | ||
const data = { | ||
...rest, | ||
publisher: setWebSitePublisher(publisher), | ||
}; | ||
|
||
return ( | ||
<JsonLd | ||
type={type} | ||
keyOverride={keyOverride} | ||
{...data} | ||
scriptKey="WebSite" | ||
/> | ||
); | ||
} | ||
|
||
export default WebSiteJsonLd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { WebSitePublisher } from '../../types'; | ||
|
||
export function setWebSitePublisher(publisher?: WebSitePublisher) { | ||
if (publisher) { | ||
return { | ||
'@id': publisher.id, | ||
}; | ||
} | ||
|
||
return undefined; | ||
} |