UNPKG

gatsby-plugin-next-seo

Version:
128 lines (115 loc) 4.45 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.BookJsonLd = void 0; var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _react = _interopRequireDefault(require("react")); var _jsonld = require("./jsonld"); function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } var getBookFormat = function getBookFormat(type) { return type ? "https://schema.org/".concat(type) : undefined; }; /** * The `Book` component makes search engines an entry point for discovering your * books and authors. Users can then buy the books that they find directly from * Search results. * * @remarks * * An example feed is shown below. * * ```tsx * import React from 'react'; * import { CourseJsonLd } from 'gatsby-plugin-next-seo'; * * export default () => ( * <> * <h1>Book JSON-LD</h1> * <BookJsonLd * author={{ name: 'Tolu B.' }} * url='https://example.com/tolub' * name='Rock your world - the final chapter' * workExample={[ * { * bookFormat: 'AudiobookFormat', * isbn: '123123123', * potentialAction: { * expectsAcceptanceOf: { * '@type': 'Offer', * price: '6.99', * priceCurrency: 'USD', * eligibleRegion: { * '@type': 'Country', * name: 'US', * }, * availability: 'http://schema.org/InStock', * }, * target: { * '@type': 'EntryPoint', * urlTemplate: 'http://www.barnesandnoble.com/store/info/offer/0316769487?purchase=true', * actionPlatform: [ * 'http://schema.org/DesktopWebPlatform', * 'http://schema.org/IOSPlatform', * 'http://schema.org/AndroidPlatform', * ], * }, * }, * }, * ]} * /> * </> * ); * ``` * * @public */ var BookJsonLd = function BookJsonLd(_ref) { var name = _ref.name, author = _ref.author, url = _ref.url, _ref$workExample = _ref.workExample, workExample = _ref$workExample === void 0 ? [] : _ref$workExample, id = _ref.id, sameAs = _ref.sameAs, _ref$overrides = _ref.overrides, overrides = _ref$overrides === void 0 ? {} : _ref$overrides, _ref$defer = _ref.defer, defer = _ref$defer === void 0 ? false : _ref$defer; var json = _objectSpread({ '@context': 'https://schema.org', '@type': 'Book', name: name, url: url, '@id': id, sameAs: sameAs, author: _objectSpread({ '@type': 'Person' }, author), workExample: workExample.map(function (_ref2) { var bookFormat = _ref2.bookFormat, potentialAction = _ref2.potentialAction, author = _ref2.author, rest = (0, _objectWithoutProperties2["default"])(_ref2, ["bookFormat", "potentialAction", "author"]); return _objectSpread(_objectSpread({ '@type': 'Book', bookFormat: getBookFormat(bookFormat) }, rest), {}, { person: _objectSpread({ '@type': 'Person' }, author), potentialAction: _objectSpread({ '@type': 'ReadAction' }, potentialAction) }); }) }, overrides); return /*#__PURE__*/_react["default"].createElement(_jsonld.JsonLd, { defer: defer, json: json }); }; exports.BookJsonLd = BookJsonLd;