Skip to content

Commit

Permalink
added new schema.org types and added tests
Browse files Browse the repository at this point in the history
BREAKING CHANGE: code was rearranged
  • Loading branch information
olexiyk committed Aug 23, 2019
1 parent da9422c commit 6ea022c
Show file tree
Hide file tree
Showing 68 changed files with 11,770 additions and 866 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@researchgate/spire-config/eslint');
34 changes: 16 additions & 18 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
---
name: Bug report
about: Create a report to help us improve

---

**Describe the bug**
A clear and concise description of what the bug is.
**Describe the bug** A clear and concise description of what the bug is.

**To Reproduce** Steps to reproduce the behavior:

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.
**Expected behavior** A clear and concise description of what you expected to
happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.
**Screenshots** If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context** Add any other context about the problem here.
17 changes: 8 additions & 9 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
---
name: Feature request
about: Suggest an idea for this project

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Is your feature request related to a problem? Please describe.** A clear and
concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe the solution you'd like** A clear and concise description of what you
want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Describe alternatives you've considered** A clear and concise description of
any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
**Additional context** Add any other context or screenshots about the feature
request here.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/dist

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
Expand All @@ -20,5 +19,4 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn.lock
*.tgz
/lib/
190 changes: 119 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [React Structured Data](#react-structured-data)
- [Installation](#installation)
- [Yarn](#yarn)
- [NPM](#npm)
- [Code Example](#code-example)
- [Reference](#reference)
- [PropTypes](#proptypes)
- [Preset Components](#preset-components)
- [Structured Data and Schema.org](#structured-data-and-schemaorg)
- [Contributors](#contributors)
- [License](#license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# React Structured Data

React Structured Data provides an easy way to add structured data to your React apps. Structured data is a standardized format for providing information about a page and classifying the page content. This library follows guidelines specified at http://schema.org/.
React Structured Data provides an easy way to add structured data to your React
apps. Structured data is a standardized format for providing information about a
page and classifying the page content. This library follows guidelines specified
at http://schema.org/.

## Installation

Expand All @@ -17,69 +37,77 @@ React Structured Data provides an easy way to add structured data to your React
The following JSX:

```jsx
<JSONLD>
<Product name="Product Name">
<AggregateRating ratingValue={4.3} reviewCount={197}/>
<GenericCollection type="review">
<Review name="It's awesome" reviewBody="This is Great! My family loves it" datePublished="11/22/1963">
<Author name="Jerry"/>
<Location name="Chicago, IL"/>
<Rating ratingValue={5} />
</Review>
<Review name="Very cool" reviewBody="I like this a lot. Very cool product" datePublished="11/22/1963">
<Author name="Cool Carl"/>
<Location name="Chicago, IL"/>
<Rating ratingValue={4} />
</Review>
</GenericCollection>
</Product>
</JSONLD>
<JSONLD>
<Product name="Product Name">
<AggregateRating ratingValue={4.3} reviewCount={197} />
<GenericNodeCollection type="review">
<Review
name="It's awesome"
reviewBody="This is Great! My family loves it"
datePublished="11/22/1963"
>
<Author name="Jerry" />
<Location name="Chicago, IL" />
<Rating ratingValue={5} />
</Review>
<Review
name="Very cool"
reviewBody="I like this a lot. Very cool product"
datePublished="11/22/1963"
>
<Author name="Cool Carl" />
<Location name="Chicago, IL" />
<Rating ratingValue={4} />
</Review>
</GenericCollection>
</Product>
</JSONLD>
```

will add the following to your markup (will be minified):

```html
<script type="application/ld+json">
{
"@context":"https://schema.org/",
"@type":"Product",
"name":"Product Name",
"@context": "https://schema.org/",
"@type": "Product",
"name": "Product Name",
"aggregateRating": {
"@type":"AggregateRating",
"ratingValue":4.3,
"reviewCount":197
"@type": "AggregateRating",
"ratingValue": 4.3,
"reviewCount": 197
},
"review":[
"review": [
{
"@type":"Review",
"datePublished":"11/22/1963",
"reviewBody":"This is Great! My family loves it",
"name":"It's awesome",
"@type": "Review",
"datePublished": "11/22/1963",
"reviewBody": "This is Great! My family loves it",
"name": "It's awesome",
"author": {
"@type":"Person",
"name":"Jerry"
"@type": "Person",
"name": "Jerry"
},
"locationCreated": {
"@type":"AdministrativeArea",
"name":"Chicago, IL"
"@type": "AdministrativeArea",
"name": "Chicago, IL"
},
"reviewRating": {
"@type": "Rating",
"ratingValue": 5
}
},
{
"@type":"Review",
"datePublished":"11/22/1963",
"reviewBody":"I like this a lot. Very cool product",
"name":"Very cool",
"author":{
"@type":"Person",
"name":"Cool Carl"
"@type": "Review",
"datePublished": "11/22/1963",
"reviewBody": "I like this a lot. Very cool product",
"name": "Very cool",
"author": {
"@type": "Person",
"name": "Cool Carl"
},
"locationCreated": {
"@type":"AdministrativeArea",
"name":"Chicago, IL"
"@type": "AdministrativeArea",
"name": "Chicago, IL"
},
"reviewRating": {
"@type": "Rating",
Expand All @@ -97,32 +125,27 @@ will add the following to your markup (will be minified):

#### Generic Component PropTypes


| PropType | Value | Description |
| ------------- | ------------- | ------ |
| type | String | The @type description in the json-ld body: `"@type": "Product"` |
| jsonldtype | String | The value of the @type description in the json-ld body: `"@type": "Product"` |
| schema | Object (json) | This should be the schema that you want for your structured data node: `{name: "It is awesome", reviewBody: "This is great!"}` |

| PropType | Value | Description |
| ---------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| type | String | The @type description in the json-ld body: `"@type": "Product"` |
| jsonldtype | String | The value of the @type description in the json-ld body: `"@type": "Product"` |
| schema | Object (json) | This should be the schema that you want for your structured data node: `{name: "It is awesome", reviewBody: "This is great!"}` |

#### JSONLD node propTypes


| PropType | Value | Description |
| ------------- | ----------- | ------ |
| dangerouslyExposeHtml | Boolean | Set this to render the json within script tag using `dangerouslySetInnerHTML` |

| PropType | Value | Description |
| --------------------- | ------- | ----------------------------------------------------------------------------- |
| dangerouslyExposeHtml | Boolean | Set this to render the json within script tag using `dangerouslySetInnerHTML` |

#### Schema node PropTypes


| PropType | Value | Description |
| ------------- | ------------- | ------ |
| parentID | String | Sets the id of the schema that becomes a reference that the children point to `"@id": "product-x"` |
| id | String | similar to parentID but uses the ID on itself |

| PropType | Value | Description |
| -------- | ------ | -------------------------------------------------------------------------------------------------- |
| parentID | String | Sets the id of the schema that becomes a reference that the children point to `"@id": "product-x"` |
| id | String | similar to parentID but uses the ID on itself |

### Preset Components

There are several preset schema components that can be used

- AggregateRating
Expand All @@ -134,19 +157,41 @@ There are several preset schema components that can be used
- Question
- Rating
- Review
- QAPage
- Organisation
- Person
- Review
- Place

If you would like to use a component that is not listed, simply use the Generic component and add the prop jsonldtype.
Generic and GenericCollection allow you to add your own structured data type.
If you would like to use a component that is not listed, simply use the Generic
component and add the prop type. Generic and GenericCollection allow you to add
your own structured data type.

For example, If Review preset didn't exist, you could write:

```jsx
<JSONLD>
<Generic type="review" jsonldtype="Review" schema={{name: "It is awesome", reviewBody: "This is great!"}}>
<Generic type="itemReviewed" jsonldtype="Product" schema={{"@id":"product-x"}} />
<Generic type="author" jsonldtype="Person" schema={{name: "Cool Carl"}}/>
<Generic type="locationCreated" jsonldtype="AdministrativeArea" schema={{name: "Chicago, IL"}}/>
</Generic>
<GenericNode
type="review"
jsonldtype="Review"
schema={{ name: 'It is awesome', reviewBody: 'This is great!' }}
>
<GenericNode
type="itemReviewed"
jsonldtype="Product"
schema={{ '@id': 'product-x' }}
/>
<GenericNode
type="author"
jsonldtype="Person"
schema={{ name: 'Cool Carl' }}
/>
<GenericNode
type="locationCreated"
jsonldtype="AdministrativeArea"
schema={{ name: 'Chicago, IL' }}
/>
</GenericNode>
</JSONLD>
```

Expand Down Expand Up @@ -175,13 +220,16 @@ This will output (minified):
</script>
```

This may seem not as ideal as using the presets, but this allows completely customizable structured data.
There will also be more preset components to come in future releases to make implementation easier so stay tuned!
This may seem not as ideal as using the presets, but this allows completely
customizable structured data. There will also be more preset components to come
in future releases to make implementation easier so stay tuned!

### Structured Data and Schema.org

For more information on Structured data, visit https://developers.google.com/search/docs/guides/intro-structured-data, and also http://schema.org/.
You can also validate the structured data here: https://search.google.com/structured-data/testing-tool.
For more information on Structured data, visit
https://developers.google.com/search/docs/guides/intro-structured-data, and also
http://schema.org/. You can also validate the structured data here:
https://search.google.com/structured-data/testing-tool.

## Contributors

Expand Down
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ["@researchgate/babel-preset"]
};
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: "spire-plugin-jest",
testEnvironment: "node"
};
Loading

0 comments on commit 6ea022c

Please sign in to comment.