@griddo/cx 1.67.6 → 1.67.9

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/cx",
3
3
  "description": "Griddo SSG based on Gatsby",
4
- "version": "1.67.6",
4
+ "version": "1.67.9",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Carlos Torres <carlos.torres@secuoyas.com>",
@@ -64,7 +64,7 @@
64
64
  "react-helmet": "^6.0.0"
65
65
  },
66
66
  "devDependencies": {
67
- "@griddo/eslint-config-back": "^1.67.6",
67
+ "@griddo/eslint-config-back": "^1.67.9",
68
68
  "eslint": "^7.5.0",
69
69
  "eslint-plugin-node": "^11.1.0",
70
70
  "eslint-plugin-react": "7.14.3",
@@ -96,5 +96,5 @@
96
96
  "publishConfig": {
97
97
  "access": "public"
98
98
  },
99
- "gitHead": "2269a483e2cf3876f692331469b2402af3bb0e48"
99
+ "gitHead": "5532ae88c11fc5cc89e7bd78f56269e8ca9c710b"
100
100
  }
@@ -1,13 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { Helmet } from 'react-helmet';
3
3
  import parse from 'html-react-parser';
4
-
5
- const cleanCommaSeparated = x =>
6
- x
7
- .split(',')
8
- .map(item => item.trim())
9
- .filter(item => !!item)
10
- .join(',');
4
+ import { addGriddoDamParams, cleanCommaSeparated } from '../utils/helpers';
11
5
 
