1// Site Settings Loader - Fetches settings from Firestore and applies to the page 2import { firebaseConfig } from './firebase-config.js'; 3 4// Default settings (fallback if Firestore fails) 5const defaultSettings = { 6 socialTwitter: 'https://x.com/ServeAndLeadHQ', 7 socialLinkedin: 'https://www.linkedin.com/company/serve-lead/', 8 socialInstagram: 'https://www.instagram.com/serveandlead/', 9 socialYoutube: 'https://www.youtube.com/@ServeAndLeadHQ', 10 substackUrl: 'https://serveandlead.substack.com', 11 paypalUrl: 'https://paypal.me/ServeAndLead', 12 stripeUrl: 'https://donate.stripe.com/9B6bIUaPs9PHbON5vR7AI00' 13}; 14 15let siteSettings = null; 16 17// Load settings from Firestore 18async function loadSiteSettings() { 19 // Check if already loaded 20 if (siteSettings) return siteSettings; 21 22 // Check if config is set up 23 if (firebaseConfig.apiKey === "YOUR_API_KEY") { 24 console.warn('Firebase not configured, using default settings'); 25 siteSettings = defaultSettings; 26 return siteSettings; 27 } 28 29 try { 30 const { initializeApp } = await import('https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js'); 31 const { getFirestore, doc, getDoc } = await import('https://www.gstatic.com/firebasejs/10.7.1/firebase-firestore.js'); 32 33 const app = initializeApp(firebaseConfig); 34 const db = getFirestore(app); 35 36 const docRef = doc(db, 'site_settings', 'main'); 37 const docSnap = await getDoc(docRef); 38 39 if (docSnap.exists()) { 40 siteSettings = { ...defaultSettings, ...docSnap.data() }; 41 } else { 42 siteSettings = defaultSettings; 43 } 44 } catch (error) { 45 console.error('Error loading site settings:', error); 46 siteSettings = defaultSettings; 47 } 48 49 return siteSettings; 50} 51 52// Apply settings to page elements 53function applySettings(settings) { 54 // Social Links 55 document.querySelectorAll('[data-setting="socialTwitter"]').forEach(el => { 56 if (settings.socialTwitter) el.href = settings.socialTwitter; 57 }); 58 59 document.querySelectorAll('[data-setting="socialLinkedin"]').forEach(el => { 60 if (settings.socialLinkedin) el.href = settings.socialLinkedin; 61 }); 62 63 document.querySelectorAll('[data-setting="socialInstagram"]').forEach(el => { 64 if (settings.socialInstagram) el.href = settings.socialInstagram; 65 }); 66 67 document.querySelectorAll('[data-setting="socialYoutube"]').forEach(el => { 68 if (settings.socialYoutube) el.href = settings.socialYoutube; 69 }); 70 71 // Newsletter/Substack 72 document.querySelectorAll('[data-setting="substackUrl"]').forEach(el => { 73 if (settings.substackUrl) el.href = settings.substackUrl; 74 }); 75 76 document.querySelectorAll('[data-setting="substackSubscribe"]').forEach(el => { 77 if (settings.substackUrl) el.href = settings.substackUrl + '/subscribe'; 78 }); 79 80 // Donation Links 81 document.querySelectorAll('[data-setting="paypalUrl"]').forEach(el => { 82 if (settings.paypalUrl) el.href = settings.paypalUrl; 83 }); 84 85 document.querySelectorAll('[data-setting="stripeUrl"]').forEach(el => { 86 if (settings.stripeUrl) el.href = settings.stripeUrl; 87 }); 88 89 // Contact Emails 90 document.querySelectorAll('[data-setting="speakingEmail"]').forEach(el => { 91 if (settings.speakingEmail) { 92 if (el.tagName === 'A') { 93 el.href = 'mailto:' + settings.speakingEmail; 94 el.textContent = settings.speakingEmail; 95 } else { 96 el.textContent = settings.speakingEmail; 97 } 98 } 99 }); 100} 101 102// Initialize on page load 103async function initSiteSettings() { 104 const settings = await loadSiteSettings(); 105 applySettings(settings); 106} 107 108// Auto-initialize when DOM is ready 109if (document.readyState === 'loading') { 110 document.addEventListener('DOMContentLoaded', initSiteSettings); 111} else { 112 initSiteSettings(); 113} 114 115export { loadSiteSettings, applySettings, siteSettings }; 116
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.