@gudhub/ssg-web-components-library 1.0.101 → 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
|
@@ -44,7 +44,10 @@ class ImageComponent extends GHComponent {
|
|
|
44
44
|
const getAppAndFileIds = (url) => {
|
|
45
45
|
if (!url) return;
|
|
46
46
|
|
|
47
|
-
const cleanUrl = url
|
|
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
|
-
|
|
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=${
|
|
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')) {
|