gatsby-plugin-next-seo
Version:
SEO plugin for Gatsby projects
203 lines (186 loc) • 7.29 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.NewsArticleJsonLd = exports.BlogPostJsonLd = exports.ArticleJsonLd = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
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; }
/**
* An article, such as a news article or piece of investigative report.
* Newspapers and magazines have articles of many different types and this is
* intended to cover them all.
*
* See also
* {@link http://blog.schema.org/2014/09/schemaorg-support-for-bibliographic_2.html | blog post}.
*/
var ArticleJsonLd = function ArticleJsonLd(_ref) {
var url = _ref.url,
headline = _ref.headline,
title = _ref.title,
_ref$images = _ref.images,
images = _ref$images === void 0 ? [] : _ref$images,
datePublished = _ref.datePublished,
dateCreated = _ref.dateCreated,
_ref$dateModified = _ref.dateModified,
dateModified = _ref$dateModified === void 0 ? datePublished : _ref$dateModified,
_ref$authorType = _ref.authorType,
authorType = _ref$authorType === void 0 ? 'Person' : _ref$authorType,
authorName = _ref.authorName,
description = _ref.description,
publisherName = _ref.publisherName,
publisherLogo = _ref.publisherLogo,
body = _ref.body,
overrides = _ref.overrides,
keywords = _ref.keywords,
speakable = _ref.speakable,
_ref$defer = _ref.defer,
defer = _ref$defer === void 0 ? false : _ref$defer;
var json = _objectSpread({
'@context': 'https://schema.org',
'@type': 'Article',
mainEntityOfPage: {
'@type': 'WebPage',
'@id': url
},
headline: headline !== null && headline !== void 0 ? headline : title,
image: images,
datePublished: datePublished,
dateModified: dateModified,
dateCreated: dateCreated,
author: {
'@type': authorType,
name: authorName
},
publisher: {
'@type': 'Organization',
name: publisherName,
logo: {
'@type': 'ImageObject',
url: publisherLogo
}
},
description: description,
articleBody: body,
speakable: speakable ? speakable.map(function (item) {
return _objectSpread({
'@type': 'SpeakableSpecification'
}, item);
}) : undefined,
keywords: Array.isArray(keywords) ? keywords.join(', ') : keywords
}, overrides);
return /*#__PURE__*/_react["default"].createElement(_jsonld.JsonLd, {
defer: defer,
json: json
});
};
exports.ArticleJsonLd = ArticleJsonLd;
/**
* A utility component which wraps the `<ArticleJsonLd />` component but is
* classified as a `BlogPosting`.
*
* @remarks
*
* ```jsx
* import React from 'react';
* import { BlogPostJsonLd } from 'gatsby-plugin-next-seo';
*
* export default () => (
* <>
* <h1>Blog Post JSON-LD</h1>
* <BlogPostJsonLd
* url='https://example.com/blog'
* title='Blog headline'
* images={[
* 'https://example.com/photos/1x1/photo.jpg',
* 'https://example.com/photos/4x3/photo.jpg',
* 'https://example.com/photos/16x9/photo.jpg',
* ]}
* datePublished='2015-02-05T08:00:00+08:00'
* dateModified='2015-02-05T09:00:00+08:00'
* authorName='Jane Blogs'
* description='This is a mighty good description of this blog.'
* />
* </>
* );
* ```
*
* @public
*/
var BlogPostJsonLd = function BlogPostJsonLd(_ref2) {
var overrides = _ref2.overrides,
_ref2$defer = _ref2.defer,
defer = _ref2$defer === void 0 ? false : _ref2$defer,
_ref2$publisherLogo = _ref2.publisherLogo,
publisherLogo = _ref2$publisherLogo === void 0 ? '' : _ref2$publisherLogo,
_ref2$publisherName = _ref2.publisherName,
publisherName = _ref2$publisherName === void 0 ? '' : _ref2$publisherName,
props = (0, _objectWithoutProperties2["default"])(_ref2, ["overrides", "defer", "publisherLogo", "publisherName"]);
return /*#__PURE__*/_react["default"].createElement(ArticleJsonLd, (0, _extends2["default"])({
defer: defer,
publisherName: publisherName,
publisherLogo: publisherLogo
}, props, {
overrides: _objectSpread(_objectSpread({}, overrides), {}, {
'@type': 'BlogPosting'
})
}));
};
exports.BlogPostJsonLd = BlogPostJsonLd;
/**
* A utility component which wraps the `<ArticleJsonLd />` component but is
* classified as a `NewsArticle`.
*
* @remarks
*
* ```tsx
* import React from 'react';
* import { NewsArticleJsonLd } from 'gatsby-plugin-next-seo';
*
* export default () => (
* <>
* <h1>News Article JSON-LD</h1>
* <NewsArticleJsonLd
* url='https://example.com/article'
* title='Article headline'
* images={[
* 'https://example.com/photos/1x1/photo.jpg',
* 'https://example.com/photos/4x3/photo.jpg',
* 'https://example.com/photos/16x9/photo.jpg',
* ]}
* section='politic'
* keywords='prayuth,taksin'
* datePublished='2015-02-05T08:00:00+08:00'
* dateModified='2015-02-05T09:00:00+08:00'
* authorName='Jane Blogs'
* publisherName='Ifiok Jr.'
* publisherLogo='https://www.example.com/photos/logo.jpg'
* description='This is a mighty good description of this article.'
* body='This is all text for this news article'
* />
* </>
* );
* ```
*/
var NewsArticleJsonLd = function NewsArticleJsonLd(_ref3) {
var overrides = _ref3.overrides,
section = _ref3.section,
_ref3$defer = _ref3.defer,
defer = _ref3$defer === void 0 ? false : _ref3$defer,
props = (0, _objectWithoutProperties2["default"])(_ref3, ["overrides", "section", "defer"]);
return /*#__PURE__*/_react["default"].createElement(ArticleJsonLd, (0, _extends2["default"])({
defer: defer
}, props, {
overrides: _objectSpread(_objectSpread({
articleSection: section
}, overrides), {}, {
'@type': 'NewsArticle'
})
}));
};
exports.NewsArticleJsonLd = NewsArticleJsonLd;