@bytebrand/export-cars 1.21.90 → 1.21.92

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytebrand/export-cars",
3
- "version": "1.21.90",
3
+ "version": "1.21.92",
4
4
  "description": "",
5
5
  "author": "bytebrand",
6
6
  "license": "UNLICENSED",
@@ -23,6 +23,10 @@ export class GoogleXmlBuilder extends XMLBuilderBase {
23
23
  return this.getVehicleFulfillmentElement(key, data);
24
24
  }
25
25
 
26
+ if (key === 'description') {
27
+ return this.getElement(`g:${key}`, this.getDescription(data));
28
+ }
29
+
26
30
  if (['additional_image_link', 'vehicle_option'].includes(key)) {
27
31
  return data.map((value: string) => this.getElement(`g:${key}`, this.escapeXML(value))).join('');
28
32
  } else {
@@ -76,4 +80,10 @@ export class GoogleXmlBuilder extends XMLBuilderBase {
76
80
  .replace(/"/g, '"')
77
81
  .replace(/'/g, ''') : str;
78
82
  }
83
+
84
+ private getDescription(str: string | null | undefined): string {
85
+ return typeof str === 'string' ? str.replace(/&/g, '&')
86
+ .replace(/"/g, '"')
87
+ .replace(/'/g, ''') : str;
88
+ }
79
89
  }
@@ -86,7 +86,7 @@ export class GoogleTransformer {
86
86
  fuel_consumption: `${this.transformService.fuelConsumption(car)}l/100km`,
87
87
  energy_consumption: this.getWLTP(car),
88
88
  co2_emissions: `${this.transformService.cO2Emission(car)}g/km`,
89
- description: (await this.getDescription(car)).substring(0, 4800),
89
+ description: this.processText((await this.getDescription(car))),
90
90
  identifier_exists: 'no',
91
91
  availability: 'in_stock',
92
92
  // custom_label_0: '',
@@ -119,6 +119,26 @@ export class GoogleTransformer {
119
119
  return trim(escape(join([this.getBrand(car), model], ' ')));
120
120
  }
121
121
 
122
+ private processText(input: string) {
123
+ return input
124
+ .replace(/\*\*\\/g, '</strong></p>|||')
125
+ .replace(/\*\*/g, '<p><strong>')
126
+ .split('|||')
127
+ .map(item => item.trim())
128
+ .flatMap(str =>
129
+ str.split('\\')
130
+ .map(item => item.trim())
131
+ .filter(Boolean)
132
+ )
133
+ .map(item =>
134
+ item.startsWith('* ') ? item.slice(2) : item
135
+ )
136
+ .map(item =>
137
+ item.includes('<p>') ? item : `<p>${item}</p>`
138
+ )
139
+ .join('');
140
+ }
141
+
122
142
  private async getDescription(car: DataSchemes.Car): Promise<string> {
123
143
  const dealerId = get(car, 'metaData.ownerId');
124
144
  const descriptionSchema = await this.userService.getDefaultSummaryByDealerId(dealerId);