ts-glitter 16.2.6 → 16.2.9

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/src/seo-config.ts CHANGED
@@ -52,12 +52,28 @@ export class SeoConfig {
52
52
  )[0] ?? {};
53
53
  const colJson = extractCols(cols);
54
54
  const urlCode = decodeURI((cf.page as string).split('/')[1]);
55
- const colData = colJson.find((item: { code: string }) => item.code === urlCode);
55
+ console.log(`urlCode===>`,urlCode)
56
+ const colData = colJson.find((item: any) => {
57
+ console.log(`item==>`,item)
58
+ if (item.language_data && item.language_data[cf.language]) {
59
+ return item.language_data[cf.language].seo.domain === urlCode || item.title === urlCode
60
+ } else {
61
+ return (item.code === urlCode) || item.title === urlCode;
62
+ }
63
+ });
64
+ console.log(`colData===>`,colData)
56
65
  if (colData) {
57
- cf.data.page_config.seo.title = colData.seo_title;
58
- cf.data.page_config.seo.content = colData.seo_content;
59
- cf.data.page_config.seo.keywords = colData.seo_keywords;
60
- cf.data.tag = cf.page
66
+ if (colData.language_data && colData.language_data[cf.language]) {
67
+ cf.data.page_config.seo.title = colData.language_data[cf.language].seo.title || urlCode;
68
+ cf.data.page_config.seo.content = colData.language_data[cf.language].seo.content;
69
+ cf.data.tag = cf.page
70
+ } else {
71
+ cf.data.page_config.seo.title = colData.seo_title || urlCode;
72
+ cf.data.page_config.seo.content = colData.seo_content;
73
+ cf.data.page_config.seo.keywords = colData.seo_keywords;
74
+ cf.data.tag = cf.page
75
+ }
76
+ cf.data.page_config.seo.image = colData.seo_image;
61
77
  }
62
78
  }
63
79
 
@@ -106,14 +122,15 @@ export class SeoConfig {
106
122
  return html`location.href = '/';`;
107
123
  }
108
124
  }
125
+
109
126
  //商品頁面SEO
