@bebranded/bb-contents 1.0.41-beta → 1.0.43-beta
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/bb-contents.js +36 -5
- package/package.json +1 -1
package/bb-contents.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* BeBranded Contents
|
|
3
3
|
* Contenus additionnels français pour Webflow
|
|
4
|
-
* @version 1.0.
|
|
4
|
+
* @version 1.0.43-beta
|
|
5
5
|
* @author BeBranded
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @website https://www.bebranded.xyz
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
// Configuration
|
|
19
19
|
const config = {
|
|
20
|
-
version: '1.0.
|
|
20
|
+
version: '1.0.43-beta',
|
|
21
21
|
debug: true, // Activé temporairement pour debug
|
|
22
22
|
prefix: 'bb-', // utilisé pour générer les sélecteurs (data-bb-*)
|
|
23
23
|
youtubeEndpoint: null, // URL du worker YouTube (à définir par l'utilisateur)
|
|
@@ -600,6 +600,7 @@
|
|
|
600
600
|
this.cleanCache();
|
|
601
601
|
|
|
602
602
|
const elements = scope.querySelectorAll('[bb-youtube-channel]');
|
|
603
|
+
console.log('[DEBUG] YouTube elements found:', elements.length);
|
|
603
604
|
if (elements.length === 0) return;
|
|
604
605
|
|
|
605
606
|
// Module détecté: youtube
|
|
@@ -616,17 +617,38 @@
|
|
|
616
617
|
const videoCount = bbContents._getAttr(element, 'bb-youtube-video-count') || '10';
|
|
617
618
|
const allowShorts = bbContents._getAttr(element, 'bb-youtube-allow-shorts') === 'true';
|
|
618
619
|
const language = bbContents._getAttr(element, 'bb-youtube-language') || 'fr';
|
|
620
|
+
|
|
621
|
+
// Vérifier la configuration au moment de l'initialisation
|
|
619
622
|
const endpoint = bbContents.config.youtubeEndpoint;
|
|
620
623
|
|
|
624
|
+
console.log('[DEBUG] YouTube config:', {channelId, videoCount, allowShorts, language, endpoint});
|
|
625
|
+
|
|
621
626
|
if (!channelId) {
|
|
622
627
|
// Erreur: bb-youtube-channel manquant
|
|
623
628
|
return;
|
|
624
629
|
}
|
|
625
630
|
|
|
626
631
|
if (!endpoint) {
|
|
627
|
-
//
|
|
628
|
-
|
|
629
|
-
|
|
632
|
+
// Attendre que la configuration soit définie (max 5 secondes)
|
|
633
|
+
const retryCount = element.getAttribute('data-youtube-retry-count') || '0';
|
|
634
|
+
const retries = parseInt(retryCount);
|
|
635
|
+
|
|
636
|
+
if (retries < 50) { // 50 * 100ms = 5 secondes max
|
|
637
|
+
console.log('[DEBUG] YouTube endpoint not configured yet, waiting... (attempt', retries + 1, ')');
|
|
638
|
+
element.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Configuration YouTube en cours...</div>';
|
|
639
|
+
element.setAttribute('data-youtube-retry-count', (retries + 1).toString());
|
|
640
|
+
|
|
641
|
+
// Réessayer dans 100ms
|
|
642
|
+
setTimeout(() => {
|
|
643
|
+
this.init(scope);
|
|
644
|
+
}, 100);
|
|
645
|
+
return;
|
|
646
|
+
} else {
|
|
647
|
+
// Timeout après 5 secondes
|
|
648
|
+
console.log('[DEBUG] YouTube endpoint configuration timeout');
|
|
649
|
+
element.innerHTML = '<div style="padding: 20px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; color: #dc2626;"><strong>Configuration YouTube manquante</strong><br>Ajoutez dans le <head> :<br><code style="display: block; background: #f3f4f6; padding: 10px; margin: 10px 0; border-radius: 4px; font-family: monospace;"><script><br>bbContents.config.youtubeEndpoint = \'votre-worker-url\';<br></script></code></div>';
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
630
652
|
}
|
|
631
653
|
|
|
632
654
|
// Chercher le template pour une vidéo (directement dans l'élément ou dans un conteneur)
|
|
@@ -668,14 +690,17 @@
|
|
|
668
690
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Chargement des vidéos YouTube...</div>';
|
|
669
691
|
|
|
670
692
|
// Appeler l'API via le Worker
|
|
693
|
+
console.log('[DEBUG] Fetching YouTube data from:', `${endpoint}?channelId=${channelId}&maxResults=${videoCount}&allowShorts=${allowShorts}`);
|
|
671
694
|
fetch(`${endpoint}?channelId=${channelId}&maxResults=${videoCount}&allowShorts=${allowShorts}`)
|
|
672
695
|
.then(response => {
|
|
696
|
+
console.log('[DEBUG] YouTube API response status:', response.status);
|
|
673
697
|
if (!response.ok) {
|
|
674
698
|
throw new Error(`HTTP ${response.status}`);
|
|
675
699
|
}
|
|
676
700
|
return response.json();
|
|
677
701
|
})
|
|
678
702
|
.then(data => {
|
|
703
|
+
console.log('[DEBUG] YouTube API data received:', data);
|
|
679
704
|
if (data.error) {
|
|
680
705
|
throw new Error(data.error.message || 'Erreur API YouTube');
|
|
681
706
|
}
|
|
@@ -687,6 +712,7 @@
|
|
|
687
712
|
this.generateYouTubeFeed(container, template, data, allowShorts, language);
|
|
688
713
|
})
|
|
689
714
|
.catch(error => {
|
|
715
|
+
console.error('[DEBUG] YouTube API error:', error);
|
|
690
716
|
// Erreur dans le module youtube
|
|
691
717
|
|
|
692
718
|
// En cas d'erreur, essayer de récupérer du cache même expiré
|
|
@@ -694,10 +720,12 @@
|
|
|
694
720
|
if (expiredCache) {
|
|
695
721
|
try {
|
|
696
722
|
const cachedData = JSON.parse(expiredCache);
|
|
723
|
+
console.log('[DEBUG] Using expired cache:', cachedData);
|
|
697
724
|
// Utilisation du cache expiré en cas d'erreur API
|
|
698
725
|
this.generateYouTubeFeed(container, template, cachedData.value, allowShorts, language);
|
|
699
726
|
return;
|
|
700
727
|
} catch (e) {
|
|
728
|
+
console.error('[DEBUG] Cache parsing error:', e);
|
|
701
729
|
// Ignorer les erreurs de parsing
|
|
702
730
|
}
|
|
703
731
|
}
|
|
@@ -708,13 +736,16 @@
|
|
|
708
736
|
},
|
|
709
737
|
|
|
710
738
|
generateYouTubeFeed: function(container, template, data, allowShorts, language = 'fr') {
|
|
739
|
+
console.log('[DEBUG] generateYouTubeFeed called with data:', data);
|
|
711
740
|
if (!data.items || data.items.length === 0) {
|
|
741
|
+
console.log('[DEBUG] No videos found in data');
|
|
712
742
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Aucune vidéo trouvée</div>';
|
|
713
743
|
return;
|
|
714
744
|
}
|
|
715
745
|
|
|
716
746
|
// Les vidéos sont déjà filtrées par l'API YouTube selon allowShorts
|
|
717
747
|
let videos = data.items;
|
|
748
|
+
console.log('[DEBUG] Processing', videos.length, 'videos');
|
|
718
749
|
// Vidéos reçues de l'API
|
|
719
750
|
|
|
720
751
|
// Vider le conteneur (en préservant les éléments marquee)
|