mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
31 lines
946 B
JavaScript
31 lines
946 B
JavaScript
|
|
function renderList(container, items, templateFn, emptyMessage) {
|
||
|
|
if (!items.length) {
|
||
|
|
container.innerHTML = `<p class="empty">${escapeHtml(emptyMessage || 'Rien à afficher pour le moment.')}</p>`;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
container.innerHTML = items.map(templateFn).join('');
|
||
|
|
}
|
||
|
|
|
||
|
|
function escapeHtml(str) {
|
||
|
|
return String(str ?? '').replace(/[&<>"']/g, (c) => ({
|
||
|
|
'&': '&', '<': '<', '>': '>', '"': '"', "'": ''',
|
||
|
|
}[c]));
|
||
|
|
}
|
||
|
|
|
||
|
|
function youtubeEmbedUrl(url) {
|
||
|
|
try {
|
||
|
|
const parsed = new URL(url);
|
||
|
|
let videoId = null;
|
||
|
|
if (parsed.hostname === 'youtu.be') {
|
||
|
|
videoId = parsed.pathname.slice(1);
|
||
|
|
} else if (parsed.pathname === '/watch') {
|
||
|
|
videoId = parsed.searchParams.get('v');
|
||
|
|
} else if (parsed.pathname.startsWith('/embed/')) {
|
||
|
|
videoId = parsed.pathname.split('/embed/')[1];
|
||
|
|
}
|
||
|
|
return videoId ? `https://www.youtube.com/embed/${videoId}` : null;
|
||
|
|
} catch {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|