@griddo/cx 11.7.12-rc.3 → 11.7.12
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 +226 -27
- package/build/adapters/gatsby/index.d.ts +4 -0
- package/build/adapters/gatsby/utils.d.ts +22 -0
- package/build/artifacts/index.d.ts +6 -0
- package/build/commands/end-render.d.ts +2 -0
- package/build/commands/move-assets.d.ts +1 -0
- package/build/commands/prepare-domains-render.d.ts +1 -0
- package/build/commands/reset-render.d.ts +2 -0
- package/build/commands/start-render.d.ts +2 -0
- package/build/commands/upload-search-content.d.ts +2 -0
- package/build/constants/endpoints.d.ts +19 -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/errors/errors-data.d.ts +22 -0
- package/build/errors/index.d.ts +15 -0
- package/build/index.d.ts +29 -0
- package/build/index.js +73 -0
- 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/Favicon/utils.d.ts +9 -0
- package/build/react/GriddoIntegrations/index.d.ts +20 -0
- package/build/react/GriddoIntegrations/utils.d.ts +26 -0
- package/{react/index.tsx → build/react/index.d.ts} +0 -1
- package/build/react/index.js +3 -0
- 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 +10 -0
- package/build/services/domains.d.ts +6 -0
- package/build/services/navigation.d.ts +50 -0
- package/build/services/reference-fields.d.ts +20 -0
- package/build/services/register.d.ts +36 -0
- package/build/services/robots.d.ts +19 -0
- package/build/services/settings.d.ts +4 -0
- package/build/services/sites.d.ts +29 -0
- package/build/services/store.d.ts +6 -0
- package/build/start-render.js +100 -0
- package/build/start-render.js.map +7 -0
- package/build/types/api.d.ts +142 -0
- package/build/types/global.d.ts +84 -0
- package/build/types/navigation.d.ts +28 -0
- package/build/types/pages.d.ts +144 -0
- package/build/types/sites.d.ts +57 -0
- package/build/types/templates.d.ts +8 -0
- 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/utils/api.d.ts +23 -0
- 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/utils/health-checks.d.ts +7 -0
- package/build/utils/images.d.ts +16 -0
- package/build/utils/instance.d.ts +21 -0
- package/build/utils/loggin.d.ts +51 -0
- package/build/utils/pages.d.ts +34 -0
- 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 +153 -73
- package/exporter/adapters/gatsby/utils.ts +161 -0
- package/exporter/artifacts/README.md +34 -0
- package/exporter/artifacts/index.ts +33 -0
- package/exporter/build.sh +38 -4
- package/exporter/commands/end-render.ts +70 -72
- package/exporter/commands/move-assets.ts +11 -0
- package/exporter/commands/prepare-domains-render.ts +31 -143
- package/exporter/commands/reset-render.ts +3 -10
- package/exporter/commands/start-render.ts +45 -22
- package/exporter/commands/upload-search-content.ts +21 -194
- package/exporter/constants/endpoints.ts +1 -2
- package/exporter/constants/envs.ts +55 -57
- package/exporter/constants/index.ts +129 -0
- package/exporter/{constants/errors.ts → errors/errors-data.ts} +14 -24
- package/exporter/{utils/errors.ts → errors/index.ts} +9 -10
- package/exporter/index.ts +82 -0
- package/{react → exporter/react}/Favicon/index.tsx +7 -1
- package/{react → exporter/react}/GriddoIntegrations/index.tsx +22 -16
- package/{react → exporter/react}/GriddoIntegrations/utils.ts +9 -21
- package/exporter/react/index.tsx +11 -0
- 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 +6 -7
- package/exporter/services/domains.ts +16 -0
- package/exporter/services/navigation.ts +10 -4
- package/exporter/services/reference-fields.ts +24 -9
- package/exporter/services/register.ts +113 -0
- package/exporter/services/robots.ts +16 -9
- package/exporter/services/settings.ts +17 -0
- package/exporter/services/sites.ts +24 -36
- package/exporter/services/store.ts +96 -107
- package/exporter/types/api.ts +28 -27
- package/exporter/types/global.ts +11 -8
- package/exporter/types/navigation.ts +1 -1
- package/exporter/types/pages.ts +3 -2
- package/exporter/types/sites.ts +2 -1
- package/exporter/utils/alerts.ts +29 -0
- package/exporter/utils/api.ts +75 -55
- package/exporter/utils/cache.ts +62 -37
- package/exporter/utils/core-utils.ts +272 -133
- package/exporter/utils/create-build-data.ts +17 -0
- package/exporter/utils/domains.ts +7 -10
- package/exporter/utils/folders.ts +98 -163
- package/exporter/utils/health-checks.ts +64 -0
- package/exporter/utils/images.ts +6 -1
- package/exporter/utils/instance.ts +13 -9
- package/exporter/utils/loggin.ts +91 -44
- package/exporter/utils/pages.ts +88 -23
- package/exporter/utils/render.ts +48 -180
- package/exporter/utils/searches.ts +156 -0
- package/exporter/utils/sites.ts +197 -19
- package/exporter/utils/store.ts +180 -87
- package/gatsby-browser.tsx +58 -41
- package/gatsby-config.ts +17 -10
- package/gatsby-node.ts +78 -17
- package/gatsby-ssr.tsx +1 -2
- package/package.json +86 -36
- package/src/README.md +7 -0
- package/src/components/Head.tsx +46 -13
- package/src/components/template.tsx +30 -8
- package/src/gatsby-node-utils.ts +2 -73
- package/src/html.tsx +11 -2
- package/src/types.ts +5 -5
- package/start-render.js +7 -0
- package/tsconfig.json +3 -5
- package/build/adapters/gatsby/actions/clean.js +0 -10
- package/build/adapters/gatsby/actions/clean.js.map +0 -1
- package/build/adapters/gatsby/actions/close.js +0 -12
- package/build/adapters/gatsby/actions/close.js.map +0 -1
- package/build/adapters/gatsby/actions/data.js +0 -18
- package/build/adapters/gatsby/actions/data.js.map +0 -1
- package/build/adapters/gatsby/actions/healthCheck.js +0 -10
- package/build/adapters/gatsby/actions/healthCheck.js.map +0 -1
- package/build/adapters/gatsby/actions/init.js +0 -22
- package/build/adapters/gatsby/actions/init.js.map +0 -1
- package/build/adapters/gatsby/actions/logs.js +0 -11
- package/build/adapters/gatsby/actions/logs.js.map +0 -1
- package/build/adapters/gatsby/actions/meta.js +0 -13
- package/build/adapters/gatsby/actions/meta.js.map +0 -1
- package/build/adapters/gatsby/actions/prepare.js +0 -9
- package/build/adapters/gatsby/actions/prepare.js.map +0 -1
- package/build/adapters/gatsby/actions/relocation.js +0 -15
- package/build/adapters/gatsby/actions/relocation.js.map +0 -1
- package/build/adapters/gatsby/actions/restore.js +0 -26
- package/build/adapters/gatsby/actions/restore.js.map +0 -1
- package/build/adapters/gatsby/actions/ssg.js +0 -9
- package/build/adapters/gatsby/actions/ssg.js.map +0 -1
- package/build/adapters/gatsby/actions/sync.js +0 -51
- package/build/adapters/gatsby/actions/sync.js.map +0 -1
- package/build/adapters/gatsby/index.js +0 -78
- package/build/adapters/gatsby/index.js.map +0 -1
- package/build/adapters/gatsby/shared/artifacts.js +0 -20
- package/build/adapters/gatsby/shared/artifacts.js.map +0 -1
- package/build/adapters/gatsby/shared/context.js +0 -31
- package/build/adapters/gatsby/shared/context.js.map +0 -1
- package/build/adapters/gatsby/shared/diff-assets.js +0 -101
- package/build/adapters/gatsby/shared/diff-assets.js.map +0 -1
- package/build/adapters/gatsby/shared/extract-assets.js +0 -58
- package/build/adapters/gatsby/shared/extract-assets.js.map +0 -1
- package/build/adapters/gatsby/shared/gatsby-build.js +0 -55
- package/build/adapters/gatsby/shared/gatsby-build.js.map +0 -1
- package/build/adapters/gatsby/shared/sync-render.js +0 -210
- package/build/adapters/gatsby/shared/sync-render.js.map +0 -1
- package/build/adapters/gatsby/shared/types.js +0 -3
- package/build/adapters/gatsby/shared/types.js.map +0 -1
- package/build/commands/end-render.js +0 -87
- package/build/commands/end-render.js.map +0 -1
- package/build/commands/prepare-assets-directory.js +0 -30
- package/build/commands/prepare-assets-directory.js.map +0 -1
- package/build/commands/prepare-domains-render.js +0 -133
- package/build/commands/prepare-domains-render.js.map +0 -1
- package/build/commands/reset-render.js +0 -21
- package/build/commands/reset-render.js.map +0 -1
- package/build/commands/start-render.js +0 -44
- package/build/commands/start-render.js.map +0 -1
- package/build/commands/upload-search-content.js +0 -180
- package/build/commands/upload-search-content.js.map +0 -1
- package/build/constants/endpoints.js +0 -43
- package/build/constants/endpoints.js.map +0 -1
- package/build/constants/envs.js +0 -68
- package/build/constants/envs.js.map +0 -1
- package/build/constants/errors.js +0 -81
- package/build/constants/errors.js.map +0 -1
- package/build/services/auth.js +0 -40
- package/build/services/auth.js.map +0 -1
- package/build/services/db-class.js +0 -49
- package/build/services/db-class.js.map +0 -1
- package/build/services/db.js +0 -34
- package/build/services/db.js.map +0 -1
- package/build/services/navigation.js +0 -96
- package/build/services/navigation.js.map +0 -1
- package/build/services/reference-fields.js +0 -131
- package/build/services/reference-fields.js.map +0 -1
- package/build/services/robots.js +0 -60
- package/build/services/robots.js.map +0 -1
- package/build/services/sites.js +0 -110
- package/build/services/sites.js.map +0 -1
- package/build/services/store.js +0 -257
- package/build/services/store.js.map +0 -1
- package/build/types/api.js +0 -3
- package/build/types/api.js.map +0 -1
- package/build/types/global.js +0 -3
- package/build/types/global.js.map +0 -1
- package/build/types/navigation.js +0 -3
- package/build/types/navigation.js.map +0 -1
- package/build/types/pages.js +0 -3
- package/build/types/pages.js.map +0 -1
- package/build/types/render.js +0 -10
- package/build/types/render.js.map +0 -1
- package/build/types/sites.js +0 -3
- package/build/types/sites.js.map +0 -1
- package/build/types/templates.js +0 -3
- package/build/types/templates.js.map +0 -1
- package/build/utils/api.js +0 -165
- package/build/utils/api.js.map +0 -1
- package/build/utils/artifacts.js +0 -38
- package/build/utils/artifacts.js.map +0 -1
- package/build/utils/brush.js +0 -30
- package/build/utils/brush.js.map +0 -1
- package/build/utils/cache.js +0 -106
- package/build/utils/cache.js.map +0 -1
- package/build/utils/check-environment-health.js +0 -73
- package/build/utils/check-environment-health.js.map +0 -1
- package/build/utils/core-utils.js +0 -270
- package/build/utils/core-utils.js.map +0 -1
- package/build/utils/domains.js +0 -37
- package/build/utils/domains.js.map +0 -1
- package/build/utils/errors.js +0 -30
- package/build/utils/errors.js.map +0 -1
- package/build/utils/folders.js +0 -341
- package/build/utils/folders.js.map +0 -1
- package/build/utils/images.js +0 -45
- package/build/utils/images.js.map +0 -1
- package/build/utils/instance.js +0 -66
- package/build/utils/instance.js.map +0 -1
- package/build/utils/loggin.js +0 -119
- package/build/utils/loggin.js.map +0 -1
- package/build/utils/npm-deps/find-up-simple.js +0 -75
- package/build/utils/npm-deps/find-up-simple.js.map +0 -1
- package/build/utils/npm-deps/pkg-dir.js +0 -20
- package/build/utils/npm-deps/pkg-dir.js.map +0 -1
- package/build/utils/npm-deps/xml-parser.js +0 -49
- package/build/utils/npm-deps/xml-parser.js.map +0 -1
- package/build/utils/pages.js +0 -359
- package/build/utils/pages.js.map +0 -1
- package/build/utils/render.js +0 -168
- package/build/utils/render.js.map +0 -1
- package/build/utils/sitemaps.js +0 -110
- package/build/utils/sitemaps.js.map +0 -1
- package/build/utils/sites.js +0 -105
- package/build/utils/sites.js.map +0 -1
- package/build/utils/store.js +0 -193
- package/build/utils/store.js.map +0 -1
- package/cli.mjs +0 -136
- package/exporter/adapters/gatsby/actions/clean.ts +0 -14
- package/exporter/adapters/gatsby/actions/close.ts +0 -17
- package/exporter/adapters/gatsby/actions/data.ts +0 -25
- package/exporter/adapters/gatsby/actions/healthCheck.ts +0 -10
- package/exporter/adapters/gatsby/actions/init.ts +0 -26
- package/exporter/adapters/gatsby/actions/logs.ts +0 -12
- package/exporter/adapters/gatsby/actions/meta.ts +0 -16
- package/exporter/adapters/gatsby/actions/prepare.ts +0 -9
- package/exporter/adapters/gatsby/actions/relocation.ts +0 -15
- package/exporter/adapters/gatsby/actions/restore.ts +0 -36
- package/exporter/adapters/gatsby/actions/ssg.ts +0 -12
- package/exporter/adapters/gatsby/actions/sync.ts +0 -71
- package/exporter/adapters/gatsby/shared/artifacts.ts +0 -16
- package/exporter/adapters/gatsby/shared/context.ts +0 -50
- package/exporter/adapters/gatsby/shared/diff-assets.ts +0 -113
- package/exporter/adapters/gatsby/shared/extract-assets.ts +0 -61
- package/exporter/adapters/gatsby/shared/gatsby-build.ts +0 -58
- package/exporter/adapters/gatsby/shared/sync-render.ts +0 -276
- package/exporter/adapters/gatsby/shared/types.ts +0 -35
- package/exporter/build-esbuild.noop +0 -42
- package/exporter/commands/prepare-assets-directory.ts +0 -30
- package/exporter/services/db-class.ts +0 -54
- package/exporter/services/db.ts +0 -32
- package/exporter/types/render.ts +0 -59
- package/exporter/utils/artifacts.ts +0 -38
- package/exporter/utils/brush.ts +0 -34
- package/exporter/utils/check-environment-health.ts +0 -84
- package/exporter/utils/npm-deps/find-up-simple.ts +0 -100
- package/exporter/utils/npm-deps/pkg-dir.ts +0 -17
- package/exporter/utils/npm-deps/xml-parser.ts +0 -57
- package/exporter/utils/sitemaps.ts +0 -129
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +0 -55
- package/plugins/gatsby-plugin-svgr-loader/package.json +0 -8
- package/react/DynamicScript/index.tsx +0 -33
- package/tsconfig.commands.json +0 -36
- package/tsconfig.exporter.json +0 -19
- /package/{react → exporter/react}/Favicon/utils.ts +0 -0
package/exporter/utils/loggin.ts
CHANGED
|
@@ -1,39 +1,52 @@
|
|
|
1
1
|
import type { Site } from "../types/sites";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import path from "node:path";
|
|
3
|
+
import kleur from "kleur";
|
|
5
4
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { brush } from "./brush";
|
|
5
|
+
import { envs } from "../constants";
|
|
6
|
+
import { getConfig } from "./core-utils";
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Custom basic logging function controlled by a environment variable.
|
|
10
|
+
*
|
|
12
11
|
* @param str The string to be logged.
|
|
13
12
|
*/
|
|
14
13
|
function verboseLog(str: string) {
|
|
15
|
-
if (GRIDDO_VERBOSE_LOGS) {
|
|
16
|
-
console.log(
|
|
14
|
+
if (envs.GRIDDO_VERBOSE_LOGS) {
|
|
15
|
+
console.log(
|
|
16
|
+
kleur.yellow("verbose"),
|
|
17
|
+
kleur.dim(str.replace(/(\s)\s+/g, "$1").trim()),
|
|
18
|
+
);
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Custom log inside a line-box.
|
|
24
|
+
*
|
|
22
25
|
* @param stringValue The string to be logged.
|
|
23
26
|
* @param paddingInline The number of white spaces inside the box at left and right.
|
|
24
27
|
* @param paddingBlock The number of white spaces inside the box at top and bottom.
|
|
25
28
|
*/
|
|
26
|
-
function boxLog(
|
|
29
|
+
function boxLog(
|
|
30
|
+
stringValue: string,
|
|
31
|
+
title = "",
|
|
32
|
+
paddingInline = 1,
|
|
33
|
+
paddingBlock = 1,
|
|
34
|
+
) {
|
|
27
35
|
const lines = stringValue
|
|
28
36
|
.split("\n") // lines
|
|
29
37
|
.map((line) => line.trim()); // remove extra spaces
|
|
30
38
|
const windowTitle = title ? ` ${title} ` : "";
|
|
31
39
|
const windowTitleLength = title ? windowTitle.length : 0;
|
|
32
|
-
const longerContent =
|
|
40
|
+
const longerContent =
|
|
41
|
+
Math.max(...lines.map((l) => l.length)) + paddingInline * 2;
|
|
33
42
|
const longerLine = Math.max(longerContent, windowTitleLength);
|
|
34
|
-
const paddingBlockString = `│${" ".repeat(longerLine)}│\n`.repeat(
|
|
43
|
+
const paddingBlockString = `│${" ".repeat(longerLine)}│\n`.repeat(
|
|
44
|
+
paddingBlock,
|
|
45
|
+
);
|
|
35
46
|
const minWidth = longerLine;
|
|
36
|
-
const borderTop = `╭${windowTitle}${"─".repeat(
|
|
47
|
+
const borderTop = `╭${windowTitle}${"─".repeat(
|
|
48
|
+
minWidth - windowTitleLength,
|
|
49
|
+
)}╮\n`;
|
|
37
50
|
const borderBottom = `╰${"─".repeat(minWidth)}╯`;
|
|
38
51
|
const content = lines
|
|
39
52
|
.map((l) => {
|
|
@@ -42,7 +55,9 @@ function boxLog(stringValue: string, title = "", paddingInline = 1, paddingBlock
|
|
|
42
55
|
})
|
|
43
56
|
.join("");
|
|
44
57
|
|
|
45
|
-
console.log(
|
|
58
|
+
console.log(
|
|
59
|
+
`${borderTop}${paddingBlockString}${content}${paddingBlockString}${borderBottom}`,
|
|
60
|
+
);
|
|
46
61
|
}
|
|
47
62
|
|
|
48
63
|
/**
|
|
@@ -52,7 +67,7 @@ function boxLog(stringValue: string, title = "", paddingInline = 1, paddingBlock
|
|
|
52
67
|
* @param str The string to be logged.
|
|
53
68
|
*/
|
|
54
69
|
function buildLog(str: string) {
|
|
55
|
-
if (GRIDDO_BUILD_LOGS) {
|
|
70
|
+
if (envs.GRIDDO_BUILD_LOGS) {
|
|
56
71
|
console.log(str.replace(/(\s)\s+/g, "$1").trim());
|
|
57
72
|
}
|
|
58
73
|
}
|
|
@@ -62,7 +77,7 @@ function buildLog(str: string) {
|
|
|
62
77
|
* @param str The string to be logged.
|
|
63
78
|
*/
|
|
64
79
|
function infoLog(str: string) {
|
|
65
|
-
console.log(`${
|
|
80
|
+
console.log(`${kleur.blue("info")} ${str}`);
|
|
66
81
|
}
|
|
67
82
|
|
|
68
83
|
/**
|
|
@@ -70,67 +85,99 @@ function infoLog(str: string) {
|
|
|
70
85
|
* @param str The string to be logged.
|
|
71
86
|
*/
|
|
72
87
|
function successLog(str: string) {
|
|
73
|
-
console.log(`${
|
|
88
|
+
console.log(`${kleur.green("success")} ${str}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Internal log
|
|
93
|
+
* @param values The values to be logged.
|
|
94
|
+
*/
|
|
95
|
+
function debugLog(...values: Array<unknown>) {
|
|
96
|
+
if (!envs.GRIDDO_DEBUG_LOGS) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
console.log(...values);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Return a scale size colors with a number and a measure string (KB by default).
|
|
104
|
+
*
|
|
105
|
+
* @param size The page size in KB.
|
|
106
|
+
* @param measure The measure string to be added in the log.
|
|
107
|
+
*/
|
|
108
|
+
function pageSizeLog(size: number, measure = "KB") {
|
|
109
|
+
const sizeScale = {
|
|
110
|
+
low: 50,
|
|
111
|
+
mid: 80,
|
|
112
|
+
large: 130,
|
|
113
|
+
extraLarge: 210,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// Ternary pawa!
|
|
117
|
+
const color =
|
|
118
|
+
size > sizeScale.large
|
|
119
|
+
? "red"
|
|
120
|
+
: size > sizeScale.mid
|
|
121
|
+
? "magenta"
|
|
122
|
+
: size > sizeScale.low
|
|
123
|
+
? "blue"
|
|
124
|
+
: "green";
|
|
125
|
+
|
|
126
|
+
return kleur[color](kleur.bold(`${size}${measure}`));
|
|
74
127
|
}
|
|
75
128
|
|
|
76
129
|
/**
|
|
77
130
|
* Console log the Griddo exporter version.
|
|
78
131
|
*/
|
|
79
|
-
|
|
132
|
+
function showExporterVersion() {
|
|
80
133
|
console.clear();
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
134
|
+
const config = getConfig();
|
|
135
|
+
const { griddoVersion } = config;
|
|
136
|
+
const logo = `\n${kleur
|
|
137
|
+
.bgYellow()
|
|
138
|
+
.black()
|
|
139
|
+
.bold(" Griddo Exporter " + griddoVersion + " ")}\n`;
|
|
85
140
|
|
|
86
141
|
console.log(logo);
|
|
87
142
|
}
|
|
88
143
|
|
|
89
144
|
function listSitesLog(title: string, sites: Array<Site>) {
|
|
90
145
|
const maxline = Math.max(
|
|
91
|
-
...sites.map(
|
|
146
|
+
...sites.map(
|
|
147
|
+
(s) =>
|
|
148
|
+
s.name.length + (s.shouldBeUpdated ? 1 : 0) + s.id.toString().length,
|
|
149
|
+
),
|
|
92
150
|
);
|
|
93
151
|
|
|
94
152
|
const sitesStr = sites.map((s) => {
|
|
95
153
|
const shouldBeUpdated = s.shouldBeUpdated ? "*" : "";
|
|
96
|
-
const lineLen =
|
|
154
|
+
const lineLen =
|
|
155
|
+
s.name.length + shouldBeUpdated.length + s.id.toString().length;
|
|
97
156
|
const padding = " ".repeat(maxline - lineLen);
|
|
98
|
-
return `${
|
|
157
|
+
return `${kleur.bold(s.name)} ${kleur.dim("(" + s.id + ")")} ${shouldBeUpdated} ${padding}${kleur.dim("-")} ${kleur.dim(s.slug)}`;
|
|
99
158
|
});
|
|
100
159
|
|
|
101
|
-
const sitesOutput =
|
|
160
|
+
const sitesOutput =
|
|
161
|
+
sitesStr.length > 0
|
|
162
|
+
? "\n\n" + sitesStr.join("\n")
|
|
163
|
+
: kleur.dim("--none--\n");
|
|
102
164
|
|
|
103
165
|
console.log(`
|
|
104
166
|
${title} ${sitesOutput}`);
|
|
105
167
|
}
|
|
106
168
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const data = await readDB();
|
|
113
|
-
|
|
114
|
-
const logFilePath = path.join(data.paths.root, `render-detail-log.txt`);
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
await fsp.appendFile(logFilePath, `${lineContent.toString()}\n`);
|
|
118
|
-
} catch (error) {
|
|
119
|
-
if (error instanceof Error) {
|
|
120
|
-
console.error("Error", error.message);
|
|
121
|
-
} else {
|
|
122
|
-
console.error(error);
|
|
123
|
-
}
|
|
124
|
-
throw error;
|
|
125
|
-
}
|
|
169
|
+
function errorLabelLog(msg: string) {
|
|
170
|
+
console.error("\n" + kleur.black().bgRed(" " + msg + " ") + "\n");
|
|
126
171
|
}
|
|
127
172
|
|
|
128
173
|
export {
|
|
129
|
-
appendLogToFile,
|
|
130
174
|
boxLog,
|
|
131
175
|
buildLog,
|
|
176
|
+
debugLog,
|
|
177
|
+
errorLabelLog,
|
|
132
178
|
infoLog,
|
|
133
179
|
listSitesLog,
|
|
180
|
+
pageSizeLog,
|
|
134
181
|
showExporterVersion,
|
|
135
182
|
successLog,
|
|
136
183
|
verboseLog,
|
package/exporter/utils/pages.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Core, Fields } from "@griddo/core";
|
|
2
1
|
import type {
|
|
3
2
|
APIPageObject,
|
|
4
3
|
GriddoListPage,
|
|
@@ -10,9 +9,14 @@ import type {
|
|
|
10
9
|
PageAdditionalInfo,
|
|
11
10
|
} from "../types/pages";
|
|
12
11
|
import type { TemplateWithReferenceField } from "../types/templates";
|
|
12
|
+
import type { Core, Fields } from "@griddo/core";
|
|
13
|
+
|
|
14
|
+
import dotenv from "dotenv";
|
|
13
15
|
|
|
14
16
|
import { formatImage } from "./images";
|
|
15
17
|
|
|
18
|
+
dotenv.config();
|
|
19
|
+
|
|
16
20
|
// Consts
|
|
17
21
|
const DEFAULT_ITEMS_PER_PAGE_FOR_LIST_TEMPLATES = 25;
|
|
18
22
|
|
|
@@ -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 = (
|
|
@@ -339,10 +391,11 @@ function getMultiPageElements(page: TemplateWithReferenceField): Promise<MultiPa
|
|
|
339
391
|
hasGriddoMultiPage: boolean;
|
|
340
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: Array<Fields.QueriedDataItem>, pag
|
|
|
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: Array<Fields.QueriedDataIte
|
|
|
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
|
/**
|