@griddo/cx 1.67.5 → 1.67.8

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.5",
4
+ "version": "1.67.8",
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.5",
67
+ "@griddo/eslint-config-back": "^1.67.8",
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": "3acb4a0eba1d07138ac7cef7a1eb7dc3ca55e948"
99
+ "gitHead": "c8f6997813536836cf6a0532662a65d73a3d6152"
100
100
  }
@@ -39,16 +39,29 @@ try {
39
39
  if (fs.existsSync(cxDirSource)) {
40
40
  // TODO: Use proper tools instead of execSync to delete and move files
41
41
  try {
42
- execSync(`mkdir -p ${cxDirDest}`);
43
- execSync(`cp -r ${cxDirSource}/* ${cxDirDest}/`, {
42
+ if (fs.existsSync(cxDirDest)) {
43
+ console.log(chalk.blue("Creando backup de " + cxDirDest + "..."));
44
+ execSync(`mv ${cxDirDest} ${cxDirDest}-BACKUP`);
45
+ }
46
+ //execSync(`mkdir -p ${cxDirDest}`);
47
+ console.log(chalk.blue("Moviendo ficheros de " + cxDirSource + " a " + cxDirDest + "..."));
48
+ execSync(`mv ${cxDirSource} ${cxDirDest}`, {
44
49
  cwd: workingDirPath,
45
50
  });
51
+ console.log(chalk.blue("Eliminando backup de " + cxDirDest + "..."));
52
+ execSync(`rm -rf ${cxDirDest}-BACKUP`);
46
53
  } catch {
47
54
  console.log(
48
55
  chalk.red(` Error moving files to ${cxDirDest}`),
49
56
  componentDir,
50
57
  error.message
51
58
  );
59
+ if (fs.existsSync(cxDirDest + "-BACKUP")) {
60
+ console.log(chalk.blue("Restaurando " + cxDirDest + "..."));
61
+ execSync(`mv ${cxDirDest}-BACKUP ${cxDirDest}`, {
62
+ cwd: workingDirPath,
63
+ });
64
+ }
52
65
  continue;
53
66
  }
54
67
  } else {
@@ -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,9 @@ export default function SEO(props) {
36
30
  const showMetaRobots =
37
31
  showBasicMetaRobots || metaRobots !== 'index,follow,translate';
38
32
 
33
+
34
+ const emptyCodeScript = { props: { dangerouslySetInnerHTML: {} } };
35
+
39
36
  const analyticsSrc =
40
37
  (analyticsScript &&
41
38
  analyticsScript.startsWith('UA-') &&
@@ -44,7 +41,9 @@ export default function SEO(props) {
44
41
  const analyticsCode =
45
42
  analyticsScript && !analyticsSrc && analyticsScript.includes('<script')
46
43
  ? parse(analyticsScript)
47
- : { props: { dangerouslySetInnerHTML: {} } };
44
+ : emptyCodeScript;
45
+
46
+ const fixedAnalyticsCode = Array.isArray(analyticsCode) ? analyticsCode.find(item => item.type === 'script') || emptyCodeScript : analyticsCode;
48
47
 
49
48
  const {
50
49
  props: {
@@ -53,7 +52,12 @@ export default function SEO(props) {
53
52
  children: analyticsScriptChildren,
54
53
  ...analyticsScriptProps
55
54
  },
56
- } = analyticsCode;
55
+ } = fixedAnalyticsCode;
56
+
57
+ // Resize favicon
58
+ // If favicon is a Griddo DAM url, returns a griddo image url with params,
59
+ // else (Cloudinary or unkonwn) returns the original favicon url.
60
+ const faviconResized = addGriddoDamParams(favicon, 'f/png/w/32/h/32');
57
61
 
58
62
  return (
59
63
  <>
@@ -61,7 +65,7 @@ export default function SEO(props) {
61
65
  <meta name="description" content={description} />
62
66
  <meta name="title" content={title} />
63
67
  {canonical && <link rel="canonical" href={canonical} />}
64
- <link rel="icon" href={favicon} />
68
+ <link rel="icon" href={faviconResized} />
65
69
 
66
70
  {/* Alternate */}
67
71
  {pageLanguages?.length > 1 &&
@@ -108,9 +112,9 @@ export default function SEO(props) {
108
112
 
109
113
  {/* Data Layer */}
110
114
  {/* 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
- }
115
+ {typeof window !== 'undefined' && (
116
+ <script>{`const newDataLayer = ${analyticsDimensions};newDataLayer && window.dataLayer && window.dataLayer.push(newDataLayer);`}</script>
117
+ )}
114
118
  </Helmet>
115
119
  </>
116
120
  );
@@ -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,12 @@ 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
+ if (analyticsDimensions) delete analyticsDimensions.__HIDDEN;
47
48
  if (!content.dimensions) content.dimensions = [];
48
49
  content.dimensions.values = analyticsDimensions;
49
50
 
@@ -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;