@griddo/cx 10.7.3 → 10.7.4

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.
@@ -0,0 +1,12 @@
1
+ import type { Fields } from "@griddo/core";
2
+ /**
3
+ * Format Cloudinary or DAM URL
4
+ *
5
+ * @param image The image url
6
+ * @param width With of the image
7
+ * @param height Height of the image
8
+ * @param format Format of the image
9
+ * @returns A composed URL for the Cloudinary or DAM service
10
+ */
11
+ declare function formatImage(image: Fields.Image | string, width: number, height: number, format?: string): string | null;
12
+ export { formatImage };
@@ -1,6 +1,6 @@
1
+ import type { Fields } from "@griddo/core";
1
2
  import type { GriddoListPage, GriddoMultiPage, GriddoPageObject, GriddoSinglePage, MultiPageElements, PageAdditionalInfo } from "../types/pages";
2
3
  import type { TemplateWithDistributor } from "../types/templates";
3
- import type { Fields } from "@griddo/core";
4
4
  /**
5
5
  * Create a single Griddo page object.
6
6
  *
@@ -1,5 +1,3 @@
1
- import type { Fields } from "@griddo/core";
2
-
3
1
  import { spawnSync } from "node:child_process";
4
2
  import path from "node:path";
5
3
 
@@ -42,56 +40,6 @@ function getGatsbyAssetPrefixWithDomain(domain: string) {
42
40
  return assetPrefixWithDomain;
43
41
  }
44
42
 
45
- /**
46
- * Format Cloudinary or DAM URL
47
- *
48
- * @param image The image url
49
- * @param width With of the image
50
- * @param height Height of the image
51
- * @param format Format of the image
52
- * @returns A composed URL for the Cloudinary or DAM service
53
- */
54
- function formatImage(
55
- image: Fields.Image | string,
56
- width: number,
57
- height: number,
58
- format = "jpg",
59
- ) {
60
- const url = typeof image === "string" ? image : image?.url;
61
-
62
- if (!url) {
63
- return null;
64
- }
65
-
66
- const isCloudinary = url.split("/")[2].includes("cloudinary.com");
67
-
68
- return isCloudinary
69
- ? addCloudinaryParams(url, `c_fill,w_${width},h_${height}`)
70
- : addGriddoDamParams(url, `f/${format}/w/${width}/h/${height}`);
71
- }
72
-
73
- /**
74
- * Format Griddo DAM image url.
75
- */
76
- function addGriddoDamParams(image: string, params: string) {
77
- const urlParts = image.split("/");
78
- const imagePath = urlParts.slice(0, -1).join("/");
79
- const imageName = urlParts.slice(-1)[0];
80
-
81
- return `${imagePath}/${params}/${imageName}`;
82
- }
83
-
84
- /**
85
- * Take a cloudinary url and add query params.
86
- */
87
- function addCloudinaryParams(image: string, params: string) {
88
- const plainUrl = image.replace("https://", "");
89
- const head = plainUrl.split("/").slice(0, 4).join("/");
90
- const fullId = plainUrl.replace(head, "");
91
-
92
- return `https://${head}/${params}${fullId}`;
93
- }
94
-
95
43
  /**
96
44
  * Spawn a new node process `yarn gatsby-build`
97
45
  * @note This proccess (`yarn gatsby-build`) can not access to the custom Griddo
@@ -191,7 +139,6 @@ async function legacy__createDistFromGatsbyPublic(
191
139
  }
192
140
 
193
141
  export {
194
- formatImage,
195
142
  getGatsbyAssetPrefixWithDomain,
196
143
  legacy__createDistFromGatsbyPublic,
197
144
  runGatsbyBuildCommand,
package/exporter/index.ts CHANGED
@@ -5,13 +5,10 @@
5
5
  * This file exports functions to use in both: adapters and SSG's frameworks.
6
6
  * Turning CX basically in a javascript library.
7
7
  *
8
- * # Browser context.
9
- * There is another export in the `/browser` directory to use exclusivelly in
8
+ * # React
9
+ * There is another export in the `/react` directory to use exclusivelly in
10
10
  * the browser context where nodejs (path, fs, etc..) is not available.
11
11
  *
12
- * # Render script (bin)
13
- * The binary file of the package is `run-start-render.ts`.
14
- *
15
12
  * # Separate scripts.
16
13
  * There are some separate .ts files as build-complete.ts or reset-render.ts
17
14
  * that are intended to be used by infra via npm script like `npm run
@@ -0,0 +1,37 @@
1
+ import * as React from "react";
2
+ import { formatImage } from "./utils";
3
+
4
+ function Favicon({ url }: { url: string | undefined }) {
5
+ if (!url) {
6
+ return null;
7
+ }
8
+
9
+ return (
10
+ <>
11
+ <link
12
+ rel="icon"
13
+ type="image/png"
14
+ sizes="48x48"
15
+ href={formatImage(url, { width: 48, height: 48, format: "png" })}
16
+ />
17
+ <link
18
+ rel="icon"
19
+ type="image/png"
20
+ sizes="192x192"
21
+ href={formatImage(url, { width: 192, height: 192, format: "png" })}
22
+ />
23
+ <link
24
+ rel="apple-touch-icon"
25
+ sizes="180x180"
26
+ href={formatImage(url, { width: 180, height: 180, format: "png" })}
27
+ />
28
+ <link
29
+ rel="icon"
30
+ type="image/svg+xml"
31
+ href={formatImage(url, { format: "svg" })}
32
+ />
33
+ </>
34
+ );
35
+ }
36
+
37
+ export { Favicon };
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Format Cloudinary or DAM URL
3
+ */
4
+ function formatImage(
5
+ url: string,
6
+ options?: {
7
+ format?: string;
8
+ width?: number;
9
+ height?: number;
10
+ },
11
+ ) {
12
+ const { format, height, width } = options || {};
13
+
14
+ if (!url) {
15
+ return "";
16
+ }
17
+
18
+ const isCloudinary = url.split("/")[2].includes("cloudinary.com");
19
+ const isDAM = !isCloudinary;
20
+
21
+ if (isCloudinary) {
22
+ const _w = width ? `,w_${width}` : "";
23
+ const _h = height ? `,h_${height}` : "";
24
+
25
+ return addCloudinaryParams(url, `c_fill${_w}${_h}`);
26
+ }
27
+
28
+ if (isDAM) {
29
+ const _w = width ? `/w/${width}` : "";
30
+ const _h = height ? `/h/${height}` : "";
31
+
32
+ return addGriddoDamParams(url, `f/${format}${_w}${_h}`);
33
+ }
34
+
35
+ return "";
36
+ }
37
+
38
+ /**
39
+ * Format Griddo DAM image url.
40
+ */
41
+ function addGriddoDamParams(url: string, params: string) {
42
+ const urlParts = url.split("/");
43
+ const urlWithoutImageName = urlParts.slice(0, -1).join("/");
44
+ const imageName = urlParts.slice(-1)[0];
45
+
46
+ return `${urlWithoutImageName}/${params}/${imageName}`;
47
+ }
48
+
49
+ /**
50
+ * Take a cloudinary url and add query params.
51
+ */
52
+ function addCloudinaryParams(image: string, params: string) {
53
+ const plainUrl = image.replace("https://", "");
54
+ const head = plainUrl.split("/").slice(0, 4).join("/");
55
+ const fullId = plainUrl.replace(head, "");
56
+
57
+ return `https://${head}/${params}${fullId}`;
58
+ }
59
+
60
+ export { formatImage };
@@ -1,15 +1,14 @@
1
- import type { Dimensions } from "../../types/pages";
2
1
  import type { Core } from "@griddo/core";
