@griddo/cx 10.3.22 → 10.3.23

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.
@@ -1,5 +1,6 @@
1
1
  import { getInstanceDomains } from "@exporter/utils/domains";
2
2
  import { downloadBuildData } from "@exporter/utils/download-build-data";
3
+ import { uploadSearchContentToAPI } from "@exporter/utils/searches";
3
4
  import {
4
5
  measureExecutionTime,
5
6
  printExporterLogo,
@@ -66,6 +67,22 @@ async function runGatsbyAdapter() {
66
67
 
67
68
  console.info(`success gatsby build command - ${exeTime}s`);
68
69
 
70
+ /*
71
+ * Gatsby build is done, if the .env GRIDDO_SEARCH_FEATURE is set to true
72
+ * we save the search data in the API.
73
+ */
74
+ const shouldUploadSearchData = JSON.parse(process.env.GRIDDO_SEARCH_FEATURE || "false");
75
+ if (shouldUploadSearchData) {
76
+ exeTime = await measureExecutionTime(uploadSearchContentToAPI).catch((err) => {
77
+ console.error(
78
+ "Error while uploads search content in DDBB :",
79
+ err?.stdout?.toString() || err
80
+ );
81
+ process.exit(1);
82
+ });
83
+
84
+ console.info(`success upload search information to DDBB - ${exeTime}s`);
85
+ }
69
86
  /*
70
87
  * When Gatsby ends, remove disposable artifacts and save .cache and
71
88
  * public foler to use in the next render.
@@ -32,8 +32,8 @@ export type Petition = Record<string, unknown>;
32
32
  // TODO: JSDoc
33
33
  export interface PostSearchInfoProps {
34
34
  title?: string;
35
- description: string;
36
- image: string;
35
+ description: string | null | undefined;
36
+ image: string | null | undefined;
37
37
  pageId?: number;
38
38
  siteId: number;
39
39
  content: string;
@@ -11,20 +11,13 @@ import type {
11
11
  import type { TemplateWithDistributor } from "../types/templates";
12
12
  import type { Core, Fields } from "@griddo/core";
13
13
 
14
- import fs from "node:fs";
15
- import path from "node:path";
16
-
17
14
  import dotenv from "dotenv";
18
15
 
19
- import { postSearchInfo } from "./searches";
20
16
  import { formatImage } from "../../src/utils";
21
17
 
22
18
  dotenv.config();
23
19
 
24
20
  // Envs
25
- const GRIDDO_SEARCH_FEATURE = !!JSON.parse(
26
- process.env.GRIDDO_SEARCH_FEATURE || "false"
27
- );
28
21
  const STRIP_DOMAIN_FROM_PATH = JSON.parse(
29
22
  process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH || "false"
30
23
  );
@@ -213,29 +206,6 @@ async function createGriddoPageObject(
213
206
  },
214
207
  };
215
208
 
216
- if (GRIDDO_SEARCH_FEATURE && !excludeFromSearch) {
217
- const exportFile = path.resolve(
218
- __dirname,
219
- "../../dist/",
220
- `./${pagePath}index.html`
221
- );
222
- const content = fs.existsSync(exportFile)
223
- ? fs.readFileSync(exportFile).toString()
224
- : "";
225
-
226
- await postSearchInfo({
227
- title,
228
- description: openGraph.description || "",
229
- image: openGraph.image || "",
230
- pageId: id,
231
- languageId,
232
- template: page?.template?.templateType || page?.templateId || null,
233
- siteId: page.site,
234
- url: page.fullUrl,
235
- content,
236
- });
237
- }
238
-
239
209
  return griddoPageObject;
240
210
  }
241
211
 
@@ -1,7 +1,11 @@
1
1
  import type { PostSearchInfoResponse } from "../types/api";
2
2
  import type { PostSearchInfoProps } from "../types/global";
3
3
 
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+
4
7
  import { post } from "./api";
8
+ import { getBuildPages } from "./store";
5
9
 
6
10
  // Envs
7
11
  const API_URL = process.env.API_URL as string;
@@ -98,4 +102,49 @@ function stripSpaces(str: string) {
98
102
  return str.replace(/\s+/g, " ");
99
103
  }
100
104
 
101
- export { postSearchInfo };
105
+ /**
106
+ * Function that search in the /public folder the content info of the pages and send it to the search table in the ddbb using the API.
107
+ */
108
+ async function uploadSearchContentToAPI() {
109
+ // Extraemos el path de la carpeta store
110
+ const storeFolder = path.resolve(__dirname, `../store`);
111
+ // Convertimos el string que nos devuelve el env en un booleano
112
+ const isDomainStrippedFromPath: boolean = JSON.parse(process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH || "false");
113
+
114
+
115
+ for await (const store of getBuildPages(storeFolder)) {
116
+ const {
117
+ context: {
118
+ page,
119
+ openGraph
120
+ }
121
+ } = store;
122
+
123
+ const {
124
+ compose,
125
+ domain
126
+ } = page.fullPath;
127
+
128
+ const contextPath = isDomainStrippedFromPath
129
+ ? path.resolve(__dirname, `../dist/${compose}/index.html`)
130
+ : path.resolve(__dirname, `../dist${domain}${compose}/index.html`);
131
+
132
+ const content = fs.readFileSync(contextPath).toString();
133
+
134
+ const pageObject: PostSearchInfoProps = {
135
+ siteId: page.site,
136
+ pageId: page.id,
137
+ title: page.title,
138
+ languageId: page.language,
139
+ url: page.fullUrl,
140
+ template: page.template.templateType || page.templateId,
141
+ description: openGraph.description,
142
+ image: openGraph.image,
143
+ content
144
+ };
145
+
146
+ await postSearchInfo(pageObject);
147
+ }
148
+ }
149
+
150
+ export { postSearchInfo, uploadSearchContentToAPI };
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": "10.3.22",
4
+ "version": "10.3.23",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -70,7 +70,7 @@
70
70
  "react-helmet": "^6.0.0"
71
71
  },
72
72
  "devDependencies": {
73
- "@griddo/eslint-config-back": "^10.3.22",
73
+ "@griddo/eslint-config-back": "^10.3.23",
74
74
  "@types/babel__core": "^7.20.0",
75
75
  "@types/babel__preset-env": "^7.9.2",
76
76
  "@types/csvtojson": "^2.0.0",
@@ -117,5 +117,5 @@
117
117
  "publishConfig": {
118
118
  "access": "public"
119
119
  },
120
- "gitHead": "1016e656a2fb09acc98c3576dcbc3f092bd85ee1"
120
+ "gitHead": "e7753f3423d12e77162843c53fcaac6e6a79c5d9"
121
121
  }