@griddo/cx 11.9.12-rc.0 → 11.9.13
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/README.md +240 -13
- package/build/adapters/gatsby/index.d.ts +4 -0
- package/build/adapters/gatsby/utils.d.ts +26 -0
- package/build/artifacts/index.d.ts +6 -0
- package/build/commands/end-render.d.ts +1 -0
- package/build/commands/reset-render.d.ts +1 -0
- package/build/commands/start-render.d.ts +1 -0
- package/build/commands/upload-search-content.d.ts +1 -0
- package/build/constants/envs.d.ts +37 -0
- package/build/constants/index.d.ts +57 -0
- package/build/end-render.js +74 -0
- package/build/end-render.js.map +7 -0
- package/build/{shared/errors.d.ts → errors/errors-data.d.ts} +3 -5
- package/build/errors/index.d.ts +15 -0
- package/build/index.d.ts +29 -10
- package/build/index.js +73 -406
- package/build/index.js.map +7 -0
- package/build/prepare-domains-render.js +73 -0
- package/build/prepare-domains-render.js.map +7 -0
- package/build/react/Favicon/index.d.ts +5 -0
- package/build/react/GriddoIntegrations/index.d.ts +4 -3
- package/build/react/GriddoIntegrations/utils.d.ts +6 -7
- package/build/react/index.d.ts +2 -3
- package/build/react/index.js +3 -1
- package/build/registers/api.d.ts +9 -0
- package/build/registers/gatsby.d.ts +9 -0
- package/build/registers/index.d.ts +3 -0
- package/build/reset-render.js +74 -0
- package/build/reset-render.js.map +7 -0
- package/build/services/auth.d.ts +5 -2
- package/build/services/domains.d.ts +4 -3
- package/build/services/navigation.d.ts +16 -16
- package/build/services/reference-fields.d.ts +3 -3
- package/build/services/register.d.ts +36 -0
- package/build/services/robots.d.ts +19 -2
- package/build/services/settings.d.ts +4 -0
- package/build/services/sites.d.ts +5 -8
- package/build/services/store.d.ts +1 -10
- package/build/start-render.js +100 -0
- package/build/start-render.js.map +7 -0
- package/build/{shared/types → types}/api.d.ts +18 -18
- package/build/{shared/types → types}/global.d.ts +16 -15
- package/build/{shared/types → types}/navigation.d.ts +5 -5
- package/build/{shared/types → types}/pages.d.ts +9 -9
- package/build/{shared/types → types}/sites.d.ts +19 -18
- package/build/upload-search-content.js +74 -0
- package/build/upload-search-content.js.map +7 -0
- package/build/utils/alerts.d.ts +3 -0
- package/build/{services → utils}/api.d.ts +1 -1
- package/build/utils/cache.d.ts +35 -0
- package/build/utils/core-utils.d.ts +107 -0
- package/build/utils/create-build-data.d.ts +8 -0
- package/build/utils/domains.d.ts +13 -0
- package/build/utils/folders.d.ts +53 -0
- package/build/{core/check-env-health.d.ts → utils/health-checks.d.ts} +2 -4
- package/build/utils/loggin.d.ts +51 -0
- package/build/{services → utils}/pages.d.ts +3 -3
- package/build/utils/render.d.ts +13 -0
- package/build/utils/searches.d.ts +15 -0
- package/build/utils/sites.d.ts +31 -0
- package/build/utils/store.d.ts +81 -0
- package/cx.config.d.ts +5 -0
- package/cx.config.js +36 -0
- package/exporter/adapters/gatsby/index.ts +182 -0
- package/exporter/adapters/gatsby/utils.ts +186 -0
- package/exporter/artifacts/README.md +34 -0
- package/exporter/artifacts/index.ts +33 -0
- package/exporter/build.sh +24 -16
- package/exporter/commands/end-render.ts +86 -65
- package/exporter/commands/move-assets.ts +11 -0
- package/exporter/commands/prepare-domains-render.ts +35 -132
- package/exporter/commands/reset-render.ts +8 -13
- package/exporter/commands/start-render.ts +64 -26
- package/exporter/commands/upload-search-content.ts +26 -204
- package/exporter/{shared → constants}/endpoints.ts +11 -12
- package/exporter/constants/envs.ts +94 -0
- package/exporter/constants/index.ts +129 -0
- package/exporter/{shared/errors.ts → errors/errors-data.ts} +14 -24
- package/exporter/errors/index.ts +40 -0
- package/exporter/index.ts +56 -14
- package/exporter/react/{GriddoFavicon → Favicon}/index.tsx +9 -3
- package/exporter/react/GriddoIntegrations/index.tsx +23 -17
- package/exporter/react/GriddoIntegrations/utils.ts +12 -24
- package/exporter/react/index.tsx +9 -3
- package/exporter/registers/api.ts +14 -0
- package/exporter/registers/gatsby.ts +14 -0
- package/exporter/registers/index.ts +4 -0
- package/exporter/services/auth.ts +10 -8
- package/exporter/services/domains.ts +8 -23
- package/exporter/services/navigation.ts +18 -12
- package/exporter/services/reference-fields.ts +32 -14
- package/exporter/services/register.ts +113 -0
- package/exporter/services/robots.ts +61 -33
- package/exporter/services/settings.ts +17 -0
- package/exporter/services/sites.ts +28 -40
- package/exporter/services/store.ts +321 -354
- package/exporter/{shared/types → types}/api.ts +41 -40
- package/exporter/{shared/types → types}/global.ts +21 -17
- package/exporter/{shared/types → types}/navigation.ts +3 -3
- package/exporter/{shared/types → types}/pages.ts +11 -10
- package/exporter/{shared/types → types}/sites.ts +19 -18
- package/exporter/utils/alerts.ts +29 -0
- package/exporter/utils/api.ts +243 -0
- package/exporter/utils/cache.ts +142 -0
- package/exporter/utils/core-utils.ts +458 -0
- package/exporter/utils/create-build-data.ts +17 -0
- package/exporter/utils/domains.ts +39 -0
- package/exporter/utils/folders.ts +320 -0
- package/exporter/utils/health-checks.ts +64 -0
- package/exporter/{core → utils}/images.ts +6 -1
- package/exporter/{core → utils}/instance.ts +13 -9
- package/exporter/utils/loggin.ts +184 -0
- package/exporter/{services → utils}/pages.ts +92 -27
- package/exporter/utils/render.ts +71 -0
- package/exporter/utils/searches.ts +156 -0
- package/exporter/utils/sites.ts +312 -0
- package/exporter/utils/store.ts +314 -0
- package/gatsby-browser.tsx +58 -41
- package/gatsby-config.ts +17 -10
- package/gatsby-node.ts +79 -20
- package/gatsby-ssr.tsx +1 -2
- package/package.json +80 -41
- package/src/README.md +7 -0
- package/src/components/Head.tsx +73 -28
- package/src/components/template.tsx +29 -6
- package/src/gatsby-node-utils.ts +2 -76
- package/src/html.tsx +11 -2
- package/src/types.ts +3 -3
- package/start-render.js +7 -0
- package/tsconfig.json +3 -5
- package/build/commands/end-render.js +0 -31
- package/build/commands/end-render.js.map +0 -7
- package/build/commands/prepare-assets-directory.js +0 -9
- package/build/commands/prepare-assets-directory.js.map +0 -7
- package/build/commands/prepare-domains-render.js +0 -38
- package/build/commands/prepare-domains-render.js.map +0 -7
- package/build/commands/reset-render.js +0 -31
- package/build/commands/reset-render.js.map +0 -7
- package/build/commands/single-domain-upload-search-content.d.ts +0 -1
- package/build/commands/start-render.js +0 -66
- package/build/commands/start-render.js.map +0 -7
- package/build/commands/upload-search-content.js +0 -32
- package/build/commands/upload-search-content.js.map +0 -7
- package/build/core/GriddoLog.d.ts +0 -16
- package/build/core/db-class.d.ts +0 -11
- package/build/core/db.d.ts +0 -4
- package/build/core/dist-rollback.d.ts +0 -11
- package/build/core/errors.d.ts +0 -26
- package/build/core/fs.d.ts +0 -69
- package/build/core/life-cycle.d.ts +0 -26
- package/build/core/logger.d.ts +0 -18
- package/build/core/objects.d.ts +0 -11
- package/build/core/print-logos.d.ts +0 -5
- package/build/react/DynamicScript/index.d.ts +0 -4
- package/build/react/GriddoFavicon/index.d.ts +0 -4
- package/build/react/GriddoOpenGraph/index.d.ts +0 -10
- package/build/services/manage-sites.d.ts +0 -22
- package/build/services/manage-store.d.ts +0 -32
- package/build/services/render-artifacts.d.ts +0 -6
- package/build/services/render.d.ts +0 -70
- package/build/services/sitemaps.d.ts +0 -5
- package/build/shared/context.d.ts +0 -36
- package/build/shared/envs.d.ts +0 -19
- package/build/shared/npm-modules/brush.d.ts +0 -18
- package/build/shared/npm-modules/find-up-simple.d.ts +0 -34
- package/build/shared/npm-modules/pkg-dir.d.ts +0 -7
- package/build/shared/npm-modules/xml-parser.d.ts +0 -4
- package/build/shared/types/render.d.ts +0 -54
- package/build/shared/types.d.ts +0 -15
- package/build/ssg-adapters/gatsby/actions/clean.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/close.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/data.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/healthCheck.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/init.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/logs.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/meta.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/prepare.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/relocation.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/restore.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/ssg.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/sync.d.ts +0 -3
- package/build/ssg-adapters/gatsby/index.d.ts +0 -9
- package/build/ssg-adapters/gatsby/shared/artifacts.d.ts +0 -4
- package/build/ssg-adapters/gatsby/shared/diff-assets.d.ts +0 -15
- package/build/ssg-adapters/gatsby/shared/extract-assets.d.ts +0 -7
- package/build/ssg-adapters/gatsby/shared/gatsby-build.d.ts +0 -7
- package/build/ssg-adapters/gatsby/shared/render-rollback.d.ts +0 -18
- package/build/ssg-adapters/gatsby/shared/sync-render.d.ts +0 -26
- package/build/ssg-adapters/gatsby/shared/types.d.ts +0 -34
- package/cli.mjs +0 -231
- package/exporter/build-esbuild.noop +0 -42
- package/exporter/commands/README.md +0 -151
- package/exporter/commands/prepare-assets-directory.ts +0 -35
- package/exporter/commands/single-domain-upload-search-content.ts +0 -206
- package/exporter/core/GriddoLog.ts +0 -45
- package/exporter/core/check-env-health.ts +0 -204
- package/exporter/core/db-class.ts +0 -54
- package/exporter/core/db.ts +0 -33
- package/exporter/core/dist-rollback.ts +0 -49
- package/exporter/core/errors.ts +0 -93
- package/exporter/core/fs.ts +0 -385
- package/exporter/core/life-cycle.ts +0 -73
- package/exporter/core/logger.ts +0 -141
- package/exporter/core/objects.ts +0 -37
- package/exporter/core/print-logos.ts +0 -21
- package/exporter/react/DynamicScript/index.tsx +0 -33
- package/exporter/react/GriddoOpenGraph/index.tsx +0 -39
- package/exporter/services/api.ts +0 -306
- package/exporter/services/manage-sites.ts +0 -116
- package/exporter/services/manage-store.ts +0 -173
- package/exporter/services/render-artifacts.ts +0 -44
- package/exporter/services/render.ts +0 -229
- package/exporter/services/sitemaps.ts +0 -129
- package/exporter/shared/context.ts +0 -49
- package/exporter/shared/envs.ts +0 -62
- package/exporter/shared/npm-modules/README.md +0 -36
- package/exporter/shared/npm-modules/brush.ts +0 -34
- package/exporter/shared/npm-modules/find-up-simple.ts +0 -100
- package/exporter/shared/npm-modules/pkg-dir.ts +0 -17
- package/exporter/shared/npm-modules/xml-parser.ts +0 -57
- package/exporter/shared/types/render.ts +0 -63
- package/exporter/shared/types.ts +0 -15
- package/exporter/ssg-adapters/gatsby/actions/clean.ts +0 -26
- package/exporter/ssg-adapters/gatsby/actions/close.ts +0 -17
- package/exporter/ssg-adapters/gatsby/actions/data.ts +0 -22
- package/exporter/ssg-adapters/gatsby/actions/healthCheck.ts +0 -10
- package/exporter/ssg-adapters/gatsby/actions/init.ts +0 -12
- package/exporter/ssg-adapters/gatsby/actions/logs.ts +0 -10
- package/exporter/ssg-adapters/gatsby/actions/meta.ts +0 -13
- package/exporter/ssg-adapters/gatsby/actions/prepare.ts +0 -9
- package/exporter/ssg-adapters/gatsby/actions/relocation.ts +0 -15
- package/exporter/ssg-adapters/gatsby/actions/restore.ts +0 -21
- package/exporter/ssg-adapters/gatsby/actions/ssg.ts +0 -12
- package/exporter/ssg-adapters/gatsby/actions/sync.ts +0 -65
- package/exporter/ssg-adapters/gatsby/index.ts +0 -114
- package/exporter/ssg-adapters/gatsby/shared/artifacts.ts +0 -17
- package/exporter/ssg-adapters/gatsby/shared/diff-assets.ts +0 -128
- package/exporter/ssg-adapters/gatsby/shared/extract-assets.ts +0 -75
- package/exporter/ssg-adapters/gatsby/shared/gatsby-build.ts +0 -58
- package/exporter/ssg-adapters/gatsby/shared/render-rollback.ts +0 -33
- package/exporter/ssg-adapters/gatsby/shared/sync-render.ts +0 -298
- package/exporter/ssg-adapters/gatsby/shared/types.ts +0 -35
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +0 -55
- package/plugins/gatsby-plugin-svgr-loader/package.json +0 -8
- package/tsconfig.commands.json +0 -36
- package/tsconfig.exporter.json +0 -21
- /package/build/commands/{prepare-assets-directory.d.ts → move-assets.d.ts} +0 -0
- /package/build/{shared → constants}/endpoints.d.ts +0 -0
- /package/build/react/{GriddoFavicon → Favicon}/utils.d.ts +0 -0
- /package/build/{shared/types → types}/templates.d.ts +0 -0
- /package/build/{core → utils}/images.d.ts +0 -0
- /package/build/{core → utils}/instance.d.ts +0 -0
- /package/exporter/react/{GriddoFavicon → Favicon}/utils.ts +0 -0
- /package/exporter/{shared/types → types}/templates.ts +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Core, Fields } from "@griddo/core";
|
|
2
1
|
import type {
|
|
3
2
|
APIPageObject,
|
|
4
3
|
GriddoListPage,
|
|
@@ -8,10 +7,15 @@ import type {
|
|
|
8
7
|
MultiPageElement,
|
|
9
8
|
MultiPageElements,
|
|
10
9
|
PageAdditionalInfo,
|
|
11
|
-
} from "../
|
|
12
|
-
import type { TemplateWithReferenceField } from "../
|
|
10
|
+
} from "../types/pages";
|
|
11
|
+
import type { TemplateWithReferenceField } from "../types/templates";
|
|
12
|
+
import type { Core, Fields } from "@griddo/core";
|
|
13
|
+
|
|
14
|
+
import dotenv from "dotenv";
|
|
13
15
|
|
|
14
|
-
import { formatImage } from "
|
|
16
|
+
import { formatImage } from "./images";
|
|
17
|
+
|
|
18
|
+
dotenv.config();
|
|
15
19
|
|
|
16
20
|
// Consts
|
|
17
21
|
const DEFAULT_ITEMS_PER_PAGE_FOR_LIST_TEMPLATES = 25;
|
|
@@ -27,7 +31,10 @@ function getOpenGraph({
|
|
|
27
31
|
socialTitle,
|
|
28
32
|
socialDescription,
|
|
29
33
|
socialImage,
|
|
30
|
-
}: Pick<
|
|
34
|
+
}: Pick<
|
|
35
|
+
Core.Page,
|
|
36
|
+
"socialTitle" | "socialDescription" | "socialImage"
|
|
37
|
+
>): Core.Page["openGraph"] {
|
|
31
38
|
return {
|
|
32
39
|
type: "website",
|
|
33
40
|
title: socialTitle,
|
|
@@ -42,7 +49,9 @@ function getOpenGraph({
|
|
|
42
49
|
*
|
|
43
50
|
* @param params A Page object
|
|
44
51
|
*/
|
|
45
|
-
function getPageMetadata(
|
|
52
|
+
function getPageMetadata(
|
|
53
|
+
params: Core.Page,
|
|
54
|
+
): GriddoPageObject["context"]["pageMetadata"] {
|
|
46
55
|
const {
|
|
47
56
|
title,
|
|
48
57
|
metaTitle,
|
|
@@ -78,7 +87,9 @@ function getPageMetadata(params: Core.Page): GriddoPageObject["context"]["pageMe
|
|
|
78
87
|
index: isIndexed ? "index" : "noindex",
|
|
79
88
|
follow: follow ? "follow" : "nofollow",
|
|
80
89
|
translate: metasAdvancedList.includes("notranslate") ? "notranslate" : "",
|
|
81
|
-
metasAdvanced: metasAdvancedList
|
|
90
|
+
metasAdvanced: metasAdvancedList
|
|
91
|
+
.filter((item) => item !== "notranslate")
|
|
92
|
+
.join(),
|
|
82
93
|
pageLanguages,
|
|
83
94
|
metaKeywords: metaKeywords
|
|
84
95
|
?.filter(Boolean)
|
|
@@ -122,9 +133,8 @@ async function createGriddoPageObject(
|
|
|
122
133
|
siteSlug,
|
|
123
134
|
socials,
|
|
124
135
|
theme,
|
|
125
|
-
navigations,
|
|
136
|
+
navigations: { header, footer },
|
|
126
137
|
} = additionalInfo;
|
|
127
|
-
const { header, footer } = navigations;
|
|
128
138
|
|
|
129
139
|
// Update page object
|
|
130
140
|
page.breadcrumb = breadcrumb;
|
|
@@ -197,7 +207,10 @@ async function createGriddoPageObject(
|
|
|
197
207
|
* @param page A Griddo single page object.
|
|
198
208
|
* @param additionalInfo Additional page info.
|
|
199
209
|
*/
|
|
200
|
-
async function createGriddoSinglePage(
|
|
210
|
+
async function createGriddoSinglePage(
|
|
211
|
+
page: GriddoSinglePage,
|
|
212
|
+
additionalInfo: PageAdditionalInfo,
|
|
213
|
+
) {
|
|
201
214
|
return createGriddoPageObject(page, additionalInfo);
|
|
202
215
|
}
|
|
203
216
|
|
|
@@ -205,7 +218,14 @@ async function createGriddoSinglePage(page: GriddoSinglePage, additionalInfo: Pa
|
|
|
205
218
|
* Create multiples pages from one page as list paginated pages
|
|
206
219
|
*/
|
|
207
220
|
async function createGriddoListPages(
|
|
208
|
-
{
|
|
221
|
+
{
|
|
222
|
+
page,
|
|
223
|
+
pages,
|
|
224
|
+
isRoot = false,
|
|
225
|
+
defaultLang,
|
|
226
|
+
template,
|
|
227
|
+
totalQueriedItems,
|
|
228
|
+
}: GriddoListPage,
|
|
209
229
|
additionalInfo: PageAdditionalInfo,
|
|
210
230
|
) {
|
|
211
231
|
const allPages = pages.map(async (dataInPage, idx) => {
|
|
@@ -213,8 +233,19 @@ async function createGriddoListPages(
|
|
|
213
233
|
const pageNumber = idx + 1;
|
|
214
234
|
const { domainUrl, compose } = page.fullPath;
|
|
215
235
|
|
|
236
|
+
// Crea un id como número negativo y añadiendo un sufijo para los
|
|
237
|
+
// listados estáticos. Esto es así para marcarlas y posteriormente
|
|
238
|
+
// borrarlas siempre en cada nuevo render desde el Adapter.
|
|
239
|
+
//
|
|
240
|
+
// id de página con mode:"list": 1546
|
|
241
|
+
// ids de las "sub-páginas": -15460, -15461, -1546n, (-)id(idx)
|
|
242
|
+
//
|
|
243
|
+
// @todo eliminar el concepto multipage de CX, debería ser algo core de
|
|
244
|
+
// Griddo itself: API/AX, que fuesen páginas con sus ids, etc..
|
|
245
|
+
|
|
216
246
|
const paginatedPage = {
|
|
217
247
|
...page,
|
|
248
|
+
id: Number.parseInt(`-${page.id}${idx}`),
|
|
218
249
|
fullPath: {
|
|
219
250
|
...page.fullPath,
|
|
220
251
|
// Add a page number (tailPageNumber) from page 2 onwards
|
|
@@ -256,11 +287,16 @@ async function createGriddoListPages(
|
|
|
256
287
|
* @param page A Griddo Multipage object.
|
|
257
288
|
* @param additionalInfo Additional page info.
|
|
258
289
|
*/
|
|
259
|
-
function createGriddoMultiPages(
|
|
290
|
+
function createGriddoMultiPages(
|
|
291
|
+
page: GriddoMultiPage,
|
|
292
|
+
additionalInfo: PageAdditionalInfo,
|
|
293
|
+
) {
|
|
260
294
|
const { multiPageElements: multiPageElementsBulk, ...cleanPage } = page;
|
|
261
295
|
// TODO: Use structuredClone() when node 18 is available.
|
|
262
296
|
// WARN!! Se ha probado que parse(stringify()) está tan optimizado que puede ser más rápido que structuredClone...
|
|
263
|
-
const multiPageElements: MultiPageElements = JSON.parse(
|
|
297
|
+
const multiPageElements: MultiPageElements = JSON.parse(
|
|
298
|
+
JSON.stringify(multiPageElementsBulk),
|
|
299
|
+
);
|
|
264
300
|
|
|
265
301
|
// Si no hay un elemento sin slug, como mínimo hay que dibujar una página
|
|
266
302
|
// principal para el conjunto de páginas.
|
|
@@ -269,7 +305,7 @@ function createGriddoMultiPages(page: GriddoMultiPage, additionalInfo: PageAddit
|
|
|
269
305
|
}
|
|
270
306
|
|
|
271
307
|
// Creates each page based on `multiPageElements` from the schema.
|
|
272
|
-
const allPages = multiPageElements.map(async (pageElement) => {
|
|
308
|
+
const allPages = multiPageElements.map(async (pageElement, idx) => {
|
|
273
309
|
// TODO: Use structuredClone() when node 18 is available.
|
|
274
310
|
// WARN!! Se ha probado que parse(stringify()) está tan optimizado que puede ser más rápido que structuredClone...
|
|
275
311
|
const paginatedPage: APIPageObject = JSON.parse(JSON.stringify(cleanPage));
|
|
@@ -287,7 +323,9 @@ function createGriddoMultiPages(page: GriddoMultiPage, additionalInfo: PageAddit
|
|
|
287
323
|
|
|
288
324
|
const cleanSectionSlug = sectionSlug?.replace(/\//g, "");
|
|
289
325
|
const isRootSlug = sectionSlug === "/";
|
|
290
|
-
const rightSectionSlug = isRootSlug
|
|
326
|
+
const rightSectionSlug = isRootSlug
|
|
327
|
+
? cleanSectionSlug
|
|
328
|
+
: `${cleanSectionSlug}/`;
|
|
291
329
|
|
|
292
330
|
const slash = compose.endsWith("/") ? "" : "/";
|
|
293
331
|
const newCompose = `${compose}${slash}${rightSectionSlug}`;
|
|
@@ -300,12 +338,24 @@ function createGriddoMultiPages(page: GriddoMultiPage, additionalInfo: PageAddit
|
|
|
300
338
|
paginatedPage.metaDescription = metaDescription;
|
|
301
339
|
}
|
|
302
340
|
|
|
341
|
+
// Crea un id como número negativo y añadiendo un sufijo para las multipages.
|
|
342
|
+
// Esto es así para marcarlas y posteriormente borrarlas siempre en cada
|
|
343
|
+
// nuevo render desde el Adapter.
|
|
344
|
+
//
|
|
345
|
+
// id de página con hasMultipageTrue: 1546
|
|
346
|
+
// ids de las "sub-páginas": -15460, -15461, -1546n, (-)id(idx)
|
|
347
|
+
//
|
|
348
|
+
// @todo eliminar el concepto multipage de CX, debería ser algo core de
|
|
349
|
+
// Griddo itself: API/AX, que fuesen páginas con sus ids, etc..
|
|
350
|
+
paginatedPage.id = Number.parseInt(`-${paginatedPage.id}${idx}`);
|
|
351
|
+
|
|
303
352
|
paginatedPage.fullUrl = `${fullUrl}/${rightSectionSlug}`;
|
|
304
353
|
paginatedPage.fullPath.compose = newCompose;
|
|
305
354
|
paginatedPage.slug = newCompose;
|
|
306
355
|
paginatedPage.template.activeSectionSlug = sectionSlug;
|
|
307
356
|
paginatedPage.template.activeSectionBase = fullUrl;
|
|
308
|
-
paginatedPage.metaTitle =
|
|
357
|
+
paginatedPage.metaTitle =
|
|
358
|
+
metaTitle.trim() || title.trim() || paginatedPage.metaTitle;
|
|
309
359
|
|
|
310
360
|
return createGriddoPageObject(paginatedPage, additionalInfo);
|
|
311
361
|
});
|
|
@@ -318,7 +368,9 @@ function createGriddoMultiPages(page: GriddoMultiPage, additionalInfo: PageAddit
|
|
|
318
368
|
*
|
|
319
369
|
* @param page The page to get the multipage parts.
|
|
320
370
|
*/
|
|
321
|
-
function getMultiPageElements(
|
|
371
|
+
function getMultiPageElements(
|
|
372
|
+
page: TemplateWithReferenceField,
|
|
373
|
+
): Promise<MultiPageElements> | null {
|
|
322
374
|
const multiPageElements = new Promise((resolve) => {
|
|
323
375
|
// Recursive
|
|
324
376
|
const getMultiPageComponent = (
|
|
@@ -337,12 +389,13 @@ function getMultiPageElements(page: TemplateWithReferenceField): Promise<MultiPa
|
|
|
337
389
|
const currentComponent = template[key] as {
|
|
338
390
|
component: string;
|
|
339
391
|
hasGriddoMultiPage: boolean;
|
|
340
|
-
elements: Record<string, unknown
|
|
392
|
+
elements: Array<Record<string, unknown>>;
|
|
341
393
|
};
|
|
342
|
-
const isValidComponent =
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
394
|
+
const isValidComponent =
|
|
395
|
+
currentComponent || typeof currentComponent === "object";
|
|
396
|
+
const hasGriddoMultiPageProp = JSON.stringify(
|
|
397
|
+
currentComponent,
|
|
398
|
+
).includes('"hasGriddoMultiPage":true');
|
|
346
399
|
|
|
347
400
|
if (!isValidComponent) {
|
|
348
401
|
continue;
|
|
@@ -392,7 +445,11 @@ function getMultiPageElements(page: TemplateWithReferenceField): Promise<MultiPa
|
|
|
392
445
|
* getPage(3, ["a", "b", "c", "d", "e", "f", "g", "h"], 2)
|
|
393
446
|
* // -> ["d", "e", "f"]
|
|
394
447
|
*/
|
|
395
|
-
function getPage(
|
|
448
|
+
function getPage(
|
|
449
|
+
itemsPerPage: number,
|
|
450
|
+
items: Array<Fields.QueriedDataItem>,
|
|
451
|
+
page: number,
|
|
452
|
+
) {
|
|
396
453
|
return items?.slice(itemsPerPage * (page - 1), itemsPerPage * page);
|
|
397
454
|
}
|
|
398
455
|
|
|
@@ -406,11 +463,16 @@ function getPage(itemsPerPage: number, items: Fields.QueriedDataItem[], page: nu
|
|
|
406
463
|
* getPageCluster(3, ["a", "b", "c", "d", "e", "f", "g", "h"])
|
|
407
464
|
* // -> [["a", "b", "c"], ["d", "e", "f"], ["g", "h"]]
|
|
408
465
|
*/
|
|
409
|
-
function getPageCluster(
|
|
466
|
+
function getPageCluster(
|
|
467
|
+
itemsPerPage: number,
|
|
468
|
+
items: Array<Fields.QueriedDataItem>,
|
|
469
|
+
) {
|
|
410
470
|
const totalPagesCount = Math.ceil(items.length / itemsPerPage) || 1;
|
|
411
471
|
const pageNumbers = Array.from({ length: totalPagesCount }, (_, i) => i + 1);
|
|
412
472
|
|
|
413
|
-
return pageNumbers?.map((pageNumber) =>
|
|
473
|
+
return pageNumbers?.map((pageNumber) =>
|
|
474
|
+
getPage(itemsPerPage, items, pageNumber),
|
|
475
|
+
);
|
|
414
476
|
}
|
|
415
477
|
|
|
416
478
|
/**
|
|
@@ -420,7 +482,8 @@ function getPageCluster(itemsPerPage: number, items: Fields.QueriedDataItem[]) {
|
|
|
420
482
|
*/
|
|
421
483
|
function getPaginatedPages(listTemplate: TemplateWithReferenceField) {
|
|
422
484
|
const items = listTemplate.queriedItems || [];
|
|
423
|
-
const itemsPerPage =
|
|
485
|
+
const itemsPerPage =
|
|
486
|
+
listTemplate?.itemsPerPage || DEFAULT_ITEMS_PER_PAGE_FOR_LIST_TEMPLATES;
|
|
424
487
|
const pageClusters = getPageCluster(itemsPerPage, items);
|
|
425
488
|
|
|
426
489
|
return pageClusters;
|
|
@@ -461,7 +524,9 @@ function addPageNumberToUrl(
|
|
|
461
524
|
return removeDuplicateTrailing(`${url}${endingSlash}`);
|
|
462
525
|
}
|
|
463
526
|
|
|
464
|
-
return removeDuplicateTrailing(
|
|
527
|
+
return removeDuplicateTrailing(
|
|
528
|
+
`${url}${trailingSlash}${pageNumber}${endingSlash}`,
|
|
529
|
+
);
|
|
465
530
|
}
|
|
466
531
|
|
|
467
532
|
/**
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { envs } from "../constants";
|
|
5
|
+
import { throwError } from "../errors";
|
|
6
|
+
import { RenderUUIDError } from "../errors/errors-data";
|
|
7
|
+
import { apiRegister } from "../registers";
|
|
8
|
+
import { insertAlert } from "./alerts";
|
|
9
|
+
import { getConfig } from "./core-utils";
|
|
10
|
+
import { debugLog } from "./loggin";
|
|
11
|
+
|
|
12
|
+
const config = getConfig();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates a sentinel file with the current date and time.
|
|
16
|
+
* This file is used to track later if node_modules/@griddo/cx was cleaned by a
|
|
17
|
+
* npm install from a deploy.
|
|
18
|
+
*/
|
|
19
|
+
function createSentinelRenderFile() {
|
|
20
|
+
const { __cx } = config.paths();
|
|
21
|
+
const renderSentinelFile = path.join(__cx, ".render-sentinel");
|
|
22
|
+
fs.writeFileSync(renderSentinelFile, new Date().toISOString());
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function deleteSentinelRenderFile() {
|
|
26
|
+
const { __cx } = config.paths();
|
|
27
|
+
const renderSentinelFile = path.join(__cx, ".render-sentinel");
|
|
28
|
+
fs.unlinkSync(renderSentinelFile);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isValidRender() {
|
|
32
|
+
const { __cx } = config.paths();
|
|
33
|
+
const renderSentinelFile = path.join(__cx, ".render-sentinel");
|
|
34
|
+
if (!fs.existsSync(renderSentinelFile)) {
|
|
35
|
+
throwError(RenderUUIDError);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Send the default registers through Griddo alerts.
|
|
41
|
+
*/
|
|
42
|
+
async function sendGriddoDefaultAlerts() {
|
|
43
|
+
if (envs.GRIDDO_ALERT_FEATURE) {
|
|
44
|
+
const registerContent = apiRegister.get("API_RESPONSE_TOO_BIG");
|
|
45
|
+
|
|
46
|
+
if (registerContent.entries.length < 1) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
debugLog("\nRender register report\n");
|
|
51
|
+
debugLog(registerContent);
|
|
52
|
+
debugLog();
|
|
53
|
+
|
|
54
|
+
await insertAlert({
|
|
55
|
+
description: `API response size is too large (${envs.GRIDDO_API_MAX_RESPONSE_SIZE}KB).`,
|
|
56
|
+
area: "Griddo",
|
|
57
|
+
level: "W",
|
|
58
|
+
fullData: {
|
|
59
|
+
output: registerContent,
|
|
60
|
+
date: new Date().toISOString(),
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
createSentinelRenderFile,
|
|
68
|
+
deleteSentinelRenderFile,
|
|
69
|
+
isValidRender,
|
|
70
|
+
sendGriddoDefaultAlerts,
|
|
71
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { PostSearchInfoResponse } from "../types/api";
|
|
2
|
+
import type {
|
|
3
|
+
AIEmbeddingsResponse,
|
|
4
|
+
PostSearchInfoProps,
|
|
5
|
+
} from "../types/global";
|
|
6
|
+
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
|
|
10
|
+
import { post } from "./api";
|
|
11
|
+
import { getConfig } from "./core-utils";
|
|
12
|
+
import { getBuildPagesFromCachedStore } from "./store";
|
|
13
|
+
import { endpoints } from "../constants";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Save in the BBDD the content of a page parsed without HTML tags.
|
|
17
|
+
*
|
|
18
|
+
* @param props Object with parts of the final page object to be saved in the BBDD.
|
|
19
|
+
*/
|
|
20
|
+
async function postSearchInfo(props: PostSearchInfoProps) {
|
|
21
|
+
const {
|
|
22
|
+
title,
|
|
23
|
+
description,
|
|
24
|
+
image,
|
|
25
|
+
pageId,
|
|
26
|
+
languageId,
|
|
27
|
+
siteId,
|
|
28
|
+
url,
|
|
29
|
+
content,
|
|
30
|
+
template,
|
|
31
|
+
} = props;
|
|
32
|
+
|
|
33
|
+
const response = await post<PostSearchInfoResponse>({
|
|
34
|
+
endpoint: endpoints.SEARCH,
|
|
35
|
+
body: {
|
|
36
|
+
title,
|
|
37
|
+
description,
|
|
38
|
+
image,
|
|
39
|
+
pageId,
|
|
40
|
+
languageId,
|
|
41
|
+
siteId,
|
|
42
|
+
url,
|
|
43
|
+
template,
|
|
44
|
+
content,
|
|
45
|
+
},
|
|
46
|
+
useApiCacheDir: false,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return response;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Remove the every cntent inside some HTML tags including them.
|
|
54
|
+
*
|
|
55
|
+
* @param content A string with the content.
|
|
56
|
+
*/
|
|
57
|
+
function prepareHTMLContentForSearch(content: string): string {
|
|
58
|
+
// 1. Remove script, style, and other unwanted block tags and their content.
|
|
59
|
+
// The regex looks for <tag...>...</tag> where tag is one of the specified ones.
|
|
60
|
+
const tagsToRemove = [
|
|
61
|
+
"meta",
|
|
62
|
+
"link",
|
|
63
|
+
"style",
|
|
64
|
+
"script",
|
|
65
|
+
"noscript",
|
|
66
|
+
"nav",
|
|
67
|
+
"header",
|
|
68
|
+
"footer",
|
|
69
|
+
];
|
|
70
|
+
const removeTagsRegex = new RegExp(
|
|
71
|
+
`<(${tagsToRemove.join("|")})\\b[^>]*>.*?<\\/\\1>`,
|
|
72
|
+
"gis",
|
|
73
|
+
);
|
|
74
|
+
let processedContent = content.replace(removeTagsRegex, "");
|
|
75
|
+
|
|
76
|
+
// 2. Strip all remaining HTML tags.
|
|
77
|
+
processedContent = processedContent.replace(/<[^>]+>/g, " ");
|
|
78
|
+
|
|
79
|
+
// 3. Normalize whitespace: replace multiple spaces/newlines with a single space and trim.
|
|
80
|
+
processedContent = processedContent.replace(/\s+/g, " ").trim();
|
|
81
|
+
|
|
82
|
+
return processedContent;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Function that search in the `/public` dir the content info of the pages and
|
|
87
|
+
* send it to the search table in the ddbb using the API.
|
|
88
|
+
*/
|
|
89
|
+
async function uploadRenderedSearchContentToAPI(
|
|
90
|
+
distDomainPath: string,
|
|
91
|
+
domain: string,
|
|
92
|
+
) {
|
|
93
|
+
const config = getConfig();
|
|
94
|
+
const { __cache } = config.paths(domain);
|
|
95
|
+
|
|
96
|
+
// Extraemos el path de la carpeta store dentro de un dominio
|
|
97
|
+
const storeFolder = path.join(__cache, "store");
|
|
98
|
+
|
|
99
|
+
// Este caso sería que el dominio existe en la instancia pero no hay sites
|
|
100
|
+
// renderizardos bajo el mismo. Por lo que `store` no existe.
|
|
101
|
+
if (!fs.existsSync(storeFolder)) {
|
|
102
|
+
console.log(
|
|
103
|
+
`Skipping uploading content to the search endpoint for the domain ${domain}, it has not exported sites.`,
|
|
104
|
+
);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Obtenemos las páginas del store cacheado de un dominio
|
|
109
|
+
const storePages = getBuildPagesFromCachedStore(domain);
|
|
110
|
+
|
|
111
|
+
for await (const store of storePages) {
|
|
112
|
+
const {
|
|
113
|
+
context: { page, openGraph, pageMetadata },
|
|
114
|
+
} = store;
|
|
115
|
+
|
|
116
|
+
const { compose } = page.fullPath;
|
|
117
|
+
|
|
118
|
+
const contextPath = path.resolve(`${distDomainPath}/${compose}/index.html`);
|
|
119
|
+
|
|
120
|
+
const content = fs.readFileSync(contextPath).toString();
|
|
121
|
+
|
|
122
|
+
const pageObject: PostSearchInfoProps = {
|
|
123
|
+
siteId: page.site,
|
|
124
|
+
pageId: page.id,
|
|
125
|
+
// `pageMetadata.title` has already a fallback `metatitle ||
|
|
126
|
+
// pageTitle` so probably `title` never will be take the
|
|
127
|
+
// `openGraph?.title` value. Only when the `metatitle` and
|
|
128
|
+
// `pageTitle` are empty.
|
|
129
|
+
title: pageMetadata?.title || openGraph?.title,
|
|
130
|
+
languageId: page.language,
|
|
131
|
+
url: page.fullUrl,
|
|
132
|
+
template: page.template.templateType || page.templateId,
|
|
133
|
+
description: pageMetadata?.description || openGraph?.description,
|
|
134
|
+
image: openGraph.image,
|
|
135
|
+
content: prepareHTMLContentForSearch(content),
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
await postSearchInfo(pageObject);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function startAIEmbeddings() {
|
|
143
|
+
try {
|
|
144
|
+
await post<AIEmbeddingsResponse>({
|
|
145
|
+
endpoint: endpoints.AI_EMBEDDINGS,
|
|
146
|
+
useApiCacheDir: false,
|
|
147
|
+
});
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.warn(
|
|
150
|
+
"There was an error with the ai embeddings",
|
|
151
|
+
(error as Error).message,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { postSearchInfo, startAIEmbeddings, uploadRenderedSearchContentToAPI };
|