2
+ import type { Dimensions } from "../../types/pages";
3
3
 
4
4
  import { generateAutomaticDimensions } from "@griddo-instance";
5
5
  import parse from "html-react-parser";
6
6
  import * as React from "react";
7
-
8
7
  import {
9
8
  composeAnalytics,
10
9
  filterBodyIntegrationFromPosition,
11
10
  filterHeadIntegrations,
12
- } from "../../utils/integrations";
11
+ } from "./utils";
13
12
 
14
13
  export interface GriddoIntegrationsProps {
15
14
  integrations?: Array<Core.PageIntegration>;
@@ -1,5 +1,5 @@
1
- import type { Dimensions } from "../types/pages";
2
1
  import type { Core } from "@griddo/core";
2
+ import { Dimensions } from "../../types/pages";
3
3
 
4
4
  /**
5
5
  * Return true if the argument is an object (not null)
@@ -1,3 +1,4 @@
1
+ import { Favicon } from "./Favicon";
1
2
  import { GriddoIntegrations } from "./GriddoIntegrations";
2
3
 
3
- export { GriddoIntegrations };
4
+ export { Favicon, GriddoIntegrations };
@@ -1,25 +1,5 @@
1
- // Only browser environment code, not node.
2
- //
3
- // Don't write node code (fs, path, etc..) in this file because is imported by
4
- // `template.tsx` in a browser environment and node doesn't exist there.
5
- // If you need to write utils, for example for `gatsby-node.ts` that uses node
6
- // packages write them in `gatsby-node-utils.ts`.
7
- //
8
- // NOTE: Browserify doesn't work with the mixture of typescript + webpack 5 + SSR
9
-
10
1
  import type { Fields } from "@griddo/core";
11
2
 
12
- /**
13
- * Sanitize a string separated by commas.
14
- */
15
- function cleanCommaSeparated(str: string) {
16
- return str
17
- .split(",")
18
- .map((item) => item.trim())
19
- .filter(Boolean)
20
- .join(",");
21
- }
22
-
23
3
  /**
24
4
  * Format Cloudinary or DAM URL
25
5
  *
@@ -70,4 +50,4 @@ function addCloudinaryParams(image: string, params: string) {
70
50
  return `https://${head}/${params}${fullId}`;
71
51
  }
72
52
 
73
- export { cleanCommaSeparated, formatImage };
53
+ export { formatImage };
@@ -1,3 +1,4 @@
1
+ import type { Core, Fields } from "@griddo/core";
1
2
  import type {
2
3
  APIPageObject,
3
4
  GriddoListPage,
@@ -9,11 +10,9 @@ import type {
9
10
  PageAdditionalInfo,
10
11
  } from "../types/pages";
11
12
  import type { TemplateWithDistributor } from "../types/templates";
12
- import type { Core, Fields } from "@griddo/core";
13
13
 
14
14
  import dotenv from "dotenv";
15
-
16
- import { formatImage } from "../adapters/gatsby/utils";
15
+ import { formatImage } from "./images";
17
16
 
18
17
  dotenv.config();
19
18
 
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.7.3",
4
+ "version": "10.7.4",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -47,7 +47,7 @@
47
47
  "@babel/preset-env": "^7.14.5",
48
48
  "@babel/preset-react": "^7.14.5",
49
49
  "@babel/preset-typescript": "^7.16.5",
50
- "@griddo/core": "10.7.3",
50
+ "@griddo/core": "10.7.4",
51
51
  "@svgr/webpack": "^5.5.0",
52
52
  "babel-loader": "^8.0.6",
53
53
  "babel-plugin-transform-runtime": "^6.23.0",
@@ -115,5 +115,5 @@
115
115
  "publishConfig": {
116
116
  "access": "public"
117
117
  },
118
- "gitHead": "e4765708d342635b3d58af6605256d90671d2ef3"
118
+ "gitHead": "ffe5e36398cb00a902d9c47002278e8008b62a01"
119
119
  }
@@ -2,8 +2,7 @@ import type { CustomHeadProps } from "../types";
2
2
 
3
3
  import * as React from "react";
4
4
 
5
- import { GriddoIntegrations } from "../../build/react";
6
- import { cleanCommaSeparated, formatImage } from "../utils";
5
+ import { Favicon, GriddoIntegrations } from "../../build/react";
7
6
 
8
7
  /**
9
8
  * Gatsby Head API
@@ -36,9 +35,6 @@ const Head = (props: CustomHeadProps) => {
36
35
  !!metaRobots &&
37
36
  (siteOptions?.showBasicMetaRobots || metaRobots !== "index,follow");
38
37
 
39
- // Resize favicon
40
- const faviconResized = formatImage(siteMetadata?.favicon, 32, 32, "png");
41
-
42
38
  // Validate options
43
39
  const cleanPageLanguages =
44
40
  pageMetadata?.pageLanguages?.filter((item) => item.isLive) || [];
@@ -73,7 +69,6 @@ const Head = (props: CustomHeadProps) => {
73
69
  <>
74
70
  {/* Uncomment with Gatsby 5.5.0 */}
