@quintype/seo 1.41.5-description-fallback.0 → 1.41.5-description-fallback.2

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/dist/index.cjs.js CHANGED
@@ -6,8 +6,8 @@ var lodash = require('lodash');
6
6
  var React = require('react');
7
7
  var ReactDomServer = require('react-dom/server');
8
8
  var get = require('lodash/get');
9
- var url = require('url');
10
9
  var dateFnsTz = require('date-fns-tz');
10
+ var url = require('url');
11
11
  var isUndefined = require('lodash/isUndefined');
12
12
  var omitBy = require('lodash/omitBy');
13
13
  var quintypeJs = require('quintype-js');
@@ -51,7 +51,7 @@ function isStoryPublic(story) {
51
51
 
52
52
  function getTextOfCards(story) {
53
53
  if (story && story.cards) {
54
- story.cards.map(item => {
54
+ return story.cards.map(item => {
55
55
  return item['story-elements'].reduce((acc, currentItem) => {
56
56
  const elementType = currentItem.subtype || currentItem.type || '';
57
57
  if (elementType === 'text') {
@@ -968,11 +968,13 @@ function buildTagsFromStory(config, story, url = {}, data = {}, seoConfig = {})
968
968
 
969
969
  let descriptionWithExtraFallback = "";
970
970
  let ogDescriptionWithExtraFallback = "";
971
- if (seoConfig.enableMetaDescriptionFallback) {
971
+ const enableMetaDescriptionFallback = lodash.get(seoConfig, ["enableMetaDescriptionFallback"], false);
972
+ if (enableMetaDescriptionFallback) {
973
+ const subHeadline = lodash.get(story, ["subheadline"]);
972
974
  const fetch160Characters = data => data ? data.substring(0, 160) : null;
973
975
  const fullStoryTextElementContent = getTextOfCards(story);
974
- descriptionWithExtraFallback = fetch160Characters(story.subheadline) || fetch160Characters(fullStoryTextElementContent);
975
- ogDescriptionWithExtraFallback = fetch160Characters(fullStoryTextElementContent) || fetch160Characters(story.subheadline) || seo["meta-description"];
976
+ descriptionWithExtraFallback = fetch160Characters(subHeadline) || fetch160Characters(fullStoryTextElementContent);
977
+ ogDescriptionWithExtraFallback = fetch160Characters(fullStoryTextElementContent) || fetch160Characters(subHeadline) || lodash.get(seo, ["meta-description"]);
976
978
  }
977
979
 
978
980
  const storyUrl = story.url || `${config["sketches-host"]}/${story.slug}`;
@@ -1227,7 +1229,7 @@ const SKIP_CANONICAL = "__SKIP__CANONICAL__";
1227
1229
  * @param {boolean} seoConfig.enableOgTags Add og tags for Facebook
1228
1230
  * @param {boolean} seoConfig.enableTwitterCards Add twitter tags
1229
1231
  * @param {boolean} seoConfig.enableNews Add tags for Google News, like news_keywords
1230
- * @param {boolean} seoConfig.enableMetaDescriptionsFallback Add extra fallbacks for meta description, og:description and twitter:description
1232
+ * @param {boolean} seoConfig.enableMetaDescriptionFallback Add extra fallbacks for meta description, og:description and twitter:description
1231
1233
  * @param {Object} seoConfig.customTags Add tags for a custom page type. Usually looks like `{"custom-page": {"title": "value", "canonicalUrl": "value"}}`
1232
1234
  * @param {...*} params See {@link Generator} for other Parameters
1233
1235
  */
@@ -1363,7 +1365,7 @@ class MetaTagList {
1363
1365
  * enableNewsArticle: true
1364
1366
  * },
1365
1367
  * ampStoryPages: true,
1366
- * enableMetaDescriptionsFallback: true
1368
+ * enableMetaDescriptionFallback: true
1367
1369
  * });
1368
1370
  * ```
1369
1371
  */
package/index.js CHANGED
@@ -94,7 +94,7 @@ export class MetaTagList {
94
94
  * enableNewsArticle: true
95
95
  * },
96
96
  * ampStoryPages: true,
97
- * enableMetaDescriptionsFallback: true
97
+ * enableMetaDescriptionFallback: true
98
98
  * });
99
99
  * ```
100
100
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/seo",
3
- "version": "1.41.5-description-fallback.0",
3
+ "version": "1.41.5-description-fallback.2",
4
4
  "description": "SEO Modules for Quintype",
5
5
  "main": "dist/index.cjs.js",
6
6
  "repository": "https://github.com/quintype/quintype-node-seo",
package/src/text-tags.js CHANGED
@@ -24,15 +24,16 @@ function buildTagsFromStory(config, story, url = {}, data = {}, seoConfig = {})
24
24
 
25
25
  let descriptionWithExtraFallback = "";
26
26
  let ogDescriptionWithExtraFallback = "";
27
- if (seoConfig.enableMetaDescriptionFallback) {
27
+ const enableMetaDescriptionFallback = get(seoConfig, ["enableMetaDescriptionFallback"], false);
28
+ if (enableMetaDescriptionFallback) {
29
+ const subHeadline = get(story, ["subheadline"]);
28
30
  const fetch160Characters = (data) => (data ? data.substring(0, 160) : null);
29
31
  const fullStoryTextElementContent = getTextOfCards(story);
30
- descriptionWithExtraFallback =
31
- fetch160Characters(story.subheadline) || fetch160Characters(fullStoryTextElementContent);
32
+ descriptionWithExtraFallback = fetch160Characters(subHeadline) || fetch160Characters(fullStoryTextElementContent);
32
33
  ogDescriptionWithExtraFallback =
33
34
  fetch160Characters(fullStoryTextElementContent) ||
34
- fetch160Characters(story.subheadline) ||
35
- seo["meta-description"];
35
+ fetch160Characters(subHeadline) ||
36
+ get(seo, ["meta-description"]);
36
37
  }
37
38
 
38
39
  const storyUrl = story.url || `${config["sketches-host"]}/${story.slug}`;
@@ -314,7 +315,7 @@ const SKIP_CANONICAL = "__SKIP__CANONICAL__";
314
315
  * @param {boolean} seoConfig.enableOgTags Add og tags for Facebook
315
316
  * @param {boolean} seoConfig.enableTwitterCards Add twitter tags
316
317
  * @param {boolean} seoConfig.enableNews Add tags for Google News, like news_keywords
317
- * @param {boolean} seoConfig.enableMetaDescriptionsFallback Add extra fallbacks for meta description, og:description and twitter:description
318
+ * @param {boolean} seoConfig.enableMetaDescriptionFallback Add extra fallbacks for meta description, og:description and twitter:description
318
319
  * @param {Object} seoConfig.customTags Add tags for a custom page type. Usually looks like `{"custom-page": {"title": "value", "canonicalUrl": "value"}}`
319
320
  * @param {...*} params See {@link Generator} for other Parameters
320
321
  */
package/src/utils.js CHANGED
@@ -1,6 +1,6 @@
1
- import {entries} from 'lodash';
2
- import { URL, URLSearchParams } from 'url';
3
1
  import { format, utcToZonedTime } from 'date-fns-tz';
2
+ import { entries } from 'lodash';
3
+ import { URL, URLSearchParams } from 'url';
4
4
 
5
5
  export function objectToTags(object) {
6
6
  return entries(object)
@@ -36,7 +36,7 @@ export function isStoryPublic(story) {
36
36
 
37
37
  export function getTextOfCards(story) {
38
38
  if (story && story.cards) {
39
- story.cards
39
+ return story.cards
40
40
  .map((item) => {
41
41
  return item['story-elements'].reduce((acc, currentItem) => {
42
42
  const elementType = currentItem.subtype || currentItem.type || '';