@griddo/cx 1.67.4 → 1.67.7

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.4",
4
+ "version": "1.67.7",
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.4",
67
+ "@griddo/eslint-config-back": "^1.67.7",
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": "a356dd64d48cd9d3043adc038e43e6158d8f6241"
99
+ "gitHead": "1f30909d372622d6dac5eebcce131d7d6b086fd5"
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 {
@@ -55,13 +49,18 @@ export default function SEO(props) {
55
49
  },
56
50
  } = analyticsCode;
57
51
 
52
+ // Resize favicon
53
+ // If favicon is a Griddo DAM url, returns a griddo image url with params,
54
+ // else (Cloudinary or unkonwn) returns the original favicon url.
55
+ const faviconResized = addGriddoDamParams(favicon, 'f/png/w/32/h/32');
56
+
58
57
  return (
59
58
  <>
60
59
  <Helmet title={title}>
61
60
  <meta name="description" content={description} />
62
61
  <meta name="title" content={title} />
63
62
  {canonical && <link rel="canonical" href={canonical} />}
64
- <link rel="icon" href={favicon} />
63
+ <link rel="icon" href={faviconResized} />
65
64
 
66
65
  {/* Alternate */}
67
66
  {pageLanguages?.length > 1 &&
@@ -108,9 +107,9 @@ export default function SEO(props) {
108
107
 
109
108
  {/* Data Layer */}
110
109
  {/* 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
- }
110
+ {typeof window !== 'undefined' && (
111
+ <script>{`const newDataLayer = ${analyticsDimensions};newDataLayer && window.dataLayer && window.dataLayer.push(newDataLayer);`}</script>
112
+ )}
114
113
  </Helmet>
115
114
  </>
116
115
  );
@@ -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;