@griddo/cx 1.66.5 → 1.66.6

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.66.5",
4
+ "version": "1.66.6",
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.66.5",
67
+ "@griddo/eslint-config-back": "^1.66.6",
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": "8a742124beca9714eddf49d01fce20ebb4bed4aa"
99
+ "gitHead": "b651d639816bb26483bc43210df5780fddf27f48"
100
100
  }
@@ -1,4 +1,6 @@
1
1
  const path = require('path');
2
+ const fs = require('fs-extra');
3
+ const { postSearchInfo } = require('./searches');
2
4
  const helpers = require('./helpers.js');
3
5
 
4
6
  async function renderPage(page, additionalInfo, createPage) {
@@ -25,7 +27,7 @@ async function renderSinglePage(page, additionalInfo, createPage) {
25
27
  showBasicMetaRobots,
26
28
  BUILD_MODE,
27
29
  sitePages,
28
- siteScript
30
+ siteScript,
29
31
  } = additionalInfo;
30
32
 
31
33
  // 3 - Build final page object
@@ -91,7 +93,30 @@ async function renderSinglePage(page, additionalInfo, createPage) {
91
93
 
92
94
  if (assetPrefix) mappedPage.matchPath = fullPath.compose;
93
95
 
94
- return createPage(mappedPage);
96
+ const exportFile = path.resolve(
97
+ __dirname,
98
+ '../../dist/',
99
+ `./${filepath}index.html`
100
+ );
101
+
102
+ createPage(mappedPage);
103
+
104
+ const content = fs.existsSync(exportFile)
105
+ ? fs.readFileSync(exportFile).toString()
106
+ : '';
107
+
108
+ await postSearchInfo({
109
+ title,
110
+ description: openGraph.description,
111
+ image: openGraph.image,
112
+ pageId: id,
113
+ languageId,
114
+ siteId: page.site,
115
+ url: page.fullUrl,
116
+ content,
117
+ });
118
+
119
+ return content;
95
120
  }
96
121
 
97
122
  async function renderListPages(
@@ -152,15 +177,17 @@ async function renderMultiplePages(page, additionalInfo, createPage) {
152
177
  ? paginatedPage.fullUrl.slice(0, -1)
153
178
  : paginatedPage.fullUrl;
154
179
  const rightSectionSlug = sectionSlug?.replace(/\//g, '');
155
- const newCompose = `${compose}${compose.endsWith('/') ? '' : '/'
156
- }${rightSectionSlug}`;
180
+ const newCompose = `${compose}${
181
+ compose.endsWith('/') ? '' : '/'
182
+ }${rightSectionSlug}`;
157
183
  paginatedPage.fullUrl = `${fullUrl}/${rightSectionSlug}`;
158
184
  paginatedPage.fullPath.compose = newCompose;
159
185
  paginatedPage.slug = newCompose;
160
186
  paginatedPage.template.activeSectionSlug = sectionSlug;
161
187
  paginatedPage.template.activeSectionBase = fullUrl;
162
188
  if (title.trim()) paginatedPage.title = title;
163
- paginatedPage.metaTitle = metaTitle.trim() || title.trim() || paginatedPage.metaTitle;
189
+ paginatedPage.metaTitle =
190
+ metaTitle.trim() || title.trim() || paginatedPage.metaTitle;
164
191
  if (metaDescription.trim()) paginatedPage.metaDescription = metaDescription;
165
192
  await renderSinglePage(paginatedPage, additionalInfo, createPage);
166
193
  }
@@ -0,0 +1,60 @@
1
+ const { post } = require('../api');
2
+
3
+ const baseURL = process.env.API_URL;
4
+
5
+ async function postSearchInfo({
6
+ title,
7
+ description,
8
+ image,
9
+ pageId,
10
+ languageId,
11
+ siteId,
12
+ url,
13
+ content,
14
+ }) {
15
+ const response = await post(`${baseURL}/search`, {
16
+ title,
17
+ description,
18
+ image,
19
+ pageId,
20
+ languageId,
21
+ siteId,
22
+ url,
23
+ content: prepareHTMLContentForSearch(content),
24
+ });
25
+
26
+ return response;
27
+ }
28
+
29
+ function prepareHTMLContentForSearch(content) {
30
+ const noTagsContent = removeHTMLTags(
31
+ ['meta', 'link', 'style', 'script', 'noscript', 'nav', 'header', 'footer'],
32
+ content,
33
+ ' '
34
+ );
35
+ const plainTextContent = stripHTMLTags(noTagsContent, ' ');
36
+
37
+ return stripSpaces(plainTextContent);
38
+ }
39
+
40
+ function removeHTMLTags(tags, content, replaceWith = '') {
41
+ let filteredContent = content;
42
+
43
+ tags.map(tag => {
44
+ filteredContent = filteredContent
45
+ .replace(new RegExp(`<${tag}.*?>.*?<\/${tag}>`, 'gis'), replaceWith)
46
+ .replace(new RegExp(`(<${tag}([^>]+)>)`, 'gis'), replaceWith);
47
+ });
48
+
49
+ return filteredContent;
50
+ }
51
+
52
+ function stripHTMLTags(content = '', replaceWith = '') {
53
+ return content.replace(/(<([^>]+)>)/gis, replaceWith);
54
+ }
55
+
56
+ function stripSpaces(str) {
57
+ return str.replace(/\s+/gis, ' ');
58
+ }
59
+
60
+ exports.postSearchInfo = postSearchInfo;