forked from garmeeh/next-seo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Corporate Contact JSON-LD (garmeeh#40)
Include support to [corporate contact](https://developers.google.com/search/docs/data-types/corporate-contact) and corresponding tests and documentation
- Loading branch information
Showing
7 changed files
with
311 additions
and
1 deletion.
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
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,100 @@ | ||
import { versionSchemas } from '@cypress/schema-tools'; | ||
|
||
const contactPoint100 = { | ||
version: { | ||
major: 1, | ||
minor: 0, | ||
patch: 0, | ||
}, | ||
schema: { | ||
type: 'object', | ||
description: 'Corporate Contact - ContactPoint', | ||
properties: { | ||
'@type': { | ||
type: 'string', | ||
description: 'ContactPoint', | ||
}, | ||
telephone: { | ||
type: 'string', | ||
description: 'Telephone number of the company', | ||
}, | ||
contactType: { | ||
type: 'string', | ||
description: 'The main usage of the phone number', | ||
}, | ||
areaServed: { | ||
type: ['string', 'array'], | ||
description: 'Geographical region served', | ||
}, | ||
availableLanguage: { | ||
type: ['string', 'array'], | ||
description: 'Language spoken', | ||
}, | ||
contactOption: { | ||
type: 'string', | ||
description: 'Details about the number', | ||
}, | ||
}, | ||
required: ['@type', 'telephone', 'contactType'], | ||
additionalProperties: false, | ||
}, | ||
example: { | ||
'@type': 'ContactPoint', | ||
contactType: 'customer service', | ||
telephone: '+1-877-746-0909', | ||
areaServed: 'US', | ||
availableLanguage: ['English', 'Spanish', 'French'], | ||
contactOption: 'TollFree', | ||
}, | ||
}; | ||
|
||
const corporateContact100 = { | ||
version: { | ||
major: 1, | ||
minor: 0, | ||
patch: 0, | ||
}, | ||
schema: { | ||
type: 'object', | ||
title: 'Corporate Contact', | ||
description: | ||
'An example schema describing JSON-LD for type: Corporate Contact', | ||
properties: { | ||
'@context': { | ||
type: 'string', | ||
description: 'Schema.org context', | ||
}, | ||
'@type': { | ||
type: 'string', | ||
description: 'Organization', | ||
}, | ||
url: { | ||
type: 'string', | ||
description: 'The URL of the website associated with the logo.', | ||
}, | ||
logo: { | ||
type: 'string', | ||
description: 'The url for the company logo', | ||
}, | ||
contactPoint: { | ||
type: 'array', | ||
items: { | ||
...contactPoint100.schema, | ||
}, | ||
see: contactPoint100, | ||
}, | ||
}, | ||
required: ['@context', '@type', 'url', 'contactPoint'], | ||
additionalProperties: false, | ||
}, | ||
example: { | ||
'@context': 'https://schema.org', | ||
'@type': 'Organization', | ||
url: 'http://www.your-company-site.com', | ||
logo: 'http://www.example.com/logo.png', | ||
contactPoint: [contactPoint100.example], | ||
}, | ||
}; | ||
|
||
const corporateContact = versionSchemas(corporateContact100); | ||
export default corporateContact; |
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
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,74 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Head from 'next/head'; | ||
|
||
import markup from '../utils/markup'; | ||
|
||
const formatIfArray = value => | ||
Array.isArray(value) ? `[${value.map(val => `"${val}"`)}]` : `"${value}"`; | ||
|
||
const buildContactPoint = contactPoint => | ||
contactPoint.map( | ||
contact => `{ | ||
"@type": "ContactPoint", | ||
"telephone": "${contact.telephone}", | ||
"contactType": "${contact.contactType}"${ | ||
contact.areaServed | ||
? `, | ||
"areaServed": ${formatIfArray(contact.areaServed)}` | ||
: '' | ||
}${ | ||
contact.availableLanguage | ||
? `, | ||
"availableLanguage": ${formatIfArray(contact.availableLanguage)}` | ||
: '' | ||
}${ | ||
contact.contactOption | ||
? `, | ||
"contactOption": "${contact.contactOption}"` | ||
: '' | ||
} | ||
}`, | ||
); | ||
const CorporateContactJsonLd = ({ url, logo, contactPoint = [] }) => { | ||
const jslonld = `{ | ||
"@context": "https://schema.org", | ||
"@type": "Organization", | ||
"url": "${url}", | ||
${logo ? `"logo": "${logo}",` : ''} | ||
"contactPoint": [${buildContactPoint(contactPoint)}] | ||
}`; | ||
|
||
return ( | ||
<Head> | ||
<script | ||
type="application/ld+json" | ||
dangerouslySetInnerHTML={markup(jslonld)} | ||
key="jsonld-corporate-contact" | ||
/> | ||
</Head> | ||
); | ||
}; | ||
|
||
CorporateContactJsonLd.defaultProps = { | ||
logo: null, | ||
}; | ||
|
||
CorporateContactJsonLd.propTypes = { | ||
logo: PropTypes.string, | ||
url: PropTypes.string.isRequired, | ||
contactPoint: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
telephone: PropTypes.string.isRequired, | ||
contactType: PropTypes.string.isRequired, | ||
areaServed: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), | ||
availableLanguage: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.array, | ||
]), | ||
contactOption: PropTypes.string, | ||
}), | ||
).isRequired, | ||
}; | ||
|
||
export default CorporateContactJsonLd; |