@griddo/cx 1.75.32 → 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/gatsby-node.js CHANGED
@@ -29,7 +29,10 @@ const BUILD_MODE = process.env.CXBRANCH;
29
29
  let updatedSites;
30
30
  let createdPages = [];
31
31
  let buildProcessData = {};
32
- const componentsVersion = getComponentsVersion();
32
+ const {
33
+ componentsVersion,
34
+ griddoVersion,
35
+ } = getComponentsVersion();
33
36
 
34
37
  const renderId = process.env.RENDERID || new Date().valueOf();
35
38
 
@@ -130,6 +133,7 @@ exports.createPages = async ({ actions }) => {
130
133
  showBasicMetaRobots,
131
134
  avoidHrefLangsOnCanonicals,
132
135
  avoidSelfReferenceCanonicals,
136
+ avoidDebugMetas,
133
137
  } = SettingsService.settings;
134
138
 
135
139
  NavService.navigations = {
@@ -163,11 +167,13 @@ exports.createPages = async ({ actions }) => {
163
167
  siteLangs,
164
168
  cloudinaryName,
165
169
  componentsVersion,
170
+ griddoVersion,
166
171
  siteOptions: {
167
172
  useMetaTitle,
168
173
  showBasicMetaRobots,
169
174
  avoidHrefLangsOnCanonicals,
170
175
  avoidSelfReferenceCanonicals,
176
+ avoidDebugMetas,
171
177
  },
172
178
  BUILD_MODE,
173
179
  siteScript,
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.32",
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.32",
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": "3f977c15e10a3b3ece4d60280083f01ad5460ad4"
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.
@@ -32,6 +32,8 @@ export const Head = ({ pageContext }) => {
32
32
  openGraph,
33
33
  analyticsDimensions,
34
34
  analyticsScript,
35
+ componentsVersion,
36
+ griddoVersion,
35
37
  page: {
36
38
  fullUrl,
37
39
  },
@@ -70,11 +72,11 @@ export const Head = ({ pageContext }) => {
70
72
  } = fixedAnalyticsCode;
71
73
 
72
74
  // Resize favicon
73
- // If favicon is a Griddo DAM url, returns a griddo image url with params,
74
- // else (Cloudinary or unkonwn) returns the original favicon url.
75
- const faviconResized = addGriddoDamParams(
75
+ const faviconResized = formatImage(
76
76
  siteMetadata?.favicon,
77
- 'f/png/w/32/h/32'
77
+ 32,
78
+ 32,
79
+ 'png'
78
80
  );
79
81
 
80
82
  // Validate options
@@ -86,7 +88,7 @@ export const Head = ({ pageContext }) => {
86
88
  siteOptions?.avoidSelfReferenceCanonicals &&
87
89
  pageMetadata?.canonical === fullUrl
88
90
  );
89
-
91
+
90
92
  const useHrefLangs =
91
93
  !(
92
94
  siteOptions?.avoidHrefLangsOnCanonicals &&
@@ -133,7 +135,7 @@ export const Head = ({ pageContext }) => {
133
135
  content={openGraph?.title || pageMetadata?.title}
134
136
  />}
135
137
  <meta property="og:type" content={openGraph?.type || 'website'} />
136
- {!!openGraph?.description && <meta property="og:description" content={openGraph?.description} />}
138
+ {(!!openGraph?.description || !!pageMetadata?.description) && <meta property="og:description" content={openGraph?.description || pageMetadata?.description} />}
137
139
  {!!openGraph?.image && <meta property="og:image" content={openGraph?.image} />}
138
140
  <meta property="og:url" content={pageMetadata?.canonical || fullUrl} />
139
141
 
@@ -143,12 +145,13 @@ export const Head = ({ pageContext }) => {
143
145
  property="twitter:title"
144
146
  content={openGraph?.title || pageMetadata?.title}
145
147
  />}
146
- {!!openGraph?.description && <meta property="twitter:description" content={openGraph?.description} />}
148
+ {(!!openGraph?.description || pageMetadata?.description) && <meta property="twitter:description" content={openGraph?.description || pageMetadata?.description} />}
147
149
  {(!!openGraph?.twitterImage || !!openGraph?.image) && <meta property="twitter:image" content={openGraph?.twitterImage || openGraph?.image} />}
148
150
  <meta
149
151
  property="twitter:url"
150
152
  content={pageMetadata?.canonical || fullUrl}
151
153
  />
154
+ {!siteOptions?.avoidDebugMetas && <meta property="debug" content={`Components v${componentsVersion} by Griddo v${griddoVersion} @ ${new Date()}`} />}
152
155
 
153
156
  {/* Data Layer */}
154
157
  {/* Solo cuando se ejecuta en el navegador */}
@@ -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;
@@ -1,12 +1,18 @@
1
- const package = require('../../package.json');
1
+ const packageInfo = require('../../package.json');
2
2
 
3
3
  const getComponentsVersion = () => {
4
4
  const {
5
- dependencies
6
- } = package;
5
+ dependencies,
6
+ version,
7
+ } = packageInfo;
8
+
7
9
  const componentsKey = dependencies.components ? 'components' : Object.keys(dependencies).find(key => key.endsWith('/components'));
8
- const version = componentsKey ? dependencies[componentsKey] : '0.0.0';
9
- return version.split('^').join('').split('@').slice(-1)[0];
10
+ const componentsVersion = componentsKey ? dependencies[componentsKey] : '0.0.0';
11
+
12
+ return {
13
+ componentsVersion: componentsVersion.split('^').join('').split('@').slice(-1)[0],
14
+ griddoVersion: version,
15
+ };
10
16
  };
11
17
 
12
18
  module.exports = {
@@ -25,6 +25,7 @@ async function renderSinglePage(page, additionalInfo, createPage) {
25
25
  cloudinaryName,
26
26
  siteOptions,
27
27
  componentsVersion,
28
+ griddoVersion,
28
29
  BUILD_MODE,
29
30
  sitePages,
30
31
  siteScript,
@@ -75,6 +76,7 @@ async function renderSinglePage(page, additionalInfo, createPage) {
75
76
  siteOptions,
76
77
  BUILD_MODE,
77
78
  componentsVersion,
79
+ griddoVersion,
78
80
  sitePages,
79
81
  siteScript,
80
82