@griddo/cx 1.56.10 → 1.57.0

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
@@ -22,8 +22,6 @@ const baseUrl = process.env.API_URL;
22
22
  const publicBaseUrl = process.env.PUBLIC_API_URL;
23
23
  const IS_SERVE = !!process.env.IS_SERVE && JSON.parse(process.env.IS_SERVE);
24
24
  const BUILD_MODE = process.env.CXBRANCH;
25
- const isIE = process.env.CLIENT === 'IEEDU';
26
- const isGARRIGUES = process.env.CLIENT && process.env.CLIENT.startsWith('CEG');
27
25
 
28
26
  // Share info between actions (createPages and onPostBuild)
29
27
  let updatedSites;
@@ -125,8 +123,6 @@ exports.createPages = async ({ actions }) => {
125
123
  componentsVersion,
126
124
  showBasicMetaRobots,
127
125
  BUILD_MODE,
128
- isIE,
129
- isGARRIGUES,
130
126
  sitePages,
131
127
  };
132
128
 
@@ -153,29 +149,34 @@ exports.createPages = async ({ actions }) => {
153
149
 
154
150
  const isList = distributorTemplate?.type?.mode?.toLowerCase() === 'list';
155
151
 
152
+ const multiPageElements = await helpers.getMultiPageElements(
153
+ distributorTemplate
154
+ );
155
+
156
156
  // Multi-page (pagination) or single-page
157
157
  isList
158
- ? await utils.renderMultiplePages(
159
- {
160
- rootPage: page,
161
- pages: utils.getList(distributorTemplate),
162
- isRoot: false,
163
- defaultLang,
164
- distributorTemplate,
165
- },
166
- additionalInfo,
167
- actions.createPage
168
- )
169
- : await utils.renderSinglePage(
170
- {
171
- ...page,
172
- template: distributorTemplate,
173
- isRoot: false,
174
- defaultLang,
175
- },
176
- additionalInfo,
177
- actions.createPage
178
- );
158
+ ? await utils.renderListPages(
159
+ {
160
+ rootPage: page,
161
+ pages: utils.getList(distributorTemplate),
162
+ isRoot: false,
163
+ defaultLang,
164
+ distributorTemplate,
165
+ },
166
+ additionalInfo,
167
+ actions.createPage
168
+ )
169
+ : await utils.renderPage(
170
+ {
171
+ ...page,
172
+ template: distributorTemplate,
173
+ isRoot: false,
174
+ defaultLang,
175
+ multiPageElements,
176
+ },
177
+ additionalInfo,
178
+ actions.createPage
179
+ );
179
180
 
180
181
  buildProcessData[siteID].publishHashes.push(page.hash);
181
182
  }
package/gatsby-ssr.js CHANGED
@@ -21,7 +21,7 @@ export const onRenderBody = ({
21
21
  htmlAttributes,
22
22
  bodyAttributes,
23
23
  bodyProps,
24
- } = onRenderBodyFromClient;
24
+ } = onRenderBodyFromClient || {};
25
25
 
26
26
  setHeadComponents(headComponents);
27
27
  setPreBodyComponents(preBodyComponents);
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.56.10",
4
+ "version": "1.57.0",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Carlos Torres <carlos.torres@secuoyas.com>",
@@ -61,7 +61,7 @@
61
61
  "react-helmet": "^6.0.0"
62
62
  },
63
63
  "devDependencies": {
64
- "@griddo/eslint-config-back": "^1.56.10",
64
+ "@griddo/eslint-config-back": "^1.57.0",
65
65
  "eslint": "^7.5.0",
66
66
  "eslint-plugin-node": "^11.1.0",
67
67
  "eslint-plugin-react": "7.14.3",
@@ -93,5 +93,5 @@
93
93
  "publishConfig": {
94
94
  "access": "public"
95
95
  },
96
- "gitHead": "586a090d1cb535fa0577fd12d2e874860c1fc3b8"
96
+ "gitHead": "fe9a8f9481f35021584d79706fd7020c8c87b685"
97
97
  }
@@ -69,6 +69,28 @@ const getOpenGraph = ({
69
69
  twitterImage: addCloudinaryParams(socialImage, 'c_fill,w_1024,h_512')
70
70
  });
71
71
 
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
+ const {
79
+ component,
80
+ hasGriddoMultiPage,
81
+ elements,
82
+ } = currentComponent;
83
+ if (component && hasGriddoMultiPage) {
84
+ resolve(elements || []);
85
+ }
86
+ getMultiPageComponent(currentComponent, level + 1);
87
+ }
88
+ if (!level) resolve(null);
89
+ };
90
+ getMultiPageComponent([distributorTemplate]);
91
+ });
92
+
72
93
  exports.getOpenGraph = getOpenGraph;