110
- public static async productSEO(cf:{
111
- data:any,
112
- language:any,
113
- appName:string,
114
- product_id:string,
115
- page:string
116
- }){
127
+ public static async productSEO(cf: {
128
+ data: any,
129
+ language: any,
130
+ appName: string,
131
+ product_id: string,
132
+ page: string
133
+ }) {
117
134
  const product_domain = (cf.page as string).split('/')[1];
118
135
  const pd = await new Shopping(cf.appName, undefined).getProduct(
119
136
  product_domain
@@ -130,36 +147,35 @@ export class SeoConfig {
130
147
  language: cf.language,
131
148
  }
132
149
  );
133
-
134
- console.log(`pd==>`,pd)
135
150
  if (pd.data.content) {
136
151
  pd.data.content.language_data = pd.data.content.language_data ?? {};
137
152
  const productSeo = (pd.data.content.language_data[cf.language] && pd.data.content.language_data[cf.language].seo) || (pd.data.content.seo ?? {});
138
- const language_data=pd.data.content.language_data
153
+ const language_data = pd.data.content.language_data
139
154
  cf.data.page_config = cf.data.page_config ?? {};
140
155
  cf.data.page_config.seo = cf.data.page_config.seo ?? {};
141
156
  cf.data.page_config.seo.title = productSeo.title;
142
- cf.data.page_config.seo.image = (language_data && language_data[cf.language] && language_data.preview_image && language_data.preview_image[0] ) || pd.data.content.preview_image[0];
157
+ cf.data.page_config.seo.image = (language_data && language_data[cf.language] && language_data.preview_image && language_data.preview_image[0]) || pd.data.content.preview_image[0];
143
158
  cf.data.page_config.seo.content = productSeo.content;
144
159
  cf.data.tag = cf.page;
145
160
  }
146
161
  }
162
+
147
163
  //網誌頁面SEO
148
- public static async articleSeo(cf:{
149
- article:any,
150
- page:string,
151
- appName:string,
152
- data:any,
153
- language:any
154
- }){
164
+ public static async articleSeo(cf: {
165
+ article: any,
166
+ page: string,
167
+ appName: string,
168
+ data: any,
169
+ language: any
170
+ }) {
155
171
  cf.article = cf.article || (cf.page as any).split('/')[1];
156
172
  let query = [`(content->>'$.type'='article')`, `(content->>'$.tag'='${cf.article}')`];
157
173
  const article: any = await new UtDatabase(cf.appName, `t_manager_post`).querySql(query, {
158
174
  page: 0,
159
175
  limit: 1,
160
176
  });
161
- cf.data.page_config = cf.data.page_config ?? {};
162
- cf.data.page_config.seo = cf.data.page_config.seo ?? {};
177
+ cf.data.page_config = cf.data.page_config ?? {};
178
+ cf.data.page_config.seo = cf.data.page_config.seo ?? {};
163
179
  if (article.data[0]) {
164
180
  cf.data.tag = cf.page;
165
181
  if (article.data[0].content.language_data && article.data[0].content.language_data[cf.language]) {
@@ -173,8 +189,9 @@ export class SeoConfig {
173
189
  }
174
190
  }
175
191
  }
192
+
176
193
  //取得多國語言
177
- public static async language(store_info:any,req:any){
194
+ public static async language(store_info: any, req: any) {
178
195
  function checkIncludes(lan: string) {
179
196
  return store_info.language_setting.support.includes(lan);
180
197
  }
@@ -204,63 +221,66 @@ export class SeoConfig {
204
221
  return store_info.language_setting.def;
205
222
  }
206
223
  }
224
+
207
225
  //FB像素
208
- public static fbCode(FBCode:any){
226
+ public static fbCode(FBCode: any) {
209
227
  return FBCode && FBCode.pixel
210
228
  ? html`<!-- Meta Pixel Code -->
211
- <script>
212
- !(function (f, b, e, v, n, t, s) {
213
- if (f.fbq) return;
214
- n = f.fbq = function () {
215
- n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
216
- };
217
- if (!f._fbq) f._fbq = n;
218
- n.push = n;
219
- n.loaded = !0;
220
- n.version = '2.0';
221
- n.queue = [];
222
- t = b.createElement(e);
223
- t.async = !0;
224
- t.src = v;
225
- s = b.getElementsByTagName(e)[0];
226
- s.parentNode.insertBefore(t, s);
227
- })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
228
- fbq('init', '${FBCode.pixel}');
229
- fbq('track', 'PageView');
230
- </script>
231
- <noscript><img height="1" width="1" style="display:none"
232
- src="https://www.facebook.com/tr?id=617830100580621&ev=PageView&noscript=1"/>
233
- </noscript>
234
- <!-- End Meta Pixel Code -->`
229
+ <script>
230
+ !(function (f, b, e, v, n, t, s) {
231
+ if (f.fbq) return;
232
+ n = f.fbq = function () {
233
+ n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
234
+ };
235
+ if (!f._fbq) f._fbq = n;
236
+ n.push = n;
237
+ n.loaded = !0;
238
+ n.version = '2.0';
239
+ n.queue = [];
240
+ t = b.createElement(e);
241
+ t.async = !0;
242
+ t.src = v;
243
+ s = b.getElementsByTagName(e)[0];
244
+ s.parentNode.insertBefore(t, s);
245
+ })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
246
+ fbq('init', '${FBCode.pixel}');
247
+ fbq('track', 'PageView');
248
+ </script>
249
+ <noscript><img height="1" width="1" style="display:none"
250
+ src="https://www.facebook.com/tr?id=617830100580621&ev=PageView&noscript=1"/>
251
+ </noscript>
252
+ <!-- End Meta Pixel Code -->`
235
253
  : ''
236
254
  }
255
+
237
256
  //GA標籤
238
- public static gTag(g_tag:any[]){
257
+ public static gTag(g_tag: any[]) {
239
258
  return (g_tag || [])
240
259
  .map((dd: any) => {
241
260
  return html`<!-- Google tag (gtag.js) -->
242
- <!-- Google Tag Manager -->
243
- <script>
244
- (function (w, d, s, l, i) {
245
- w[l] = w[l] || [];
246
- w[l].push({
247
- 'gtm.start': new Date().getTime(),
248
- event: 'gtm.js',
249
- });
250
- var f = d.getElementsByTagName(s)[0],
251
- j = d.createElement(s),
252
- dl = l != 'dataLayer' ? '&l=' + l : '';
253
- j.async = true;
254
- j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
255
- f.parentNode.insertBefore(j, f);
256
- })(window, document, 'script', 'dataLayer', '${dd.code}');
257
- </script>
258
- <!-- End Google Tag Manager -->`;
261
+ <!-- Google Tag Manager -->
262
+ <script>
263
+ (function (w, d, s, l, i) {
264
+ w[l] = w[l] || [];
265
+ w[l].push({
266
+ 'gtm.start': new Date().getTime(),
267
+ event: 'gtm.js',
268
+ });
269
+ var f = d.getElementsByTagName(s)[0],
270
+ j = d.createElement(s),
271
+ dl = l != 'dataLayer' ? '&l=' + l : '';
272
+ j.async = true;
273
+ j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
274
+ f.parentNode.insertBefore(j, f);
275
+ })(window, document, 'script', 'dataLayer', '${dd.code}');
276
+ </script>
277
+ <!-- End Google Tag Manager -->`;
259
278
  })
260
279
  .join('')
261
280
  }
281
+
262
282
  //GA追蹤
263
- public static gA4(ga4:any[]){
283
+ public static gA4(ga4: any[]) {
264
284
  return (ga4 || [])
265
285
  .map((dd: any) => {
266
286
  return html`<!-- Google tag (gtag.js) -->
@@ -286,32 +306,21 @@ export class SeoConfig {
286
306
 
287
307
 
288
308
  export function extractCols(data: {
289
- value: {
290
- code: string;
291
- array: { code: string }[];
292
- }[];
309
+ value: any[];
293
310
  updated_at: Date;
294
311
  }) {
295
- const items: any = [];
312
+ let items: any = [];
296
313
  const updated_at = new Date(data.updated_at).toISOString().replace(/\.\d{3}Z$/, '+00:00');
297
314
  data.value.map((item: any) => {
298
315
  items.push({
299
- code: item.code,
300
- updated_at,
301
- seo_title: item.seo_title,
302
- seo_image: item.seo_image,
303
- seo_content: item.seo_content,
316
+ ...item,
317
+ updated_at
304
318
  });
305
319
  if (item.array && item.array.length > 0) {
306
- item.array.map((child: any) => {
307
- items.push({
308
- code: child.code,
309
- updated_at,
310
- seo_title: child.seo_title,
311
- seo_image: child.seo_image,
312
- seo_content: child.seo_content,
313
- });
314
- });
320
+ items = items.concat(extractCols({
321
+ value: item.array,
322
+ updated_at: data.updated_at
323
+ }))
315
324
  }
316
325
  });
317
326
  return items;
@@ -320,15 +329,8 @@ export function extractCols(data: {
320
329
  export function extractProds(data: any) {
321
330
  const items: any = [];
322
331
  data.map((item: any) => {
323
- const code = (() => {
324
- try {
325
- return item.content.seo.domain;
326
- } catch (error) {
327
- return '';
328
- }
329
- })();
330
332
  const updated_at = new Date(item.updated_time).toISOString().replace(/\.\d{3}Z$/, '+00:00');
331
- items.push({code, updated_at});
333
+ items.push({items});
332
334
  });
333
335
  return items;
334
336
  }