@griddo/cx 10.4.28 → 10.4.30
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/build/index.d.ts +2 -2
- package/build/index.js +30 -27
- package/build/react/GriddoIntegrations/index.d.ts +12 -0
- package/build/react/index.d.ts +2 -2
- package/build/react/index.js +3 -1
- package/build/run-start-render.js +30 -27
- package/build/start-render.js +30 -27
- package/build/types/global.d.ts +1 -1
- package/build/types/pages.d.ts +6 -0
- package/build/utils/integrations.d.ts +26 -0
- package/exporter/adapters/gatsby/index.ts +25 -1
- package/exporter/index.ts +2 -1
- package/exporter/react/GriddoIntegrations/index.tsx +131 -0
- package/exporter/react/index.tsx +2 -2
- package/exporter/start-render.ts +7 -6
- package/exporter/types/global.ts +1 -0
- package/exporter/types/pages.ts +7 -0
- package/exporter/utils/integrations.ts +110 -0
- package/package.json +3 -3
- package/src/components/Head.tsx +18 -64
- package/src/components/template.tsx +11 -19
- package/src/types.ts +2 -14
- package/src/utils.ts +3 -72
- package/build/react/Foo/index.d.ts +0 -3
- package/exporter/react/Foo/index.tsx +0 -7
package/build/types/global.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ interface RenderInfo {
|
|
|
61
61
|
createdPages: Array<number>;
|
|
62
62
|
sitesToPublish: Array<Site>;
|
|
63
63
|
}
|
|
64
|
-
type LifeCyclesNames = "Prepare" | "Restore" | "Data" | "SSG" | "Relocation" | "Meta" | "Archive" | "Clean" | "__DEBUG__";
|
|
64
|
+
type LifeCyclesNames = "Prepare" | "Restore" | "Data" | "SSG" | "Relocation" | "Meta" | "Archive" | "Clean" | "HealthCheck" | "__DEBUG__";
|
|
65
65
|
type CXDir = "__exports" | "__caches" | "__cx" | "__ssg" | "__components" | "__root";
|
|
66
66
|
interface CXConfig {
|
|
67
67
|
proDomain: string;
|
package/build/types/pages.d.ts
CHANGED
|
@@ -126,3 +126,9 @@ export type GriddoPageObject = {
|
|
|
126
126
|
page: GriddoSinglePage | GriddoListPage | GriddoMultiPage;
|
|
127
127
|
};
|
|
128
128
|
};
|
|
129
|
+
export interface Dimensions {
|
|
130
|
+
values: Record<string, string> | null;
|
|
131
|
+
contentSelect?: "group" | "individual" | null;
|
|
132
|
+
groupSelect?: string;
|
|
133
|
+
dimensionsSelect?: Array<string>;
|
|
134
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Dimensions } from "../types/pages";
|
|
2
|
+
import type { Core } from "@griddo/core";
|
|
3
|
+
declare function filterBodyIntegrationFromPosition(integrations: Array<Core.PageIntegration>, position: "start" | "end"): {
|
|
4
|
+
content: string;
|
|
5
|
+
type: "addon" | "analytics" | "datalayer";
|
|
6
|
+
}[];
|
|
7
|
+
declare function filterHeadIntegrations(integrations: Array<Core.PageIntegration>): {
|
|
8
|
+
content: string;
|
|
9
|
+
type: "addon" | "analytics" | "datalayer";
|
|
10
|
+
}[];
|
|
11
|
+
export declare const filterPositionIntegrations: (integrations: Array<Core.PageIntegration>, position: "head" | "start" | "end") => {
|
|
12
|
+
content: string;
|
|
13
|
+
type: "addon" | "analytics" | "datalayer";
|
|
14
|
+
}[];
|
|
15
|
+
export declare function composeAnalytics(siteScriptRaw?: string, dimensions?: Dimensions, page?: {
|
|
16
|
+
pageContext: {
|
|
17
|
+
siteScript: string;
|
|
18
|
+
page: {
|
|
19
|
+
dimensions: Dimensions;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}, generateAutomaticDimensions?: (page: Record<string, unknown>) => null): {
|
|
23
|
+
analyticsScript: string;
|
|
24
|
+
analyticsDimensions: string | null;
|
|
25
|
+
};
|
|
26
|
+
export { filterBodyIntegrationFromPosition, filterHeadIntegrations };
|
|
@@ -28,11 +28,16 @@ import {
|
|
|
28
28
|
} from "../../utils/folders";
|
|
29
29
|
import { generateBuildReport, generateSitemaps } from "../../utils/sites";
|
|
30
30
|
|
|
31
|
+
const config = getConfig();
|
|
32
|
+
const { __cx } = config.paths();
|
|
33
|
+
const renderSentinelFile = path.join(__cx, ".render-sentinel");
|
|
34
|
+
|
|
31
35
|
async function runGatsbyAdapter() {
|
|
32
36
|
printExporterLogo("gatsby");
|
|
33
37
|
|
|
38
|
+
fs.writeFileSync(renderSentinelFile, new Date().toISOString());
|
|
39
|
+
|
|
34
40
|
const domains = await getInstanceDomains();
|
|
35
|
-
const config = getConfig();
|
|
36
41
|
|
|
37
42
|
for (const domain of domains) {
|
|
38
43
|
const { __ssg, __exports, __caches, __cx, __components } = config.paths(
|
|
@@ -240,6 +245,25 @@ async function runGatsbyAdapter() {
|
|
|
240
245
|
() => pause("Clean LifeCycle"),
|
|
241
246
|
],
|
|
242
247
|
});
|
|
248
|
+
|
|
249
|
+
await doLifeCycle({
|
|
250
|
+
name: "HealthCheck",
|
|
251
|
+
attempts: 1,
|
|
252
|
+
steps: [
|
|
253
|
+
() => {
|
|
254
|
+
if (!fs.existsSync(renderSentinelFile)) {
|
|
255
|
+
logBox(
|
|
256
|
+
`Something has happened and the rendering uuid cannot be read safely.
|
|
257
|
+
There was probably a instance deployment during the render and files were deleted.
|
|
258
|
+
|
|
259
|
+
The files generated in this render will not be published.`,
|
|
260
|
+
"Render UUID error"
|
|
261
|
+
);
|
|
262
|
+
throw new Error("Render sentinel file does not exist.");
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
});
|
|
243
267
|
}
|
|
244
268
|
}
|
|
245
269
|
|
package/exporter/index.ts
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
/* prettier-ignore */ import type { SocialsResponse } from "./types/api";
|
|
23
|
-
/* prettier-ignore */ import type { AdditionalInfo, GriddoListPage, GriddoMultiPage, GriddoPageObject, GriddoSinglePage
|
|
23
|
+
/* prettier-ignore */ import type { AdditionalInfo, Dimensions, GriddoListPage, GriddoMultiPage, GriddoPageObject, GriddoSinglePage } from "./types/pages";
|
|
24
24
|
/* prettier-ignore */ import type { Site } from "./types/sites";
|
|
25
25
|
|
|
26
26
|
/* prettier-ignore */ import { startRender } from "./start-render";
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
export {
|
|
32
32
|
AdditionalInfo,
|
|
33
|
+
Dimensions,
|
|
33
34
|
GriddoListPage,
|
|
34
35
|
GriddoMultiPage,
|
|
35
36
|
GriddoPageObject,
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { Dimensions } from "../../types/pages";
|
|
2
|
+
import type { Core } from "@griddo/core";
|
|
3
|
+
|
|
4
|
+
import { generateAutomaticDimensions } from "@griddo-instance";
|
|
5
|
+
import parse from "html-react-parser";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
composeAnalytics,
|
|
10
|
+
filterBodyIntegrationFromPosition,
|
|
11
|
+
filterHeadIntegrations,
|
|
12
|
+
} from "../../utils/integrations";
|
|
13
|
+
|
|
14
|
+
export interface GriddoIntegrationsProps {
|
|
15
|
+
integrations?: Array<Core.PageIntegration>;
|
|
16
|
+
location: "head" | "start-body" | "end-body";
|
|
17
|
+
id?: string;
|
|
18
|
+
analyticScript?: string;
|
|
19
|
+
dimensions?: Dimensions;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function GriddoIntegrations(props: GriddoIntegrationsProps) {
|
|
23
|
+
const {
|
|
24
|
+
integrations: maybeIntegrations,
|
|
25
|
+
location,
|
|
26
|
+
id,
|
|
27
|
+
analyticScript: siteScript,
|
|
28
|
+
dimensions,
|
|
29
|
+
} = props;
|
|
30
|
+
|
|
31
|
+
const integrations = maybeIntegrations || [];
|
|
32
|
+
|
|
33
|
+
// GTM y DATALAYER van siempre en "head"
|
|
34
|
+
const integrationsGroupedBy = {
|
|
35
|
+
head: filterHeadIntegrations(integrations),
|
|
36
|
+
"start-body": filterBodyIntegrationFromPosition(integrations, "start"),
|
|
37
|
+
"end-body": filterBodyIntegrationFromPosition(integrations, "end"),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const ints = integrationsGroupedBy[location];
|
|
41
|
+
|
|
42
|
+
// Analytics GTM + Dimensions
|
|
43
|
+
const emptyCodeScript = { props: { dangerouslySetInnerHTML: {} } };
|
|
44
|
+
|
|
45
|
+
const { analyticsScript, analyticsDimensions } = composeAnalytics(
|
|
46
|
+
siteScript,
|
|
47
|
+
dimensions,
|
|
48
|
+
generateAutomaticDimensions,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const analyticsScriptSrc =
|
|
52
|
+
(analyticsScript &&
|
|
53
|
+
analyticsScript.startsWith("UA-") &&
|
|
54
|
+
`https://www.googletagmanager.com/gtag/js?id=${analyticsScript}`) ||
|
|
55
|
+
null;
|
|
56
|
+
|
|
57
|
+
// <script.../> parseado (jsx) || emptyCodeScript
|
|
58
|
+
const analyticsCodeSnippet =
|
|
59
|
+
analyticsScript &&
|
|
60
|
+
!analyticsScriptSrc &&
|
|
61
|
+
analyticsScript.includes("<script")
|
|
62
|
+
? parse(analyticsScript, { trim: true })
|
|
63
|
+
: emptyCodeScript;
|
|
64
|
+
|
|
65
|
+
// Este "fix" parece que evita errores si `analyticsCodeSnippet` es un
|
|
66
|
+
// array. ¿Puede que sea si el usuario mete más de un script en la caja de
|
|
67
|
+
// AX?
|
|
68
|
+
const fixedAnalyticsCode = Array.isArray(analyticsCodeSnippet)
|
|
69
|
+
? analyticsCodeSnippet.find((item) => item.type === "script") ||
|
|
70
|
+
emptyCodeScript
|
|
71
|
+
: analyticsCodeSnippet;
|
|
72
|
+
|
|
73
|
+
const {
|
|
74
|
+
props: {
|
|
75
|
+
dangerouslySetInnerHTML: { __html: analyticsScriptCode },
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
77
|
+
children: analyticsScriptChildren,
|
|
78
|
+
...analyticsScriptProps
|
|
79
|
+
},
|
|
80
|
+
} = fixedAnalyticsCode as {
|
|
81
|
+
props: {
|
|
82
|
+
dangerouslySetInnerHTML: { __html: React.ReactNode };
|
|
83
|
+
children: unknown;
|
|
84
|
+
src: string;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<>
|
|
90
|
+
{ints?.map((integration, key) => {
|
|
91
|
+
/* Data Layer */
|
|
92
|
+
if (integration.type === "datalayer") {
|
|
93
|
+
return (
|
|
94
|
+
<React.Fragment key={key}>
|
|
95
|
+
<script>{"window.dataLayer = window.dataLayer || [];"}</script>
|
|
96
|
+
{analyticsDimensions && (
|
|
97
|
+
<script>{`try{const {__HIDDEN, ...newDataLayer} = ${analyticsDimensions};newDataLayer && Object.keys(newDataLayer).length > 0 && window.dataLayer && window.dataLayer.push(newDataLayer);}catch{}`}</script>
|
|
98
|
+
)}
|
|
99
|
+
</React.Fragment>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (integration.type === "analytics") {
|
|
104
|
+
return (
|
|
105
|
+
<React.Fragment key={key}>
|
|
106
|
+
{/* Analytics with UA- */}
|
|
107
|
+
{analyticsScriptSrc && (
|
|
108
|
+
<script key={key} src={analyticsScriptSrc}></script>
|
|
109
|
+
)}
|
|
110
|
+
{/* Analytics with js snippet */}
|
|
111
|
+
{(analyticsScriptProps?.src || analyticsScriptCode) && (
|
|
112
|
+
<script {...analyticsScriptProps} data-griddo-id={id}>
|
|
113
|
+
{analyticsScriptCode}
|
|
114
|
+
</script>
|
|
115
|
+
)}
|
|
116
|
+
</React.Fragment>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* Integration integration.type === "addon" */
|
|
121
|
+
if (integration.type === "addon") {
|
|
122
|
+
return parse(integration.content, { trim: true });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return null;
|
|
126
|
+
})}
|
|
127
|
+
</>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { GriddoIntegrations };
|
package/exporter/react/index.tsx
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { GriddoIntegrations } from "./GriddoIntegrations";
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { GriddoIntegrations };
|
package/exporter/start-render.ts
CHANGED
|
@@ -5,14 +5,15 @@ import { runGatsbyAdapter } from "./adapters";
|
|
|
5
5
|
import { logBox, measureExecutionTime } from "./utils/core-utils";
|
|
6
6
|
|
|
7
7
|
async function startRender() {
|
|
8
|
-
|
|
8
|
+
try {
|
|
9
|
+
const exeTime = await measureExecutionTime(runGatsbyAdapter);
|
|
10
|
+
logBox(`All domains rendered in ${exeTime}s.`, "", 1, 0);
|
|
11
|
+
process.exit(0);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
console.log(error);
|
|
9
14
|
console.log("<[ Render will be reset ]>");
|
|
10
15
|
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
logBox(`All domains rendered in ${exeTime}s.`, "", 1, 0);
|
|
14
|
-
|
|
15
|
-
process.exit(0);
|
|
16
|
+
}
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export { startRender };
|
package/exporter/types/global.ts
CHANGED
package/exporter/types/pages.ts
CHANGED
|
@@ -157,3 +157,10 @@ export type GriddoPageObject = {
|
|
|
157
157
|
page: GriddoSinglePage | GriddoListPage | GriddoMultiPage;
|
|
158
158
|
};
|
|
159
159
|
};
|
|
160
|
+
|
|
161
|
+
export interface Dimensions {
|
|
162
|
+
values: Record<string, string> | null;
|
|
163
|
+
contentSelect?: "group" | "individual" | null;
|
|
164
|
+
groupSelect?: string;
|
|
165
|
+
dimensionsSelect?: Array<string>;
|
|
166
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Dimensions } from "../types/pages";
|
|
2
|
+
import type { Core } from "@griddo/core";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Return true if the argument is an object (not null)
|
|
6
|
+
*/
|
|
7
|
+
function isObject(value: unknown) {
|
|
8
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function filterBodyIntegrationFromPosition(
|
|
12
|
+
integrations: Array<Core.PageIntegration>,
|
|
13
|
+
position: "start" | "end"
|
|
14
|
+
) {
|
|
15
|
+
return (
|
|
16
|
+
integrations
|
|
17
|
+
?.filter(
|
|
18
|
+
(integration) =>
|
|
19
|
+
integration.contentBody !== null &&
|
|
20
|
+
integration.contentBody !== "" &&
|
|
21
|
+
integration.contentBodyPosition === position
|
|
22
|
+
)
|
|
23
|
+
.map((integration) => {
|
|
24
|
+
return { content: integration.contentBody!, type: integration.type };
|
|
25
|
+
}) || []
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function filterHeadIntegrations(integrations: Array<Core.PageIntegration>) {
|
|
30
|
+
return integrations
|
|
31
|
+
?.filter(
|
|
32
|
+
(integration) =>
|
|
33
|
+
integration.contentHead !== null && integration.contentHead !== ""
|
|
34
|
+
)
|
|
35
|
+
.map((integration) => {
|
|
36
|
+
return {
|
|
37
|
+
content: integration.contentHead!,
|
|
38
|
+
type: integration.type,
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const filterPositionIntegrations = (
|
|
44
|
+
integrations: Array<Core.PageIntegration>,
|
|
45
|
+
position: "head" | "start" | "end"
|
|
46
|
+
) => {
|
|
47
|
+
switch (position) {
|
|
48
|
+
case "head":
|
|
49
|
+
return filterHeadIntegrations(integrations);
|
|
50
|
+
default:
|
|
51
|
+
return filterBodyIntegrationFromPosition(integrations, position);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export function composeAnalytics(
|
|
56
|
+
siteScriptRaw?: string,
|
|
57
|
+
dimensions?: Dimensions,
|
|
58
|
+
page?: {
|
|
59
|
+
pageContext: {
|
|
60
|
+
siteScript: string;
|
|
61
|
+
page: {
|
|
62
|
+
dimensions: Dimensions;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
67
|
+
generateAutomaticDimensions = (page: Record<string, unknown>) => null
|
|
68
|
+
) {
|
|
69
|
+
const analyticsScript = siteScriptRaw ? siteScriptRaw.trim() : "";
|
|
70
|
+
|
|
71
|
+
// Las dimensiones o DataLayer
|
|
72
|
+
const dynamicValuePrefix = "__SCRIPT:";
|
|
73
|
+
const dimensionValues = isObject(dimensions?.values)
|
|
74
|
+
? dimensions?.values
|
|
75
|
+
: {};
|
|
76
|
+
const automaticDimensionValues = generateAutomaticDimensions
|
|
77
|
+
? generateAutomaticDimensions(page || {})
|
|
78
|
+
: {};
|
|
79
|
+
const allDimensionsValues = {
|
|
80
|
+
...dimensionValues,
|
|
81
|
+
...automaticDimensionValues,
|
|
82
|
+
} as Record<string, string>;
|
|
83
|
+
|
|
84
|
+
const allDimensions = [];
|
|
85
|
+
|
|
86
|
+
for (const dimension of Object.keys(allDimensionsValues)) {
|
|
87
|
+
const dimensionValue = allDimensionsValues[dimension];
|
|
88
|
+
allDimensions.push(
|
|
89
|
+
`"${dimension}":${
|
|
90
|
+
dimensionValue?.startsWith(dynamicValuePrefix)
|
|
91
|
+
? `${dimensionValue.slice(
|
|
92
|
+
dynamicValuePrefix.length,
|
|
93
|
+
dimensionValue.endsWith(";") ? -1 : dimensionValue.length
|
|
94
|
+
)}`
|
|
95
|
+
: `"${dimensionValue}"`
|
|
96
|
+
}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const analyticsDimensions = allDimensions.length
|
|
101
|
+
? `{${allDimensions.join(",")}}`
|
|
102
|
+
: null;
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
analyticsScript,
|
|
106
|
+
analyticsDimensions,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { filterBodyIntegrationFromPosition, filterHeadIntegrations };
|
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.4.
|
|
4
|
+
"version": "10.4.30",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Diego M. Béjar <diego.bejar@secuoyas.com>",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@babel/preset-env": "^7.14.5",
|
|
49
49
|
"@babel/preset-react": "^7.14.5",
|
|
50
50
|
"@babel/preset-typescript": "^7.16.5",
|
|
51
|
-
"@griddo/core": "10.4.
|
|
51
|
+
"@griddo/core": "10.4.30",
|
|
52
52
|
"@svgr/webpack": "^5.5.0",
|
|
53
53
|
"babel-loader": "^8.0.6",
|
|
54
54
|
"babel-plugin-transform-runtime": "^6.23.0",
|
|
@@ -119,5 +119,5 @@
|
|
|
119
119
|
"publishConfig": {
|
|
120
120
|
"access": "public"
|
|
121
121
|
},
|
|
122
|
-
"gitHead": "
|
|
122
|
+
"gitHead": "b9de29bad583d1e4f40f614cab7f3944d3f057f6"
|
|
123
123
|
}
|
package/src/components/Head.tsx
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { CustomHeadProps } from "../types";
|
|
2
2
|
|
|
3
|
-
import { generateAutomaticDimensions } from "@griddo-instance";
|
|
4
|
-
import parse from "html-react-parser";
|
|
5
3
|
import * as React from "react";
|
|
6
4
|
|
|
7
|
-
import {
|
|
8
|
-
import { cleanCommaSeparated,
|
|
5
|
+
import { GriddoIntegrations } from "../../build/react";
|
|
6
|
+
import { cleanCommaSeparated, formatImage } from "../utils";
|
|
7
|
+
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Gatsby Head API
|
|
@@ -18,10 +17,17 @@ const Head = (props: CustomHeadProps) => {
|
|
|
18
17
|
renderDate,
|
|
19
18
|
locale,
|
|
20
19
|
openGraph,
|
|
21
|
-
page: {
|
|
20
|
+
page: {
|
|
21
|
+
disableHrefLangs,
|
|
22
|
+
fullUrl,
|
|
23
|
+
defaultLang,
|
|
24
|
+
integrations = [],
|
|
25
|
+
dimensions,
|
|
26
|
+
},
|
|
22
27
|
pageMetadata,
|
|
23
28
|
siteMetadata,
|
|
24
29
|
siteOptions,
|
|
30
|
+
siteScript,
|
|
25
31
|
},
|
|
26
32
|
} = props;
|
|
27
33
|
|
|
@@ -33,45 +39,6 @@ const Head = (props: CustomHeadProps) => {
|
|
|
33
39
|
!!metaRobots &&
|
|
34
40
|
(siteOptions?.showBasicMetaRobots || metaRobots !== "index,follow");
|
|
35
41
|
|
|
36
|
-
const { analyticsScript, analyticsDimensions } = composeAnalytics(
|
|
37
|
-
props,
|
|
38
|
-
generateAutomaticDimensions
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const emptyCodeScript = { props: { dangerouslySetInnerHTML: {} } };
|
|
42
|
-
|
|
43
|
-
const analyticsSrc =
|
|
44
|
-
(analyticsScript &&
|
|
45
|
-
analyticsScript.startsWith("UA-") &&
|
|
46
|
-
`https://www.googletagmanager.com/gtag/js?id=${analyticsScript}`) ||
|
|
47
|
-
null;
|
|
48
|
-
|
|
49
|
-
const analyticsCode =
|
|
50
|
-
analyticsScript && !analyticsSrc && analyticsScript.includes("<script")
|
|
51
|
-
? parse(analyticsScript)
|
|
52
|
-
: emptyCodeScript;
|
|
53
|
-
|
|
54
|
-
const fixedAnalyticsCode = Array.isArray(analyticsCode)
|
|
55
|
-
? analyticsCode.find((item) => item.type === "script") || emptyCodeScript
|
|
56
|
-
: analyticsCode;
|
|
57
|
-
|
|
58
|
-
const {
|
|
59
|
-
// TODO: Type this correctly
|
|
60
|
-
props: {
|
|
61
|
-
dangerouslySetInnerHTML: { __html: analyticsScriptCode },
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
63
|
-
children: analyticsScriptChildren,
|
|
64
|
-
...analyticsScriptProps
|
|
65
|
-
},
|
|
66
|
-
} = fixedAnalyticsCode as {
|
|
67
|
-
// TODO: Fix this custom inline weird type
|
|
68
|
-
props: {
|
|
69
|
-
dangerouslySetInnerHTML: { __html: React.ReactNode };
|
|
70
|
-
children: unknown;
|
|
71
|
-
src: string;
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
|
|
75
42
|
// Resize favicon
|
|
76
43
|
const faviconResized = formatImage(siteMetadata?.favicon, 32, 32, "png");
|
|
77
44
|
|
|
@@ -105,8 +72,6 @@ const Head = (props: CustomHeadProps) => {
|
|
|
105
72
|
?.url) ||
|
|
106
73
|
null;
|
|
107
74
|
|
|
108
|
-
const headIntegrations = filterHeadIntegrations(integrations);
|
|
109
|
-
|
|
110
75
|
return (
|
|
111
76
|
<>
|
|
112
77
|
{/* Uncomment with Gatsby 5.5.0 */}
|
|
@@ -184,24 +149,13 @@ const Head = (props: CustomHeadProps) => {
|
|
|
184
149
|
<meta name="keywords" content={pageMetadata.metaKeywords} />
|
|
185
150
|
)}
|
|
186
151
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
{analyticsSrc && <script src={analyticsSrc}></script>}
|
|
195
|
-
|
|
196
|
-
{/* {analyticsCode} */}
|
|
197
|
-
{(analyticsScriptProps?.src || analyticsScriptCode) && (
|
|
198
|
-
<script {...analyticsScriptProps} data-griddo-id={fullUrl}>
|
|
199
|
-
{analyticsScriptCode}
|
|
200
|
-
</script>
|
|
201
|
-
)}
|
|
202
|
-
|
|
203
|
-
{headIntegrations &&
|
|
204
|
-
headIntegrations.map((integrationBody) => parse(integrationBody))}
|
|
152
|
+
<GriddoIntegrations
|
|
153
|
+
id={fullUrl}
|
|
154
|
+
location="head"
|
|
155
|
+
integrations={integrations}
|
|
156
|
+
dimensions={dimensions}
|
|
157
|
+
analyticScript={siteScript}
|
|
158
|
+
/>
|
|
205
159
|
</>
|
|
206
160
|
);
|
|
207
161
|
};
|
|
@@ -4,11 +4,10 @@ import type { Core } from "@griddo/core";
|
|
|
4
4
|
import { Page as RenderGriddoPage } from "@griddo/core";
|
|
5
5
|
import { components, SiteProvider, templates } from "@griddo-instance";
|
|
6
6
|
import { Link, navigate } from "gatsby";
|
|
7
|
-
import parse from "html-react-parser";
|
|
8
7
|
import * as React from "react";
|
|
9
8
|
import { Helmet } from "react-helmet";
|
|
10
9
|
|
|
11
|
-
import {
|
|
10
|
+
import { GriddoIntegrations } from "../../build/react";
|
|
12
11
|
|
|
13
12
|
// Gatsby Head
|
|
14
13
|
export { Head } from "./Head";
|
|
@@ -36,15 +35,6 @@ const Template = (data: TemplateProps) => {
|
|
|
36
35
|
const header = data.pageContext.header as Core.HeaderModule;
|
|
37
36
|
const footer = data.pageContext.footer as Core.FooterModule;
|
|
38
37
|
|
|
39
|
-
const integrationsPreBody = filterPositionIntegrations(
|
|
40
|
-
page.integrations || [],
|
|
41
|
-
"start"
|
|
42
|
-
);
|
|
43
|
-
const integrationsPostBody = filterPositionIntegrations(
|
|
44
|
-
page.integrations || [],
|
|
45
|
-
"end"
|
|
46
|
-
);
|
|
47
|
-
|
|
48
38
|
return (
|
|
49
39
|
<SiteProvider
|
|
50
40
|
apiUrl={page.apiUrl}
|
|
@@ -70,11 +60,12 @@ const Template = (data: TemplateProps) => {
|
|
|
70
60
|
<html lang={locale} />
|
|
71
61
|
</Helmet>
|
|
72
62
|
|
|
63
|
+
<GriddoIntegrations
|
|
64
|
+
location="start-body"
|
|
65
|
+
integrations={page.integrations}
|
|
66
|
+
/>
|
|
67
|
+
|
|
73
68
|
{/* Render every page */}
|
|
74
|
-
{integrationsPreBody &&
|
|
75
|
-
integrationsPreBody.map((integrationBody) =>
|
|
76
|
-
parse(integrationBody, { trim: true })
|
|
77
|
-
)}
|
|
78
69
|
<RenderGriddoPage
|
|
79
70
|
apiUrl={page.apiUrl}
|
|
80
71
|
content={page}
|
|
@@ -84,10 +75,11 @@ const Template = (data: TemplateProps) => {
|
|
|
84
75
|
library={library}
|
|
85
76
|
pageLanguages={page.pageLanguages}
|
|
86
77
|
/>
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
|
|
79
|
+
<GriddoIntegrations
|
|
80
|
+
location="end-body"
|
|
81
|
+
integrations={page.integrations}
|
|
82
|
+
/>
|
|
91
83
|
</SiteProvider>
|
|
92
84
|
);
|
|
93
85
|
};
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AdditionalInfo,
|
|
3
|
+
Dimensions,
|
|
3
4
|
GriddoListPage,
|
|
4
5
|
GriddoMultiPage,
|
|
5
6
|
GriddoPageObject,
|
|
@@ -40,13 +41,6 @@ interface HtmlProps {
|
|
|
40
41
|
preBodyComponents: React.ReactNode;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
interface Dimensions {
|
|
44
|
-
values: Record<string, string> | null;
|
|
45
|
-
contentSelect?: "group" | "individual" | null;
|
|
46
|
-
groupSelect?: string;
|
|
47
|
-
dimensionsSelect?: Array<string>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
44
|
// TODO: JSDoc
|
|
51
45
|
type GatsbyPageObject = {
|
|
52
46
|
matchPath?: string;
|
|
@@ -96,10 +90,4 @@ type GatsbyPageObject = {
|
|
|
96
90
|
};
|
|
97
91
|
};
|
|
98
92
|
|
|
99
|
-
export {
|
|
100
|
-
CustomHeadProps,
|
|
101
|
-
Dimensions,
|
|
102
|
-
GatsbyPageObject,
|
|
103
|
-
HtmlProps,
|
|
104
|
-
TemplateProps,
|
|
105
|
-
};
|
|
93
|
+
export { CustomHeadProps, GatsbyPageObject, HtmlProps, TemplateProps };
|