73
94
  exports.getPageMetaData = getPageMetaData;
74
95
  exports.log = log;
96
+ exports.getMultiPageElements = getMultiPageElements;
@@ -12,8 +12,8 @@ const getPageCluster = (itemsPerPage, items) => {
12
12
  .fill(0)
13
13
  .map((x, idx) => idx + 1)
14
14
 
15
-
16
- const result = pageNumbers.map(x => getPage(itemsPerPage, items, x))
15
+
16
+ const result = pageNumbers.map(x => getPage(itemsPerPage, items, x))
17
17
  return result;
18
18
  }
19
19
 
@@ -33,6 +33,6 @@ const getList = distributorTemplate => {
33
33
  exports.default = {
34
34
  getPagePath,
35
35
  getList,
36
- renderSinglePage: pageUtils.renderSinglePage,
37
- renderMultiplePages: pageUtils.renderMultiplePages
36
+ renderPage: pageUtils.renderPage,
37
+ renderListPages: pageUtils.renderListPages,
38
38
  }
@@ -1,9 +1,15 @@
1
1
  const path = require('path');
2
2
  const helpers = require('./helpers.js');
3
3
 
4
+ async function renderPage(page, additionalInfo, createPage) {
5
+ const { multiPageElements, ...cleanPage } = page;
6
+ if (!multiPageElements)
7
+ return await renderSinglePage(cleanPage, additionalInfo, createPage);
8
+ await renderMultiplePages(page, additionalInfo, createPage);
9
+ }
10
+
4
11
  async function renderSinglePage(page, additionalInfo, createPage) {
5
12
  const { id, name, title, fullPath, language: languageId, breadcrumb } = page;
6
-
7
13
  helpers.log('info', `renderSinglePage: ${id}`);
8
14
 
9
15
  const {
@@ -86,7 +92,7 @@ async function renderSinglePage(page, additionalInfo, createPage) {
86
92
  return createPage(mappedPage);
87
93
  }
88
94
 
89
- async function renderMultiplePages(
95
+ async function renderListPages(
90
96
  { rootPage, pages, isRoot, defaultLang, distributorTemplate },
91
97
  additionalInfo,
92
98
  createPage
@@ -121,5 +127,39 @@ async function renderMultiplePages(
121
127
  });
122
128
  }
123
129
 
124
- exports.renderSinglePage = renderSinglePage;
125
- exports.renderMultiplePages = renderMultiplePages;
130
+ async function renderMultiplePages(page, additionalInfo, createPage) {
131
+ const { multiPageElements, ...cleanPage } = page;
132
+
133
+ // si no hay un elemento sin slug, como mínimo hay que dibujar una página principal para el conjunto de páginas
134
+ if (!multiPageElements.find(({ sectionSlug }) => sectionSlug === '/')) multiPageElements.push({});
135
+
136
+ // crear cada página
137
+ for (const pageElement of multiPageElements) {
138
+ const paginatedPage = JSON.parse(JSON.stringify(cleanPage));
139
+ const {
140
+ sectionSlug = '/',
141
+ title = '',
142
+ metaTitle = '',
143
+ metaDescription = '',
144
+ } = pageElement;
145
+ const compose = paginatedPage?.fullPath?.compose || '';
146
+ const fullUrl = paginatedPage.fullUrl;
147
+ const rightSectionSlug = sectionSlug?.replace(/\//g, '');
148
+ const newCompose = `${compose}${
149
+ compose.endsWith('/') ? '' : '/'
150
+ }${rightSectionSlug}`;
151
+ paginatedPage.fullUrl = `${fullUrl}${
152
+ fullUrl.endsWith('/') ? '' : '/'
153
+ }${rightSectionSlug}`;
154
+ paginatedPage.fullPath.compose = newCompose;
155
+ paginatedPage.slug = newCompose;
156
+ paginatedPage.template.activeSectionSlug = sectionSlug;
157
+ if (title.trim()) paginatedPage.title = title;
158
+ if (metaTitle.trim()) paginatedPage.metaTitle = metaTitle;
159
+ if (metaDescription.trim()) paginatedPage.metaDescription = metaDescription;
160
+ await renderSinglePage(paginatedPage, additionalInfo, createPage);
161
+ }
162
+ }
163
+
164
+ exports.renderPage = renderPage;
165
+ exports.renderListPages = renderListPages;