Skip to content

Commit

Permalink
Merge pull request #4 from Yoast/introduce-schema-component
Browse files Browse the repository at this point in the history
Introduce schema component
  • Loading branch information
jcomack committed Feb 5, 2020
2 parents 8603f48 + e61b35e commit a3376b3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/components/YoastSchemaExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import CodeBlock from '@theme/CodeBlock';

/**
* Outputs a properly formed JSON-LD tag to be used in the output.
*
* @param string jsonScript
*
* @returns {string} The HTML output.
*/
const toHTMLOutput = ( jsonScript ) => {
return `<script type="application/ld+json">${ jsonScript }</script>`;
};

/**
* The Yoast Schema Example component.
*
* @param {Object} props The props.
*
* @returns {JSX} The schema example component.
* @constructor
*/
const YoastSchemaExample = ( props ) => {
const cleaned = toHTMLOutput( props.children );

return (
<div className="schema_example">
<form action="https://search.google.com/structured-data/testing-tool" method="post" target="_blank">
<input className="button button--secondary" type="submit" value="See in the Google Structured Data Testing Tool" />
<textarea name="code" style={{display: "none"}} value={cleaned} readOnly></textarea>
</form>
<CodeBlock className="json">{props.children}</CodeBlock>
</div>
);
}

export default YoastSchemaExample;

0 comments on commit a3376b3

Please sign in to comment.