@gudhub/ssg-web-components-library 1.0.101 → 1.0.103

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": "@gudhub/ssg-web-components-library",
3
- "version": "1.0.101",
3
+ "version": "1.0.103",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -44,7 +44,10 @@ class ImageComponent extends GHComponent {
44
44
  const getAppAndFileIds = (url) => {
45
45
  if (!url) return;
46
46
 
47
- const cleanUrl = url.split('?')[0].replace(/\/+$/, ''); // remove query & trailing slash
47
+ const cleanUrl = decodeURIComponent(url)
48
+ .split('?')[0]
49
+ .replace(/\/+$/, ''); // remove query & trailing slash
50
+
48
51
  const parts = cleanUrl.split('/');
49
52
 
50
53
  const appId = parts[parts.length - 2];
@@ -75,16 +78,13 @@ class ImageComponent extends GHComponent {
75
78
  }
76
79
  }
77
80
 
78
- const normalizeUrlPath = (value) =>
79
- value ? value.trim().replace(/\s+/g, '-') : value;
80
-
81
- this.generatedImageSrc = normalizeUrlPath(relativeImagePath);
81
+ this.generatedImageSrc = this.normalizeUrlPath(relativeImagePath);
82
82
 
83
83
  // Download image from GudHub (this.dataUrl) to cache (this.generatedImageSrc)
84
84
  if (window?.imagesRegeneration) {
85
85
  if (this.generatedImageSrc && this.dataUrl) {
86
86
  try {
87
- await fetch(`${this.generatedImageSrc}?source=${normalizeUrlPath(this.dataUrl)}&mode=ssr`);
87
+ await fetch(`${this.generatedImageSrc}?source=${encodeURIComponent(this.dataUrl)}&mode=ssr`);
88
88
  this.src = this.generatedImageSrc;
89
89
  } catch (error) {
90
90
  console.error('Failed to fetch generatedImageSrc:', error);
@@ -177,7 +177,7 @@ class ImageComponent extends GHComponent {
177
177
  const fallbackSrc = this.getAttribute('src');
178
178
  const dataMaxWidth = parseInt(this.getAttribute('data-max-width'), 10);
179
179
 
180
- const src = dataSrc && dataUrl ? dataSrc : fallbackSrc;
180
+ const src = this.normalizeUrlPath(dataSrc && dataUrl ? dataSrc : fallbackSrc);
181
181
  if (!src) {
182
182
  console.warn('No valid image source found.');
183
183
  return;
@@ -242,6 +242,20 @@ class ImageComponent extends GHComponent {
242
242
  source.setAttribute('type', type);
243
243
  return source;
244
244
  }
245
+
246
+ normalizeUrlPath = (value) => {
247
+ if (!value) return value;
248
+
249
+ return value
250
+ .normalize('NFD') // separate diacritics
251
+ .replace(/[\u0300-\u036f]/g, '') // remove diacritics
252
+ .replace(/[()]/g, '') // remove brackets
253
+ .replace(/[^a-zA-Z0-9/._-]+/g, '-') // replace special chars with -
254
+ .replace(/-+/g, '-') // collapse multiple -
255
+ .replace(/\/-+/g, '/') // avoid "/-"
256
+ .replace(/^-|-$/g, '') // trim -
257
+ .toLowerCase();
258
+ };
245
259
  }
246
260
 
247
261
  if (!window.customElements.get('image-component')) {
@@ -99,18 +99,16 @@ class MetaTag extends GHComponent {
99
99
  // fieldId = fieldId.field_id;
100
100
  // value = item.fields.find(findedField => findedField.field_id == fieldId).field_value;
101
101
 
102
-
103
102
  let titleValue = item.fields.find(findedField => findedField.field_id == titleId).field_value;
104
103
  let descriptionValue = item.fields.find(findedField => findedField.field_id == descriptionId).field_value;
105
104
  let slugValue = item.fields.find(findedField => findedField.field_id == slugId).field_value;
106
- let imageValue = !slugValue.includes('/blog/') ? item.fields.find(findedField => findedField.field_id == imageUrl).field_value : false;
105
+ let imageValue = (!slugValue.includes('/blog/') && !slugValue.includes('/service-areas/')) ? item.fields.find(findedField => findedField.field_id == imageUrl).field_value : false;
107
106
 
108
107
  // value = isNaN(value) ? value : await this.getContent(`https://gudhub.com/userdata/${window.getConfig().chapters[chapter].app_id}/${value}.html`);
109
108
  titleValue = isNaN(titleValue) ? titleValue : await this.getContent(`https://app.gudhub.com/userdata/${window.getConfig().chapters[chapter].app_id}/${titleValue}.html`);
110
109
  descriptionValue = isNaN(descriptionValue) ? descriptionValue : await this.getContent(`https://app.gudhub.com/userdata/${window.getConfig().chapters[chapter].app_id}/${descriptionValue}.html`);
111
110
  slugValue = isNaN(slugValue) ? slugValue : await this.getContent(`https://app.gudhub.com/userdata/${window.getConfig().chapters[chapter].app_id}/${slugValue}.html`);
112
- imageValue = !slugValue.includes('/blog/') ? isNaN(imageValue) ? imageValue : await this.getContent(`https://app.gudhub.com/userdata/${window.getConfig() .chapters[chapter].app_id}/${imageValue}.html`) : false;
113
-
111
+ imageValue = (!slugValue.includes('/blog/') && !slugValue.includes('/service-areas/')) ? isNaN(imageValue) ? imageValue : await this.getContent(`https://app.gudhub.com/userdata/${window.getConfig() .chapters[chapter].app_id}/${imageValue}.html`) : false;
114
112
 
115
113
  //TITLE
116
114
  if ( !document.querySelector('title') ) {
@@ -142,7 +140,7 @@ class MetaTag extends GHComponent {
142
140
  }
143
141
 
144
142
 
145
- if (!slugValue.includes('/blog/')) {
143
+ if ((!slugValue.includes('/blog/') && !slugValue.includes('/service-areas/'))) {
146
144
  if ( !document.querySelector('[name="twitter:image"]') ) {
147
145
  const twitterMetaSiteImage = document.createElement('meta');
148
146
  twitterMetaSiteImage.setAttribute('name', 'twitter:image');