@bebranded/bb-contents 1.0.30-beta → 1.0.32-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 +59 -22
- 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.32-beta
|
|
5
5
|
* @author BeBranded
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @website https://www.bebranded.xyz
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
// Configuration
|
|
19
19
|
const config = {
|
|
20
|
-
version: '1.0.
|
|
21
|
-
debug:
|
|
20
|
+
version: '1.0.32-beta',
|
|
21
|
+
debug: false, // Désactivé par défaut pour une console propre
|
|
22
22
|
prefix: 'bb-', // utilisé pour générer les sélecteurs (data-bb-*)
|
|
23
23
|
i18n: {
|
|
24
24
|
copied: 'Lien copié !'
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
// Utilitaires
|
|
36
36
|
utils: {
|
|
37
37
|
log: function(...args) {
|
|
38
|
-
if (config.debug) {
|
|
38
|
+
if (bbContents.config.debug) {
|
|
39
39
|
console.log('[BB Contents]', ...args);
|
|
40
40
|
}
|
|
41
41
|
},
|
|
@@ -76,6 +76,9 @@
|
|
|
76
76
|
|
|
77
77
|
// Initialisation
|
|
78
78
|
init: function() {
|
|
79
|
+
// Console simple et épurée
|
|
80
|
+
console.log('bb-contents | v' + this.config.version);
|
|
81
|
+
|
|
79
82
|
this.utils.log('Initialisation v' + this.config.version);
|
|
80
83
|
|
|
81
84
|
// Déterminer la portée
|
|
@@ -605,6 +608,7 @@
|
|
|
605
608
|
const channelId = bbContents._getAttr(element, 'bb-youtube-channel');
|
|
606
609
|
const videoCount = bbContents._getAttr(element, 'bb-youtube-video-count') || '10';
|
|
607
610
|
const allowShorts = bbContents._getAttr(element, 'bb-youtube-allow-shorts') === 'true';
|
|
611
|
+
const language = bbContents._getAttr(element, 'bb-youtube-language') || 'fr';
|
|
608
612
|
const endpoint = bbContents.config.youtubeEndpoint;
|
|
609
613
|
|
|
610
614
|
if (!channelId) {
|
|
@@ -644,12 +648,12 @@
|
|
|
644
648
|
element.setAttribute('data-bb-youtube-processed', 'true');
|
|
645
649
|
|
|
646
650
|
// Vérifier le cache d'abord
|
|
647
|
-
const cacheKey = `youtube_${channelId}_${videoCount}_${allowShorts}`;
|
|
651
|
+
const cacheKey = `youtube_${channelId}_${videoCount}_${allowShorts}_${language}`;
|
|
648
652
|
const cachedData = this.cache.get(cacheKey);
|
|
649
653
|
|
|
650
654
|
if (cachedData) {
|
|
651
655
|
bbContents.utils.log('Données YouTube récupérées du cache (économie API)');
|
|
652
|
-
this.generateYouTubeFeed(container, template, cachedData, allowShorts);
|
|
656
|
+
this.generateYouTubeFeed(container, template, cachedData, allowShorts, language);
|
|
653
657
|
return;
|
|
654
658
|
}
|
|
655
659
|
|
|
@@ -673,7 +677,7 @@
|
|
|
673
677
|
this.cache.set(cacheKey, data);
|
|
674
678
|
bbContents.utils.log('Données YouTube mises en cache pour 24h (économie API)');
|
|
675
679
|
|
|
676
|
-
this.generateYouTubeFeed(container, template, data, allowShorts);
|
|
680
|
+
this.generateYouTubeFeed(container, template, data, allowShorts, language);
|
|
677
681
|
})
|
|
678
682
|
.catch(error => {
|
|
679
683
|
bbContents.utils.log('Erreur dans le module youtube:', error);
|
|
@@ -696,7 +700,7 @@
|
|
|
696
700
|
});
|
|
697
701
|
},
|
|
698
702
|
|
|
699
|
-
generateYouTubeFeed: function(container, template, data, allowShorts) {
|
|
703
|
+
generateYouTubeFeed: function(container, template, data, allowShorts, language = 'fr') {
|
|
700
704
|
if (!data.items || data.items.length === 0) {
|
|
701
705
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Aucune vidéo trouvée</div>';
|
|
702
706
|
return;
|
|
@@ -725,7 +729,7 @@
|
|
|
725
729
|
clone.style.display = ''; // Rendre visible
|
|
726
730
|
|
|
727
731
|
// Remplir les données
|
|
728
|
-
this.fillVideoData(clone, videoId, snippet);
|
|
732
|
+
this.fillVideoData(clone, videoId, snippet, language);
|
|
729
733
|
|
|
730
734
|
// Ajouter au conteneur
|
|
731
735
|
container.appendChild(clone);
|
|
@@ -734,7 +738,7 @@
|
|
|
734
738
|
bbContents.utils.log(`YouTube Feed généré: ${videos.length} vidéos`);
|
|
735
739
|
},
|
|
736
740
|
|
|
737
|
-
fillVideoData: function(element, videoId, snippet) {
|
|
741
|
+
fillVideoData: function(element, videoId, snippet, language = 'fr') {
|
|
738
742
|
// Remplir le lien directement sur l'élément (link block)
|
|
739
743
|
if (element.tagName === 'A' || element.hasAttribute('bb-youtube-item')) {
|
|
740
744
|
element.href = `https://www.youtube.com/watch?v=${videoId}`;
|
|
@@ -799,7 +803,7 @@
|
|
|
799
803
|
// Remplir la date
|
|
800
804
|
const date = element.querySelector('[bb-youtube-date]');
|
|
801
805
|
if (date) {
|
|
802
|
-
date.textContent = this.formatDate(snippet.publishedAt);
|
|
806
|
+
date.textContent = this.formatDate(snippet.publishedAt, language);
|
|
803
807
|
}
|
|
804
808
|
|
|
805
809
|
// Remplir le nom de la chaîne
|
|
@@ -809,17 +813,54 @@
|
|
|
809
813
|
}
|
|
810
814
|
},
|
|
811
815
|
|
|
812
|
-
formatDate: function(dateString) {
|
|
816
|
+
formatDate: function(dateString, language = 'fr') {
|
|
813
817
|
const date = new Date(dateString);
|
|
814
818
|
const now = new Date();
|
|
815
819
|
const diffTime = Math.abs(now - date);
|
|
816
820
|
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
|
817
821
|
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
822
|
+
// Traductions
|
|
823
|
+
const translations = {
|
|
824
|
+
fr: {
|
|
825
|
+
day: 'jour',
|
|
826
|
+
days: 'jours',
|
|
827
|
+
week: 'semaine',
|
|
828
|
+
weeks: 'semaines',
|
|
829
|
+
month: 'mois',
|
|
830
|
+
months: 'mois',
|
|
831
|
+
year: 'an',
|
|
832
|
+
years: 'ans',
|
|
833
|
+
ago: 'Il y a'
|
|
834
|
+
},
|
|
835
|
+
en: {
|
|
836
|
+
day: 'day',
|
|
837
|
+
days: 'days',
|
|
838
|
+
week: 'week',
|
|
839
|
+
weeks: 'weeks',
|
|
840
|
+
month: 'month',
|
|
841
|
+
months: 'months',
|
|
842
|
+
year: 'year',
|
|
843
|
+
years: 'years',
|
|
844
|
+
ago: 'ago'
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
|
|
848
|
+
const t = translations[language] || translations.fr;
|
|
849
|
+
|
|
850
|
+
if (diffDays === 1) return `${t.ago} 1 ${t.day}`;
|
|
851
|
+
if (diffDays < 7) return `${t.ago} ${diffDays} ${t.days}`;
|
|
852
|
+
|
|
853
|
+
const weeks = Math.floor(diffDays / 7);
|
|
854
|
+
if (weeks === 1) return `${t.ago} 1 ${t.week}`;
|
|
855
|
+
if (diffDays < 30) return `${t.ago} ${weeks} ${t.weeks}`;
|
|
856
|
+
|
|
857
|
+
const months = Math.floor(diffDays / 30);
|
|
858
|
+
if (months === 1) return `${t.ago} 1 ${t.month}`;
|
|
859
|
+
if (diffDays < 365) return `${t.ago} ${months} ${t.months}`;
|
|
860
|
+
|
|
861
|
+
const years = Math.floor(diffDays / 365);
|
|
862
|
+
if (years === 1) return `${t.ago} 1 ${t.year}`;
|
|
863
|
+
return `${t.ago} ${years} ${t.years}`;
|
|
823
864
|
},
|
|
824
865
|
|
|
825
866
|
// Fonction pour décoder les entités HTML
|
|
@@ -887,9 +928,5 @@
|
|
|
887
928
|
// Initialisation
|
|
888
929
|
initBBContents();
|
|
889
930
|
|
|
890
|
-
// Message de confirmation
|
|
891
|
-
console.log(
|
|
892
|
-
'%cBeBranded Contents v' + config.version + ' chargé avec succès !',
|
|
893
|
-
'color: #422eff; font-weight: bold; font-size: 14px;'
|
|
894
|
-
);
|
|
931
|
+
// Message de confirmation supprimé pour une console plus propre
|
|
895
932
|
})();
|