@mjhls/mjh-framework 1.0.840 → 1.0.841

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # mjh-framework v. 1.0.840
1
+ # mjh-framework v. 1.0.841
2
2
 
3
3
  [![NPM](https://img.shields.io/npm/v/mjh-framework.svg)](https://www.npmjs.com/package/mjh-framework) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
4
4
 
package/dist/cjs/View.js CHANGED
@@ -442,6 +442,85 @@ var getSocialShareDisableFlag = function getSocialShareDisableFlag(article) {
442
442
  return showSocialShare;
443
443
  };
444
444
 
445
+ function toPlainText() {
446
+ var blocks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
447
+
448
+ return blocks
449
+ // loop through each block
450
+ .map(function (block) {
451
+ // if it's not a text block with children,
452
+ // return nothing
453
+ if (block._type !== 'block' || !block.children) {
454
+ return '';
455
+ }
456
+ // loop through the children spans, and join the
457
+ // text strings
458
+ return block.children.map(function (child) {
459
+ return child.text;
460
+ }).join('');
461
+ })
462
+ // join the paragraphs leaving split by two linebreaks
463
+ .join('\n\n');
464
+ }
465
+
466
+ function generateSchema(props) {
467
+ var _props$article = props.article,
468
+ title = _props$article.title,
469
+ body = _props$article.body,
470
+ summary = _props$article.summary,
471
+ url = _props$article.url,
472
+ content_placement = _props$article.content_placement,
473
+ authorDetails = _props$article.authorDetails,
474
+ thumbnail = _props$article.thumbnail,
475
+ published = _props$article.published,
476
+ _updatedAt = _props$article._updatedAt,
477
+ seoTag = _props$article.seoTag,
478
+ _props$Website = props.Website,
479
+ liveDomain = _props$Website.liveDomain,
480
+ websiteTitle = _props$Website.title,
481
+ logo = _props$Website.logo,
482
+ client = props.client;
483
+
484
+ var isAuthorFound = authorDetails && authorDetails.length > 0 && authorDetails[0].displayName;
485
+ var articleSection = content_placement && content_placement.map(function (cp) {
486
+ return cp.name;
487
+ });
488
+
489
+ if (title && thumbnail && published && websiteTitle && liveDomain && logo && isAuthorFound) {
490
+ return {
491
+ '@context': 'https://schema.org',
492
+ '@type': 'NewsArticle',
493
+ mainEntityOfPage: 'https://' + liveDomain + '/view/' + url.current,
494
+ headline: title,
495
+ description: summary,
496
+ articleBody: toPlainText(body),
497
+ inLanguage: 'en-US',
498
+ image: urlFor({ source: thumbnail, client: client }),
499
+ keywords: seoTag.join(),
500
+ articleSection: articleSection,
501
+ author: {
502
+ '@type': 'Person',
503
+ name: authorDetails[0].displayName
504
+ },
505
+ publisher: {
506
+ '@type': 'Organization',
507
+ name: websiteTitle,
508
+ logo: {
509
+ '@type': 'ImageObject',
510
+ url: 'https://' + liveDomain + logo
511
+ }
512
+ },
513
+ datePublished: published,
514
+ dateModified: _updatedAt
515
+ };
516
+ }
517
+ return null;
518
+ }
519
+
520
+ var Schema = function Schema(props) {
521
+ return React__default['default'].createElement('script', { type: 'application/ld+json', dangerouslySetInnerHTML: { __html: stringify._JSON$stringify(generateSchema(props)) } });
522
+ };
523
+
445
524
  var Article = React.forwardRef(function (props, ref) {
446
525
  var onVote = function () {
447
526
  var _ref = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee(nodeKey, selectedChoice) {
@@ -1288,7 +1367,8 @@ var Article = React.forwardRef(function (props, ref) {
1288
1367
  )
1289
1368
  )
1290
1369
  ),
1291
- props.infiniteScroll && React__default['default'].createElement('hr', { className: 'article-seperater mb-5 mt-3' })
1370
+ props.infiniteScroll && React__default['default'].createElement('hr', { className: 'article-seperater mb-5 mt-3' }),
1371
+ React__default['default'].createElement(Schema, { article: props.article, Website: props.Website, client: props.client })
1292
1372
  );
1293
1373
  };
1294
1374
 
package/dist/esm/View.js CHANGED
@@ -432,6 +432,85 @@ var getSocialShareDisableFlag = function getSocialShareDisableFlag(article) {
432
432
  return showSocialShare;
433
433
  };
434
434
 
435
+ function toPlainText() {
436
+ var blocks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
437
+
438
+ return blocks
439
+ // loop through each block
440
+ .map(function (block) {
441
+ // if it's not a text block with children,
442
+ // return nothing
443
+ if (block._type !== 'block' || !block.children) {
444
+ return '';
445
+ }
446
+ // loop through the children spans, and join the
447
+ // text strings
448
+ return block.children.map(function (child) {
449
+ return child.text;
450
+ }).join('');
451
+ })
452
+ // join the paragraphs leaving split by two linebreaks
453
+ .join('\n\n');
454
+ }
455
+
456
+ function generateSchema(props) {
457
+ var _props$article = props.article,
458
+ title = _props$article.title,
459
+ body = _props$article.body,
460
+ summary = _props$article.summary,
461
+ url = _props$article.url,
462
+ content_placement = _props$article.content_placement,
463
+ authorDetails = _props$article.authorDetails,
464
+ thumbnail = _props$article.thumbnail,
465
+ published = _props$article.published,
466
+ _updatedAt = _props$article._updatedAt,
467
+ seoTag = _props$article.seoTag,
468
+ _props$Website = props.Website,
469
+ liveDomain = _props$Website.liveDomain,
470
+ websiteTitle = _props$Website.title,
471
+ logo = _props$Website.logo,
472
+ client = props.client;
473
+
474
+ var isAuthorFound = authorDetails && authorDetails.length > 0 && authorDetails[0].displayName;
475
+ var articleSection = content_placement && content_placement.map(function (cp) {
476
+ return cp.name;
477
+ });
478
+
479
+ if (title && thumbnail && published && websiteTitle && liveDomain && logo && isAuthorFound) {
480
+ return {
481
+ '@context': 'https://schema.org',
482
+ '@type': 'NewsArticle',
483
+ mainEntityOfPage: 'https://' + liveDomain + '/view/' + url.current,
484
+ headline: title,
485
+ description: summary,
486
+ articleBody: toPlainText(body),
487
+ inLanguage: 'en-US',
488
+ image: urlFor({ source: thumbnail, client: client }),
489
+ keywords: seoTag.join(),
490
+ articleSection: articleSection,
491
+ author: {
492
+ '@type': 'Person',
493
+ name: authorDetails[0].displayName
494
+ },
495
+ publisher: {
496
+ '@type': 'Organization',
497
+ name: websiteTitle,
498
+ logo: {
499
+ '@type': 'ImageObject',
500
+ url: 'https://' + liveDomain + logo
501
+ }
502
+ },
503
+ datePublished: published,
504
+ dateModified: _updatedAt
505
+ };
506
+ }
507
+ return null;
508
+ }
509
+
510
+ var Schema = function Schema(props) {
511
+ return React.createElement('script', { type: 'application/ld+json', dangerouslySetInnerHTML: { __html: _JSON$stringify(generateSchema(props)) } });
512
+ };
513
+
435
514
  var Article = forwardRef(function (props, ref) {
436
515
  var onVote = function () {
437
516
  var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(nodeKey, selectedChoice) {
@@ -1278,7 +1357,8 @@ var Article = forwardRef(function (props, ref) {
1278
1357
  )
1279
1358
  )
1280
1359
  ),
1281
- props.infiniteScroll && React.createElement('hr', { className: 'article-seperater mb-5 mt-3' })
1360
+ props.infiniteScroll && React.createElement('hr', { className: 'article-seperater mb-5 mt-3' }),
1361
+ React.createElement(Schema, { article: props.article, Website: props.Website, client: props.client })
1282
1362
  );
1283
1363
  };
1284
1364
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mjhls/mjh-framework",
3
- "version": "1.0.840",
3
+ "version": "1.0.841",
4
4
  "description": "Foundation Framework",
5
5
  "author": "mjh-framework",
6
6
  "license": "MIT",