react-schemaorg
Version:
Typed Schema.org JSON-LD in React
101 lines (100 loc) • 3.21 kB
TypeScript
/**
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/// <reference types="react" />
import { Thing, WithContext, Graph } from "schema-dts";
interface JsonLdOptions {
/** Adds indentation, white space, and line break characters to JSON-LD output. {@link JSON.stringify} */
space?: string | number;
}
/**
* Component that inline-includes a JSON-LD script where specified.
*
* For Example:
*
* ```tsx
* <JsonLd<Person>
* item={{
* "@context": "https://schema.org",
* "@type": "Person",
* name: "Grace Hopper",
* alternateName: "Grace Brewster Murray Hopper",
* alumniOf: {
* "@type": "CollegeOrUniversity",
* name: ["Yale University", "Vassar College"]
* },
* knowsAbout: ["Compilers", "Computer Science"]
* }}
* space={2}
* />
* ```
*/
export declare function JsonLd(props: JsonLdOptions & {
item: Graph;
}): JSX.Element;
export declare function JsonLd<T extends Thing>(props: JsonLdOptions & {
item: WithContext<T>;
}): JSX.Element;
/**
* Produces necessary props for a JSX <script> tag that includes JSON-LD.
*
* Can be used by spreading the props into a <script> JSX tag:
*
* ```tsx
* <script {...jsonLdScriptProps<Person>({
* "@context": "https://schema.org",
* "@type": "Person",
* name: "Grace Hopper",
* alternateName: "Grace Brewster Murray Hopper",
* alumniOf: {
* "@type": "CollegeOrUniversity",
* name: ["Yale University", "Vassar College"]
* },
* knowsAbout: ["Compilers", "Computer Science"]
* })} />
* ```
*/
export declare function jsonLdScriptProps(item: Graph, options?: JsonLdOptions): JSX.IntrinsicElements["script"];
export declare function jsonLdScriptProps<T extends Thing>(item: WithContext<T>, options?: JsonLdOptions): JSX.IntrinsicElements["script"];
/**
* Produces a Helmet-style <script> prop for a given JSON-LD datum.
*
* For example:
*
* ```tsx
* <Helmet script={[
* helmetJsonLdProp<Person>({
* "@context": "https://schema.org",
* "@type": "Person",
* name: "Grace Hopper",
* alternateName: "Grace Brewster Murray Hopper",
* alumniOf: {
* "@type": "CollegeOrUniversity",
* name: ["Yale University", "Vassar College"]
* },
* knowsAbout: ["Compilers", "Computer Science"]
* }),
* ]} />
* ```
*/
export declare function helmetJsonLdProp(item: Graph, options?: JsonLdOptions): {
type: "application/ld+json";
innerHTML: string;
};
export declare function helmetJsonLdProp<T extends Thing>(item: WithContext<T>, options?: JsonLdOptions): {
type: "application/ld+json";
innerHTML: string;
};
export {};