@griddo/cx 1.75.33 → 1.75.34

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.75.33",
4
+ "version": "1.75.34",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Carlos Torres <carlos.torres@secuoyas.com>",
@@ -65,7 +65,7 @@
65
65
  "react-helmet": "^6.0.0"
66
66
  },
67
67
  "devDependencies": {
68
- "@griddo/eslint-config-back": "^1.75.33",
68
+ "@griddo/eslint-config-back": "^1.75.34",
69
69
  "eslint": "^7.5.0",
70
70
  "eslint-plugin-node": "^11.1.0",
71
71
  "eslint-plugin-react": "7.14.3",
@@ -97,5 +97,5 @@
97
97
  "publishConfig": {
98
98
  "access": "public"
99
99
  },
100
- "gitHead": "8fd3e9c38978faee9d3860c4f2613423bc59e117"
100
+ "gitHead": "cadffc9497096901e309b5b897f168759e09df92"
101
101
  }
@@ -11,7 +11,7 @@ import parse from 'html-react-parser';
11
11
  import * as React from 'react';
12
12
  import { Helmet } from 'react-helmet';
13
13
  import { composeAnalytics } from '../utils/dataLayer';
14
- import { addGriddoDamParams, cleanCommaSeparated } from '../utils/helpers';
14
+ import { formatImage, cleanCommaSeparated } from '../utils/helpers';
15
15
 
16
16
  //
17
17
  // Gatsby Head API, almost deprecate Helmet.
@@ -72,11 +72,11 @@ export const Head = ({ pageContext }) => {
72
72
  } = fixedAnalyticsCode;
73
73
 
74
74
  // Resize favicon
75
- // If favicon is a Griddo DAM url, returns a griddo image url with params,
76
- // else (Cloudinary or unkonwn) returns the original favicon url.
77
- const faviconResized = addGriddoDamParams(
75
+ const faviconResized = formatImage(
78
76
  siteMetadata?.favicon,
79
- 'f/png/w/32/h/32'
77
+ 32,
78
+ 32,
79
+ 'png'
80
80
  );
81
81
 
82
82
  // Validate options
@@ -24,9 +24,23 @@ const log = (state, message, data) => {
24
24
  );
25
25
  };
26
26
 
27
+ // Format image
28
+ const formatImage = (image, width, height, format = 'jpg') => {
29
+ const url = image?.url || image;
30
+ if (!url) return null;
31
+ return url.split('/')[2].includes('cloudinary.com')
32
+ ? addCloudinaryParams(url, `c_fill,w_${width},h_${height}`)
33
+ : addGriddoDamParams(url, `f/${format}/c/fill/w/${width}/h/${height}`);
34
+ };
35
+
36
+ // Format Griddo DAM image
37
+ const addGriddoDamParams = (image, params) => {
38
+ const splittedUrl = image.split('/');
39
+ return `${splittedUrl.slice(0,-1).join('/')}/${params}/${splittedUrl.slice(-1)[0]}`;
40
+ };
41
+
27
42
  // Take a cloudinary url and add query params
28
43
  const addCloudinaryParams = (socialImage, params) => {
29
- if (!socialImage) return null;
30
44
  const plainUrl = socialImage.url.replace('https://', '');
31
45
  const head = plainUrl.split('/').slice(0, 4).join('/');
32
46
  const fullId = plainUrl.replace(head, '');
@@ -82,8 +96,8 @@ const getOpenGraph = ({
82
96
  type: 'website',
83
97
  title: socialTitle || title,
84
98
  description: socialDescription,
85
- image: addCloudinaryParams(socialImage, 'c_fill,w_1024,h_512'),
86
- twitterImage: addCloudinaryParams(socialImage, 'c_fill,w_1024,h_512'),
99
+ image: formatImage(socialImage, 1280,768),
100
+ twitterImage: formatImage(socialImage, 1280, 768),
87
101
  });
88
102
 
89
103
  const getMultiPageElements = distributorTemplate =>
@@ -117,20 +131,9 @@ const cleanCommaSeparated = x =>
117
131
  .filter(item => !!item)
118
132
  .join(',');
119
133
 
120
- const isGriddoDamImage = url => !url?.includes('/res.cloudinary.com');
121
-
122
- const addGriddoDamParams = (url, params) => {
123
- if (!url) return url;
124
- if (!isGriddoDamImage(url)) return url;
125
- // eslint-disable-next-line no-unused-vars
126
- const [_, id] = url.split('//')[1].split('/');
127
- const head = url.split(id)[0];
128
- return `${head}${params}/${id}`;
129
- };
130
-
131
134
  exports.getOpenGraph = getOpenGraph;
132
135
  exports.getPageMetaData = getPageMetaData;
133
136
  exports.log = log;
134
137
  exports.getMultiPageElements = getMultiPageElements;
135
138
  exports.cleanCommaSeparated = cleanCommaSeparated;
136
- exports.addGriddoDamParams = addGriddoDamParams;
139
+ exports.formatImage = formatImage;