Skip to content

Commit

Permalink
[Feature] - OrganizationJsonLD & WebPageJsonLd & BrandJsonLd (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianu197 authored Jan 19, 2022
1 parent 9567570 commit 06d4c8b
Show file tree
Hide file tree
Showing 15 changed files with 780 additions and 65 deletions.
167 changes: 167 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ looking for inspiration on what to add.
- [Movie](#movie)
- [Recipe](#recipe-1)
- [Software App](#software-app)
- [Organization](#organization)
- [Brand](#brand)
- [WebPage](#webpage)
- [Contributors](#contributors)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down Expand Up @@ -2725,6 +2728,170 @@ export default () => (

For reference and more info check [Google docs for Software App](https://developers.google.com/search/docs/data-types/software-app)


### Organization

```jsx
import React from 'react';
import { OrganizationJsonLd } from 'next-seo';

export default () => (
<>
<h1>Organization JSON-LD</h1>
<OrganizationJsonLd
organizationType= "Corporation"
id="https://www.purpule-fox.io/#corporation"
logo="https://www.example.com/photos/logo.jpg"
legalName="Purple Fox LLC"
name="Purple Fox"
address={{
streetAddress: '1600 Saratoga Ave',
addressLocality: 'San Jose',
addressRegion: 'CA',
postalCode: '95129',
addressCountry: 'US',
}}
contactPoint={[
{
telephone: '+1-401-555-1212',
contactType: 'customer service',
areaServed: 'US',
availableLanguage: ['English', 'Spanish', 'French'],
},
{
telephone: '+1-877-746-0909',
contactType: 'customer service',
contactOption: 'TollFree',
availableLanguage: 'English',
},
{
telephone: '+1-877-453-1304',
contactType: 'technical support',
contactOption: 'TollFree',
areaServed: ['US', 'CA'],
availableLanguage: ['English', 'French'],
},
]}
sameAs={['https://www.orange-fox.com']}
url= 'https://www.purpule-fox.io/'
/>
</>
);
```

**Data required properties**

| Property | Info |
| -------------------------- | -------------------------------------------------------------------------------------------------------- |
| `name` | The name of the Organization. |
| `url` | Url of the organization |
| `contactPoint` | |
| `contactPoint.telephone` | An internationalized version of the phone number, starting with the "+" symbol and country code |
| `contactPoint.contactType` | Description of the purpose of the phone number i.e. `Technical Support`. |
**Data Recommended properties**

| Property | Info |
| -------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `logo` | ImageObject or URL an associated logo to the Organization. |
| `organizationType` | Organization type, check [here](https://schema.org/Organization#subtypes) |
| `legalName` | The official name of the organization, e.g. the registered company name. |
| `sameAs` | URL of a reference Web page that unambiguously indicates the item's identity. |
| `address` | Address of the specific business location |
| `address.addressCountry` | The 2-letter ISO 3166-1 alpha-2 country code |
| `address.addressLocality` | City |
| `address.addressRegion` | State or province, if applicable. |
| `address.postalCode` | Postal or zip code. |
| `address.streetAddress` | Street number, street name, and unit number. |
| `contactPoint.areaServed` | `String` or `Array` of geographical regions served by the business. Example `"US"` or `["US", "CA", "MX"]` |
| `contactPoint.availableLanguage` | Details about the language spoken. Example `"English"` or `["English", "French"]` |

For reference and more info check [Docs](https://schema.org/Organization)


### Brand

```jsx
import React from 'react';
import { BrandJsonLd } from 'next-seo';

export default () => (
<>
<h1>Brand JSON-LD</h1>
<BrandJsonLd
slogan= "What does the fox say?"
id="https://www.purpule-fox.io/#corporation"
logo="https://www.example.com/photos/logo.jpg"
aggregateRating={{
ratingValue: '5',
ratingCount: '18',
}}
/>
</>
);
```

**Data required properties**

| Property | Info |
| -------------------------- | -------------------------------------------------------------------------------------------------------- |
| `id` | 'URL to main entity of page' |

**Data Recommended properties**

| Property | Info |
| ------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `logo` | ImageObject or URL an associated logo to the Organization. |
| `slogan` | A slogan or motto associated with the item. |
| `aggregateRating.ratingValue` | The rating for the content.(Check the [reference](https://schema.org/ratingValue) |
| `aggregateRating.ratingCount` | The count of total number of ratings. |
| `aggregateRating.reviewCount` | The count of total number of reviews. |
| `aggregateRating.bestRating` | The highest value allowed in this rating system. If bestRating is omitted, 5 is assumed. |


For reference and more info check [Docs](https://schema.org/Brand)


### WebPage

```jsx
import React from 'react';
import { WebPageJsonLd } from 'next-seo';

export default () => (
<>
<h1>WebPage JSON-LD</h1>
<WebPageJsonLd
description= "What does the fox say?"
id="https://www.purpule-fox.io/#corporation"
lastReviewed="2021-05-26T05:59:02.085Z"
reviewedBy={{
type: 'Person',
name: 'Garmeeh',
}}
/>
</>
);
```

**Data required properties**

| Property | Info |
| -------------------------- | -------------------------------------------------------------------------------------------------------- |
| `id` | 'URL to main entity of page' |

**Data Recommended properties**

| Property | Info |
| ------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `description` | ImageObject or URL an associated logo to the Organization. |
| `lastReviewed` | Date on which the content on this web page was last reviewed for accuracy and/or completeness. |
| `reviewedBy.type` | People or organizations that will review the content of the web page. |
| `reviewedBy.name` | Name of the entity that have reviewed the content on this web page for accuracy and/or completeness. |


For reference and more info check [Docs](https://schema.org/Brand)


## Contributors

Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
Expand Down
112 changes: 111 additions & 1 deletion cypress/e2e/jsonld.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertSchema } from '@cypress/schema-tools';
import schemas from '../schemas';

const expectedJSONResults = 23;
const expectedJSONResults = 26;

const articleLdJsonIndex = 0;
const breadcrumbLdJsonIndex = 1;
Expand All @@ -26,6 +26,9 @@ const softwareAppJsonIndex = 19;
const collectionPageLdJsonIndex = 20;
const profilePageLdJsonIndex = 21;
const videoGameLdJsonIndex = 22;
const organizationLdJsonIndex = 23;
const brandLdJsonIndex = 24;
const webPageLdJsonIndex = 25;

describe('Validates JSON-LD For:', () => {
it('Article', () => {
Expand Down Expand Up @@ -1845,4 +1848,111 @@ describe('Validates JSON-LD For:', () => {
});
});
});

it('Organization', () => {
cy.visit('http://localhost:3000/jsonld');
cy.get('head script[type="application/ld+json"]')
.should('have.length', expectedJSONResults)
.then(tags => {
const jsonLD = JSON.parse(tags[organizationLdJsonIndex].innerHTML);
assertSchema(schemas)('Organization', '1.0.0')(jsonLD);
});
});

it('Organization Matches', () => {
cy.visit('http://localhost:3000/jsonld');
cy.get('head script[type="application/ld+json"]')
.should('have.length', expectedJSONResults)
.then(tags => {
const jsonLD = JSON.parse(tags[organizationLdJsonIndex].innerHTML);
expect(jsonLD).to.deep.equal({
'@context': 'https://schema.org',
'@id': 'https://www.purpule-fox.io/#corporation',
'@type': 'Corporation',
name: 'Purple Fox',
legalName: 'Purple Fox LLC',
logo: 'https://www.example.com/photos/logo.jpg',
url: 'https://www.purpule-fox.io/',
address: {
'@type': 'PostalAddress',
streetAddress: '1600 Saratoga Ave',
addressLocality: 'San Jose',
addressRegion: 'CA',
postalCode: '95129',
addressCountry: 'US',
},
contactPoints: [
{
'@type': 'ContactPoint',
contactType: 'customer service',
telephone: '+1-877-746-0909',
areaServed: 'US',
availableLanguage: ['English', 'Spanish', 'French'],
contactOption: 'TollFree',
},
],
sameAs: ['https://www.orange-fox.com'],
});
});
});
it('Brand', () => {
cy.visit('http://localhost:3000/jsonld');
cy.get('head script[type="application/ld+json"]')
.should('have.length', expectedJSONResults)
.then(tags => {
const jsonLD = JSON.parse(tags[brandLdJsonIndex].innerHTML);
assertSchema(schemas)('Brand', '1.0.0')(jsonLD);
});
});

it('Brand Matches', () => {
cy.visit('http://localhost:3000/jsonld');
cy.get('head script[type="application/ld+json"]')
.should('have.length', expectedJSONResults)
.then(tags => {
const jsonLD = JSON.parse(tags[brandLdJsonIndex].innerHTML);
expect(jsonLD).to.deep.equal({
'@context': 'https://schema.org',
'@type': 'Brand',
'@id': 'https://www.purpule-fox.io/#brand',
logo: 'https://www.example.com/photos/logo.jpg',
slogan: 'What does the fox say?',
aggregateRating: {
'@type': 'AggregateRating',
ratingValue: '4.4',
reviewCount: '89',
},
});
});
});

it('WebPage', () => {
cy.visit('http://localhost:3000/jsonld');
cy.get('head script[type="application/ld+json"]')
.should('have.length', expectedJSONResults)
.then(tags => {
const jsonLD = JSON.parse(tags[webPageLdJsonIndex].innerHTML);
assertSchema(schemas)('WebPage', '1.0.0')(jsonLD);
});
});

it('WebPage Matches', () => {
cy.visit('http://localhost:3000/jsonld');
cy.get('head script[type="application/ld+json"]')
.should('have.length', expectedJSONResults)
.then(tags => {
const jsonLD = JSON.parse(tags[webPageLdJsonIndex].innerHTML);
expect(jsonLD).to.deep.equal({
'@context': 'https://schema.org',
'@type': 'WebPage',
'@id': 'https://www.purpule-fox.io/#info',
description: 'This is a description.',
lastReviewed: '2021-05-26T05:59:02.085Z',
reviewedBy: {
'@type': 'Organization',
name: 'Garmeeh',
},
});
});
});
});
53 changes: 53 additions & 0 deletions cypress/schemas/brand-schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { versionSchemas } from '@cypress/schema-tools';

import { aggregateRating100 } from './common';

const brand100 = {
version: {
major: 1,
minor: 0,
patch: 0,
},
schema: {
type: 'object',
title: 'Brand',
description: 'Bramd description with slogan and some characteristics.',
properties: {
'@context': {
type: 'string',
description: 'Schema.org context',
},
'@type': {
type: 'string',
description: 'JSON-LD type: PostalAddress',
},
'@id': {
type: 'string',
description: 'URL to main entity of page',
},
logo: {
type: 'string',
description: "Url of the Organization's logo",
},
slogan: {
type: 'string',
description: 'Slogan of the brand',
},
aggregateRating: {
...aggregateRating100.schema,
see: aggregateRating100,
},
},
},
example: {
'@context': 'https://schema.org',
'@type': 'Brand',
'@id': 'https://www.purpule-fox.io/#corporation',
logo: 'https://www.example.com/photos/logo.jpg',
slogan: 'What does the fox say?',
aggregateRating: aggregateRating100.example,
},
};

const brandVersions = versionSchemas(brand100);
export default brandVersions;
Loading

0 comments on commit 06d4c8b

Please sign in to comment.