@nuskin/cs-product-lib 1.0.18 → 1.0.19-cx12-6646.2
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/package.json +1 -1
- package/src/helpers.js +37 -14
package/package.json
CHANGED
package/src/helpers.js
CHANGED
|
@@ -13,27 +13,37 @@ const { isNullOrEmpty } = require('@nuskin/ns-common-lib')
|
|
|
13
13
|
// CONSTS for helpers
|
|
14
14
|
const TEXT_COLOR = 'textColor';
|
|
15
15
|
const BACKGROUND_COLOR = 'backgroundColor';
|
|
16
|
+
const ALL = 'all';
|
|
16
17
|
|
|
17
|
-
/* istanbul ignore next */
|
|
18
18
|
function mapBrandStyle(feature, type) {
|
|
19
|
+
if (!feature)
|
|
20
|
+
return null
|
|
19
21
|
// if brand style background color is authored, use it, and make text black.
|
|
20
22
|
// otherwise make text white, and use feature.background_color if it exists or default the background color to be #4f4d4d if not
|
|
21
23
|
const isBrandStyle = feature.brand_style && Array.isArray(feature.brand_style) && feature.brand_style.length > 0;
|
|
22
24
|
// eslint-disable-next-line no-nested-ternary
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
let backgroundColor = isBrandStyle ? feature.brand_style[0].background_color : feature.background_color?.length > 1 ? feature.background_color : '#4f4d4d';
|
|
26
|
+
let textColor = isBrandStyle && feature.brand_style[0].background_color?.length > 0 ? '#000000' : '#ffffff';
|
|
27
|
+
const name = isBrandStyle && feature.brand_style[0].title?.length > 0 ? feature.brand_style[0].title : '';
|
|
28
|
+
|
|
29
|
+
if (!textColor.includes('#')) {
|
|
30
|
+
textColor = `#${textColor}`
|
|
31
|
+
}
|
|
32
|
+
if (!backgroundColor?.includes('#')) {
|
|
33
|
+
backgroundColor = `#${backgroundColor}`
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
switch (type) {
|
|
27
37
|
case TEXT_COLOR:
|
|
28
|
-
if (!textColor.includes('#')) {
|
|
29
|
-
return `#${textColor}`
|
|
30
|
-
}
|
|
31
38
|
return textColor;
|
|
32
39
|
case BACKGROUND_COLOR:
|
|
33
|
-
if (!backgroundColor?.includes('#')) {
|
|
34
|
-
return `#${backgroundColor}`
|
|
35
|
-
}
|
|
36
40
|
return backgroundColor;
|
|
41
|
+
case ALL:
|
|
42
|
+
return {
|
|
43
|
+
textColor,
|
|
44
|
+
backgroundColor,
|
|
45
|
+
name
|
|
46
|
+
}
|
|
37
47
|
default:
|
|
38
48
|
break;
|
|
39
49
|
}
|
|
@@ -312,7 +322,9 @@ function mapVariants(parent) {
|
|
|
312
322
|
return _variants
|
|
313
323
|
}
|
|
314
324
|
|
|
315
|
-
function mapSeoInformation(parent, homeUrl) {
|
|
325
|
+
function mapSeoInformation(parent, homeUrl, type) {
|
|
326
|
+
type = type || 'product'
|
|
327
|
+
if (!parent?.localeData && parent?.locale) parent.localeData = parseLocale(parent?.locale);
|
|
316
328
|
const { ogImage } = parent?.seo_information || {}
|
|
317
329
|
const seoData = {
|
|
318
330
|
metaTitle: parent?.seo_information?.meta_title || parent?.name,
|
|
@@ -324,11 +336,22 @@ function mapSeoInformation(parent, homeUrl) {
|
|
|
324
336
|
}/${parent?.localeData?.language}/product/${
|
|
325
337
|
parent?.seo_information?.slug || parent?.sku
|
|
326
338
|
}`,
|
|
327
|
-
ogImage:
|
|
339
|
+
ogImage: mapImage(parent?.seo_information?.og_image_bynder || parent?.seo_information?.og_image),
|
|
340
|
+
slug: parent?.seo_information?.slug
|
|
341
|
+
}
|
|
342
|
+
switch (type) {
|
|
343
|
+
case 'category':
|
|
344
|
+
seoData.canonicalURL = `${homeUrl}/catalog/${
|
|
345
|
+
parent?.localeData?.country
|
|
346
|
+
}/${parent?.localeData?.language}/category/${
|
|
347
|
+
parent?.seo_information?.slug
|
|
348
|
+
}`
|
|
349
|
+
break
|
|
350
|
+
default:
|
|
351
|
+
break
|
|
328
352
|
}
|
|
329
353
|
if (ogImage) {
|
|
330
|
-
seoData.ogImage
|
|
331
|
-
seoData.ogImage.alt = ogImage.description || ogImage.title || ''
|
|
354
|
+
seoData.ogImage = mapImage(ogImage)
|
|
332
355
|
}
|
|
333
356
|
return seoData
|
|
334
357
|
}
|