75
71
  {/* <html lang={locale} /> */}
76
-
77
72
  {!!pageMetadata?.title && <title>{pageMetadata?.title}</title>}
78
73
  {!!pageMetadata?.description && (
79
74
  <meta name="description" content={pageMetadata?.description} />
@@ -82,7 +77,9 @@ const Head = (props: CustomHeadProps) => {
82
77
  <meta name="title" content={pageMetadata?.title} />
83
78
  )}
84
79
  {useCanonical && <link rel="canonical" href={pageMetadata?.canonical} />}
85
- {!!faviconResized && <link rel="icon" href={faviconResized} />}
80
+
81
+ {/* Favicon images */}
82
+ <Favicon url={siteMetadata?.favicon} />
86
83
 
87
84
  {/* Alternate, solo si se indexa la página y tiene traducciones */}
88
85
  {hrefLangXDefaultUrl && (
@@ -146,6 +143,7 @@ const Head = (props: CustomHeadProps) => {
146
143
  <meta name="keywords" content={pageMetadata.metaKeywords} />
147
144
  )}
148
145
 
146
+ {/* Integrations */}
149
147
  <GriddoIntegrations
150
148
  id={fullUrl}
151
149
  location="head"
@@ -158,4 +156,12 @@ const Head = (props: CustomHeadProps) => {
158
156
  );
159
157
  };
160
158
 
159
+ function cleanCommaSeparated(str: string) {
160
+ return str
161
+ .split(",")
162
+ .map((item) => item.trim())
163
+ .filter(Boolean)
164
+ .join(",");
165
+ }
166
+
161
167
  export { Head };
@@ -1,5 +0,0 @@
1
- import type { Core } from "@griddo/core";
2
- declare function filterBodyIntegrationFromPosition(integrations: Array<Core.PageIntegration>, position: "start" | "end"): string[];
3
- declare function filterHeadIntegrations(integrations: Array<Core.PageIntegration>): string[];
4
- declare function filterPositionIntegrations(integrations: Array<Core.PageIntegration>, position: "head" | "start" | "end"): string[];
5
- export { filterBodyIntegrationFromPosition, filterHeadIntegrations, filterPositionIntegrations, };
@@ -1,2 +0,0 @@
1
- "use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var u=(e,t)=>{for(var n in t)o(e,n,{get:t[n],enumerable:!0})},y=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of f(t))!l.call(e,r)&&r!==n&&o(e,r,{get:()=>t[r],enumerable:!(a=i(t,r))||a.enumerable});return e};var s=e=>y(o({},"__esModule",{value:!0}),e);var I={};u(I,{filterBodyIntegrationFromPosition:()=>d,filterHeadIntegrations:()=>c,filterPositionIntegrations:()=>g});module.exports=s(I);function d(e,t){return e?.filter(n=>n.contentBody!==null&&n.contentBody!==""&&n.contentBodyPosition===t).map(n=>n.contentBody)||[]}function c(e){return e?.filter(t=>t.contentHead!==null&&t.contentHead!=="").map(t=>t.contentHead)||[]}function g(e,t){switch(t){case"head":return c(e);default:return d(e,t)}}0&&(module.exports={filterBodyIntegrationFromPosition,filterHeadIntegrations,filterPositionIntegrations});
2
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../exporter/browser/index.ts"],
4
- "sourcesContent": ["import type { Core } from \"@griddo/core\";\n\nfunction filterBodyIntegrationFromPosition(\n\tintegrations: Array<Core.PageIntegration>,\n\tposition: \"start\" | \"end\",\n) {\n\treturn (\n\t\tintegrations\n\t\t\t?.filter(\n\t\t\t\t(integration) =>\n\t\t\t\t\tintegration.contentBody !== null &&\n\t\t\t\t\tintegration.contentBody !== \"\" &&\n\t\t\t\t\tintegration.contentBodyPosition === position,\n\t\t\t)\n\t\t\t.map((integration) => integration.contentBody!) || []\n\t);\n}\n\nfunction filterHeadIntegrations(integrations: Array<Core.PageIntegration>) {\n\treturn (\n\t\tintegrations\n\t\t\t?.filter(\n\t\t\t\t(integration) =>\n\t\t\t\t\tintegration.contentHead !== null && integration.contentHead !== \"\",\n\t\t\t)\n\t\t\t.map((integration) => integration.contentHead!) || []\n\t);\n}\n\nfunction filterPositionIntegrations(\n\tintegrations: Array<Core.PageIntegration>,\n\tposition: \"head\" | \"start\" | \"end\",\n) {\n\tswitch (position) {\n\t\tcase \"head\":\n\t\t\treturn filterHeadIntegrations(integrations);\n\t\tdefault:\n\t\t\treturn filterBodyIntegrationFromPosition(integrations, position);\n\t}\n}\n\nexport {\n\tfilterBodyIntegrationFromPosition,\n\tfilterHeadIntegrations,\n\tfilterPositionIntegrations,\n};\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uCAAAE,EAAA,2BAAAC,EAAA,+BAAAC,IAAA,eAAAC,EAAAL,GAEA,SAASE,EACRI,EACAC,EACC,CACD,OACCD,GACG,OACAE,GACAA,EAAY,cAAgB,MAC5BA,EAAY,cAAgB,IAC5BA,EAAY,sBAAwBD,CACtC,EACC,IAAKC,GAAgBA,EAAY,WAAY,GAAK,CAAC,CAEvD,CAEA,SAASL,EAAuBG,EAA2C,CAC1E,OACCA,GACG,OACAE,GACAA,EAAY,cAAgB,MAAQA,EAAY,cAAgB,EAClE,EACC,IAAKA,GAAgBA,EAAY,WAAY,GAAK,CAAC,CAEvD,CAEA,SAASJ,EACRE,EACAC,EACC,CACD,OAAQA,EAAU,CACjB,IAAK,OACJ,OAAOJ,EAAuBG,CAAY,EAC3C,QACC,OAAOJ,EAAkCI,EAAcC,CAAQ,CACjE,CACD",
6
- "names": ["browser_exports", "__export", "filterBodyIntegrationFromPosition", "filterHeadIntegrations", "filterPositionIntegrations", "__toCommonJS", "integrations", "position", "integration"]
7
- }
@@ -1,3 +0,0 @@
1
- # browser code
2
-
3
- browser/index.ts can't contain nodejs code, only browser compatible.
@@ -1,46 +0,0 @@
1
- import type { Core } from "@griddo/core";
2
-
3
- function filterBodyIntegrationFromPosition(
4
- integrations: Array<Core.PageIntegration>,
5
- position: "start" | "end",
6
- ) {
7
- return (
8
- integrations
9
- ?.filter(
10
- (integration) =>
11
- integration.contentBody !== null &&
12
- integration.contentBody !== "" &&
13
- integration.contentBodyPosition === position,
14
- )
15
- .map((integration) => integration.contentBody!) || []
16
- );
17
- }
18
-
19
- function filterHeadIntegrations(integrations: Array<Core.PageIntegration>) {
20
- return (
21
- integrations
22
- ?.filter(
23
- (integration) =>
24
- integration.contentHead !== null && integration.contentHead !== "",
25
- )
26
- .map((integration) => integration.contentHead!) || []
27
- );
28
- }
29
-
30
- function filterPositionIntegrations(
31
- integrations: Array<Core.PageIntegration>,
32
- position: "head" | "start" | "end",
33
- ) {
34
- switch (position) {
35
- case "head":
36
- return filterHeadIntegrations(integrations);
37
- default:
38
- return filterBodyIntegrationFromPosition(integrations, position);
39
- }
40
- }
41
-
42
- export {
43
- filterBodyIntegrationFromPosition,
44
- filterHeadIntegrations,
45
- filterPositionIntegrations,
46
- };