@gudhub/ssg-web-components-library 1.0.100 → 1.0.102

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.100",
3
+ "version": "1.0.102",
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,13 +78,13 @@ class ImageComponent extends GHComponent {
75
78
  }
76
79
  }
77
80
 
78
- this.generatedImageSrc = relativeImagePath;
81
+ this.generatedImageSrc = this.normalizeUrlPath(relativeImagePath);
79
82
 
80
83
  // Download image from GudHub (this.dataUrl) to cache (this.generatedImageSrc)
81
84
  if (window?.imagesRegeneration) {
82
85
  if (this.generatedImageSrc && this.dataUrl) {
83
86
  try {
84
- await fetch(`${this.generatedImageSrc}?source=${this.dataUrl}&mode=ssr`);
87
+ await fetch(`${this.generatedImageSrc}?source=${encodeURIComponent(this.dataUrl)}&mode=ssr`);
85
88
  this.src = this.generatedImageSrc;
86
89
  } catch (error) {
87
90
  console.error('Failed to fetch generatedImageSrc:', error);
@@ -174,7 +177,7 @@ class ImageComponent extends GHComponent {
174
177
  const fallbackSrc = this.getAttribute('src');
175
178
  const dataMaxWidth = parseInt(this.getAttribute('data-max-width'), 10);
176
179
 
177
- const src = dataSrc && dataUrl ? dataSrc : fallbackSrc;
180
+ const src = this.normalizeUrlPath(dataSrc && dataUrl ? dataSrc : fallbackSrc);
178
181
  if (!src) {
179
182
  console.warn('No valid image source found.');
180
183
  return;
@@ -239,6 +242,20 @@ class ImageComponent extends GHComponent {
239
242
  source.setAttribute('type', type);
240
243
  return source;
241
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
+ };
242
259
  }
243
260
 
244
261
  if (!window.customElements.get('image-component')) {