12
6
  export default function SEO(props) {
13
7
  const {
@@ -36,6 +30,8 @@ export default function SEO(props) {
36
30
  const showMetaRobots =
37
31
  showBasicMetaRobots || metaRobots !== 'index,follow,translate';
38
32
 
33
+ const emptyCodeScript = { props: { dangerouslySetInnerHTML: {} } };
34
+
39
35
  const analyticsSrc =
40
36
  (analyticsScript &&
41
37
  analyticsScript.startsWith('UA-') &&
@@ -44,7 +40,9 @@ export default function SEO(props) {
44
40
  const analyticsCode =
45
41
  analyticsScript && !analyticsSrc && analyticsScript.includes('<script')
46
42
  ? parse(analyticsScript)
47
- : { props: { dangerouslySetInnerHTML: {} } };
43
+ : emptyCodeScript;
44
+
45
+ const fixedAnalyticsCode = Array.isArray(analyticsCode) ? analyticsCode.find(item => item.type === 'script') || emptyCodeScript : analyticsCode;
48
46
 
49
47
  const {
50
48
  props: {
@@ -53,7 +51,12 @@ export default function SEO(props) {
53
51
  children: analyticsScriptChildren,
54
52
  ...analyticsScriptProps
55
53
  },
56
- } = analyticsCode;
54
+ } = fixedAnalyticsCode;
55
+
56
+ // Resize favicon
57
+ // If favicon is a Griddo DAM url, returns a griddo image url with params,
58
+ // else (Cloudinary or unkonwn) returns the original favicon url.
59
+ const faviconResized = addGriddoDamParams(favicon, 'f/png/w/32/h/32');
57
60
 
58
61
  return (
59
62
  <>
@@ -61,7 +64,7 @@ export default function SEO(props) {
61
64
  <meta name="description" content={description} />
62
65
  <meta name="title" content={title} />
63
66
  {canonical && <link rel="canonical" href={canonical} />}
64
- <link rel="icon" href={favicon} />
67
+ <link rel="icon" href={faviconResized} />
65
68
 
66
69
  {/* Alternate */}
67
70
  {pageLanguages?.length > 1 &&
@@ -108,9 +111,9 @@ export default function SEO(props) {
108
111
 
109
112
  {/* Data Layer */}
110
113
  {/* Solo cuando se ejecuta en el navegador */}
111
- {
112
- typeof (window) !== 'undefined' && <script>{`const newDataLayer = ${analyticsDimensions};newDataLayer && window.dataLayer && window.dataLayer.push(newDataLayer);`}</script>
113
- }
114
+ {typeof window !== 'undefined' && analyticsDimensions && (
115
+ <script>{`const {__HIDDEN, ...newDataLayer} = ${analyticsDimensions};newDataLayer && window.dataLayer && window.dataLayer.push(newDataLayer);`}</script>
116
+ )}
114
117
  </Helmet>
115
118
  </>
116
119
  );
@@ -32,11 +32,6 @@ export default data => {
32
32
  sitePages,
33
33
  } = data.pageContext;
34
34
 
35
- const { analyticsScript, analyticsDimensions } = composeAnalytics(
36
- data,
37
- generateAutomaticDimensions
38
- );
39
-
40
35
  const library = {
41
36
  components,
42
37
  templates,
@@ -44,6 +39,11 @@ export default data => {
44
39
 
45
40
  const mappedTheme = theme || 'default-theme';
46
41
 
42
+ const { analyticsScript, analyticsDimensions } = composeAnalytics(
43
+ data,
44
+ generateAutomaticDimensions
45
+ );
46
+
47
47
  if (!content.dimensions) content.dimensions = [];
48
48
  content.dimensions.values = analyticsDimensions;
49
49
 
@@ -15,13 +15,13 @@ class NavigationService {
15
15
  get navigations() {
16
16
  return this._navigations
17
17
  }
18
-
18
+
19
19
  getDefaultFooters() {
20
20
  const safeFooters = [...this.navigations.footers];
21
21
  const defaultFooters = safeFooters.filter(footer => !!footer.setAsDefault);
22
22
  const defaultFootersByLang = defaultFooters.reduce((prev, footer) => {
23
23
  const { language } = footer;
24
- return {...prev, [language]: footer };
24
+ return { ...prev, [language]: footer };
25
25
  }, {});
26
26
  return defaultFootersByLang;
27
27
  }
@@ -31,7 +31,7 @@ class NavigationService {
31
31
  const defaultHeaders = safeHeaders.filter(header => !!header.setAsDefault);
32
32
  const defaultHeadersByLang = defaultHeaders.reduce((prev, header) => {
33
33
  const { language } = header;
34
- return {...prev, [language]: header };
34
+ return { ...prev, [language]: header };
35
35
  }, {});
36
36
  return defaultHeadersByLang;
37
37
  }
@@ -48,10 +48,10 @@ class NavigationService {
48
48
  return pageFooter;
49
49
  }
50
50
 
51
- getPageNavigations (page) {
52
- const { header: headerID, footer: footerID, language } = page;
53
- const header = !!headerID ? this.getPageHeader(headerID): this._defaultHeaders[language];
54
- const footer = !!footerID ? this.getPageFooter(footerID): this._defaultFooters[language];
51
+ getPageNavigations(page) {
52
+ const { header: headerID, footer: footerID, language } = page;
53
+ const header = headerID ? this.getPageHeader(headerID) : (headerID === 0 ? null : this._defaultHeaders[language]);
54
+ const footer = footerID ? this.getPageFooter(footerID) : (footerID === 0 ? null : this._defaultFooters[language]);
55
55
 
56
56
  return {
57
57
  header,
@@ -9,11 +9,9 @@ const log = (state, message, data) => {
9
9
  LOGS !== false &&
10
10
  state !== 'error' &&
11
11
  console.log(
12
- `${chalk[color[state]](msg[state])} ${message} ${data ? JSON.stringify(
13
- data,
14
- null,
15
- 2
16
- ) : ''}`
12
+ `${chalk[color[state]](msg[state])} ${message} ${
13
+ data ? JSON.stringify(data, null, 2) : ''
14
+ }`
17
15
  );
18
16
  };
19
17
 
@@ -23,10 +21,10 @@ const addCloudinaryParams = (socialImage, params) => {
23
21
  const plainUrl = socialImage.url.replace('https://', '');
24
22
  const head = plainUrl.split('/').slice(0, 4).join('/');
25
23
  const fullId = plainUrl.replace(head, '');
26
- return `https://${head}/${params}${fullId}`;;
24
+ return `https://${head}/${params}${fullId}`;
27
25
  };
28
26
 
29
- const getPageMetaData = (params) => {
27
+ const getPageMetaData = params => {
30
28
  const {
31
29
  title,
32
30
  metaTitle,
@@ -39,13 +37,18 @@ const getPageMetaData = (params) => {
39
37
  metasAdvanced,
40
38
  pageLanguages,
41
39
  fullUrl,
42
- noTranslate
40
+ noTranslate,
43
41
  } = params;
44
42
 
45
43
  return {
46
44
  title: metaTitle || title,
47
45
  description: metaDescription,
48
- canonical: (canonicalURL && canonicalURL !== fullUrl) ? canonicalURL : (isIndexed ? fullUrl : null),
46
+ canonical:
47
+ canonicalURL && canonicalURL !== fullUrl
48
+ ? canonicalURL
49
+ : isIndexed
50
+ ? fullUrl
51
+ : null,
49
52
  locale,
50
53
  url,
51
54
  index: isIndexed ? 'index' : 'noindex',
@@ -66,32 +69,54 @@ const getOpenGraph = ({
66
69
  title: socialTitle || title,
67
70
  description: socialDescription,
68
71
  image: addCloudinaryParams(socialImage, 'c_fill,w_1024,h_512'),
69
- twitterImage: addCloudinaryParams(socialImage, 'c_fill,w_1024,h_512')
72
+ twitterImage: addCloudinaryParams(socialImage, 'c_fill,w_1024,h_512'),
70
73
  });
71
74
 
72
- const getMultiPageElements = (distributorTemplate) => new Promise((resolve) => {
73
- const getMultiPageComponent = (template, level = 0) => {
74
- if (!template || typeof (template) !== 'object') return;
75
- for (let key in template) {
76
- const currentComponent = template[key];
77
- if (!currentComponent || typeof (currentComponent) !== 'object') continue;
78
- if (!JSON.stringify(currentComponent).includes('"hasGriddoMultiPage":true')) continue;
79
- const {
80
- component,
81
- hasGriddoMultiPage,
82
- elements,
83
- } = currentComponent;
84
- if (component && hasGriddoMultiPage) {
85
- resolve(elements || []);
75
+ const getMultiPageElements = distributorTemplate =>
76
+ new Promise(resolve => {
77
+ const getMultiPageComponent = (template, level = 0) => {
78
+ if (!template || typeof template !== 'object') return;
79
+ for (let key in template) {
80
+ const currentComponent = template[key];
81
+ if (!currentComponent || typeof currentComponent !== 'object') continue;
82
+ if (
83
+ !JSON.stringify(currentComponent).includes(
84
+ '"hasGriddoMultiPage":true'
85
+ )
86
+ )
87
+ continue;
88
+ const { component, hasGriddoMultiPage, elements } = currentComponent;
89
+ if (component && hasGriddoMultiPage) {
90
+ resolve(elements || []);
91
+ }
92
+ getMultiPageComponent(currentComponent, level + 1);
86
93
  }
87
- getMultiPageComponent(currentComponent, level + 1);
88
- }
89
- if (!level) resolve(null);
90
- };
91
- getMultiPageComponent([distributorTemplate]);
92
- });
94
+ if (!level) resolve(null);
95
+ };
96
+ getMultiPageComponent([distributorTemplate]);
97
+ });
98
+
99
+ const cleanCommaSeparated = x =>
100
+ x
101
+ .split(',')
102
+ .map(item => item.trim())
103
+ .filter(item => !!item)
104
+ .join(',');
105
+
106
+ const isGriddoDamImage = url => !url?.includes('/res.cloudinary.com');
107
+
108
+ const addGriddoDamParams = (url, params) => {
109
+ if (!url) return url;
110
+ if (!isGriddoDamImage(url)) return url;
111
+ // eslint-disable-next-line no-unused-vars
112
+ const [_, id] = url.split('//')[1].split('/');
113
+ const head = url.split(id)[0];
114
+ return `${head}${params}/${id}`;
115
+ };
93
116
 
94
117
  exports.getOpenGraph = getOpenGraph;
95
118
  exports.getPageMetaData = getPageMetaData;
96
119
  exports.log = log;
97
- exports.getMultiPageElements = getMultiPageElements;
120
+ exports.getMultiPageElements = getMultiPageElements;
121
+ exports.cleanCommaSeparated = cleanCommaSeparated;
122
+ exports.addGriddoDamParams = addGriddoDamParams;