Skip to content

Commit 0193a4d

Browse files
committed
feat(json-ld): add WebSite component
1 parent 0030c7c commit 0193a4d

File tree

13 files changed

+236
-2
lines changed

13 files changed

+236
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ package-lock.json
1010
lib
1111
notes.md
1212
.DS_Store
13+
.idea

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ If you are using **`pages`** directory then `NextSeo` is **exactly what you need
6161
- [dangerouslySetAllPagesToNoFollow](#dangerouslysetallpagestonofollow)
6262
- [robotsProps](#robotsprops)
6363
- [Twitter](#twitter)
64-
- [facebook](#facebook)
64+
- [Facebook](#facebook)
6565
- [Canonical URL](#canonical-url)
6666
- [Alternate](#alternate)
6767
- [Additional Meta Tags](#additional-meta-tags)

cypress/e2e/webSiteJsonLd.spec.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { assertSchema } from '@cypress/schema-tools';
2+
import schemas from '../schemas';
3+
4+
describe('WebPage JSON-LD', () => {
5+
it('matches schema', () => {
6+
cy.visit('http://localhost:3000/jsonld/webSite');
7+
cy.get('head script[type="application/ld+json"]').then(tags => {
8+
const jsonLD = JSON.parse(tags[0].innerHTML);
9+
assertSchema(schemas)('WebSite', '1.0.0')(jsonLD);
10+
});
11+
});
12+
13+
it('renders with all props', () => {
14+
cy.visit('http://localhost:3000/jsonld/webSite');
15+
cy.get('head script[type="application/ld+json"]').then(tags => {
16+
const jsonLD = JSON.parse(tags[0].innerHTML);
17+
expect(jsonLD).to.deep.equal({
18+
'@context': 'https://schema.org',
19+
'@type': 'WebSite',
20+
name: 'Example',
21+
alternateName: ['Example Org', 'Example Organization'],
22+
url: 'https://example.org',
23+
publisher: {
24+
'@id': 'https://example.org/#organization',
25+
},
26+
});
27+
});
28+
});
29+
30+
it('renders without a publisher', () => {
31+
cy.visit('http://localhost:3000/jsonld/webSite/withoutPublisher');
32+
cy.get('head script[type="application/ld+json"]').then(tags => {
33+
const jsonLD = JSON.parse(tags[0].innerHTML);
34+
expect(jsonLD).to.deep.equal({
35+
'@context': 'https://schema.org',
36+
'@type': 'WebSite',
37+
name: 'Example',
38+
alternateName: ['Example Org', 'Example Organization'],
39+
url: 'https://example.org',
40+
});
41+
});
42+
});
43+
44+
it('renders with a single alternate name', () => {
45+
cy.visit('http://localhost:3000/jsonld/webSite/withSingleAlternateName');
46+
cy.get('head script[type="application/ld+json"]').then(tags => {
47+
const jsonLD = JSON.parse(tags[0].innerHTML);
48+
expect(jsonLD).to.deep.equal({
49+
'@context': 'https://schema.org',
50+
'@type': 'WebSite',
51+
name: 'Example',
52+
alternateName: 'Example Organization',
53+
url: 'https://example.org',
54+
});
55+
});
56+
});
57+
});

cypress/schemas/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import howToVersions from './how-to-schema';
2929
import imageVersions from './image-schema';
3030
import campgroundVersions from './campground-schema';
3131
import parkVersions from './park-schema';
32-
32+
import webSiteVersions from './web-site-schema';
3333

3434
const schemas = combineSchemas(
3535
articleVersions,
@@ -61,5 +61,6 @@ const schemas = combineSchemas(
6161
imageVersions,
6262
campgroundVersions,
6363
parkVersions,
64+
webSiteVersions,
6465
);
6566
export default schemas;

cypress/schemas/web-site-schema.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { versionSchemas } from '@cypress/schema-tools';
2+
3+
const webSite100 = {
4+
version: {
5+
major: 1,
6+
minor: 0,
7+
patch: 0,
8+
},
9+
schema: {
10+
type: 'object',
11+
title: 'WebSite',
12+
description: 'An example schema describing JSON-LD for type: WebSite',
13+
properties: {
14+
'@context': {
15+
type: 'string',
16+
description: 'Schema.org context',
17+
},
18+
'@type': {
19+
type: 'string',
20+
description: 'JSON-LD type: WebSite',
21+
},
22+
name: {
23+
type: 'string',
24+
description: 'The site name',
25+
},
26+
url: {
27+
type: 'string',
28+
description: 'The URL of the website',
29+
},
30+
alternateName: {
31+
type: 'array',
32+
items: {
33+
type: 'string',
34+
},
35+
description: 'One or multiple alternate names for the site',
36+
},
37+
publisher: {
38+
type: 'object',
39+
properties: {
40+
'@id': {
41+
type: 'string',
42+
description: 'Id of the publisher node',
43+
},
44+
},
45+
},
46+
},
47+
},
48+
example: {
49+
'@context': 'https://schema.org',
50+
'@type': 'WebSite',
51+
url: 'https://example.org',
52+
name: 'Example',
53+
alternateName: ['Example Org', 'Example Organization'],
54+
publisher: {
55+
'@id': 'https://example.org/#organization',
56+
},
57+
},
58+
};
59+
60+
const webSiteVersions = versionSchemas(webSite100);
61+
export default webSiteVersions;

e2e/pages/jsonld/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const allJsonLDPages = [
3131
'videoGame',
3232
'webPage',
3333
'webPage2',
34+
'webSite',
3435
];
3536

3637
const Home = () => (

e2e/pages/jsonld/webSite/index.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import { WebSiteJsonLd } from '../../../..';
3+
4+
function WebPage() {
5+
return (
6+
<>
7+
<h1>WebSite</h1>
8+
<WebSiteJsonLd
9+
name="Example"
10+
alternateName={['Example Org', 'Example Organization']}
11+
url="https://example.org"
12+
publisher={{
13+
id: 'https://example.org/#organization',
14+
}}
15+
/>
16+
</>
17+
);
18+
}
19+
20+
export default WebPage;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import { WebSiteJsonLd } from '../../../..';
3+
4+
function WebPage() {
5+
return (
6+
<>
7+
<h1>WebSite</h1>
8+
<WebSiteJsonLd
9+
name="Example"
10+
alternateName="Example Organization"
11+
url="https://example.org"
12+
/>
13+
</>
14+
);
15+
}
16+
17+
export default WebPage;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import { WebSiteJsonLd } from '../../../..';
3+
4+
function WebPage() {
5+
return (
6+
<>
7+
<h1>WebSite</h1>
8+
<WebSiteJsonLd
9+
name="Example"
10+
alternateName={['Example Org', 'Example Organization']}
11+
url="https://example.org"
12+
/>
13+
</>
14+
);
15+
}
16+
17+
export default WebPage;

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ export {
7272
CampgroundJsonLdProps,
7373
} from './jsonld/campground';
7474
export { default as ParkJsonLd, ParkJsonLdProps } from './jsonld/park';
75+
export { default as WebSiteJsonLd, WebSiteJsonLdProps } from './jsonld/webSite';
7576
export { DefaultSeoProps, NextSeoProps } from './types';

0 commit comments

Comments
 (0)