-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1337 from edenia/feat/add-structured-data-for-bps…
…-1292 Feat/add structured data for bps 1292
- Loading branch information
Showing
13 changed files
with
144 additions
and
46 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
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
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,100 @@ | ||
import { eosConfig } from '../config' | ||
|
||
const getNodesStructuredData = producer => { | ||
if (!producer.bp_json?.nodes?.length) return [] | ||
|
||
const structuredData = { nodes: [], inserted: [] } | ||
const nodesTypes = [ | ||
{ | ||
type: 'seed', | ||
endpoint: 'p2p_endpoint', | ||
name: `${eosConfig.networkLabel} P2P Endpoint`, | ||
description: 'P2P connectivity endpoints', | ||
}, | ||
{ | ||
type: 'query', | ||
endpoint: 'ssl_endpoint', | ||
name: `${eosConfig.networkLabel} API Endpoint`, | ||
description: 'HTTPS API access point', | ||
}, | ||
] | ||
|
||
for (const node of producer.bp_json?.nodes) { | ||
if (structuredData.inserted.includes(node.node_type)) continue | ||
|
||
const nodeType = nodesTypes.find( | ||
item => item.type === node.node_type && node[item.endpoint], | ||
) | ||
|
||
if (nodeType) { | ||
structuredData.inserted.push(node.node_type) | ||
structuredData.nodes.push({ | ||
'@type': 'webAPI', | ||
name: nodeType.name, | ||
description: nodeType.description, | ||
url: node[nodeType.endpoint], | ||
provider: { | ||
'@type': 'Organization', | ||
name: producer?.media?.name, | ||
}, | ||
}) | ||
} | ||
|
||
if (structuredData.inserted.length >= nodesTypes.length) { | ||
break | ||
} | ||
} | ||
|
||
return structuredData.nodes | ||
} | ||
|
||
export const getBPStructuredData = producer => { | ||
const sameAs = producer.social?.map(socialMedia => socialMedia.url) | ||
const hasValidLocation = Object.keys(producer.location || {}).every( | ||
(key) => !!producer.location[key], | ||
) | ||
|
||
if (producer.info?.codeOfConduct) { | ||
sameAs.push(producer.info?.codeOfConduct) | ||
} | ||
|
||
if (producer.info?.ownership) { | ||
sameAs.push(producer.info?.ownership) | ||
} | ||
|
||
const owns = getNodesStructuredData(producer) | ||
|
||
return { | ||
'@context': 'http://schema.org', | ||
'@type': 'Organization', | ||
name: producer?.media?.name, | ||
url: producer?.media?.website, | ||
...(producer?.media?.logo && { logo: producer.media?.logo }), | ||
...(producer.media?.email && { | ||
contactPoint: { | ||
'@type': 'ContactPoint', | ||
email: producer?.media?.email, | ||
contactType: 'customer service', | ||
}, | ||
}), | ||
...(hasValidLocation && { | ||
location: { | ||
'@type': 'Place', | ||
address: { | ||
'@type': 'PostalAddress', | ||
addressLocality: producer.location.name, | ||
addressCountry: producer.location.country, | ||
}, | ||
geo: { | ||
'@type': 'GeoCoordinates', | ||
latitude: producer.location.latitude, | ||
longitude: producer.location.longitude, | ||
}, | ||
}, | ||
}), | ||
...(sameAs.length && { sameAs }), | ||
...(owns.length && { owns }), | ||
} | ||
} | ||
|
||
export default getBPStructuredData |
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
export * from './format-with-thousand-separator' | ||
export * from './on-img-error' | ||
export * from './eos' | ||
export * from './format-with-thousand-separator' | ||
export * from './formatData' | ||
export * from './get-blocknum-url' | ||
export * from './get-bp-structured-data' | ||
export * from './get-endpoint-health-status' | ||
export * from './get-evmblocknum-url' | ||
export * from './get-range-options' | ||
export * from './get-transaction-url' | ||
export * from './on-img-error' | ||
export * from './sort-nodes' | ||
export * from './validate-account-name' | ||
export * from './validate-url' | ||
export * from './get-evmblocknum-url' | ||
export * from './get-endpoint-health-status' |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
const isUrlValid = (url) => { | ||
const isValidUrl = url => { | ||
const urlRegex = | ||
/(http|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])/ | ||
|
||
return url && urlRegex.test(url) | ||
} | ||
|
||
export default isUrlValid | ||
export default isValidUrl |