Show latest 3 YouTube videos in social section (live via API, static fallback)

This commit is contained in:
Z User 2026-11-04 18:54:45 +00:00
parent a15c54df06
commit e8f2ee5231

View File

@ -140,6 +140,64 @@
transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
}
.yt-video-thumb {
position: relative;
aspect-ratio: 16 / 9;
overflow: hidden;
}
.yt-video-thumb img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
}
.yt-video:hover .yt-video-thumb img {
transform: scale(1.05);
}
.yt-play-chip {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
background: rgba(2, 6, 23, 0.35);
transition: background 200ms ease;
}
.yt-video:hover .yt-play-chip {
background: rgba(2, 6, 23, 0.15);
}
.yt-play-chip svg {
width: 52px;
height: 52px;
color: #ffffff;
filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
}
.yt-video:hover .yt-play-chip svg {
transform: scale(1.1);
}
.yt-embed {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
border: 0;
}
.yt-video-title {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.nav-scrolled {
background: rgba(15, 23, 42, 0.95);
box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.2);
@ -1634,6 +1692,15 @@
as they happen.</p>
</a>
</div>
<div class="max-w-4xl mx-auto mt-14">
<div class="flex items-end justify-between mb-6">
<h3 class="text-2xl font-semibold" style="font-family: 'Space Grotesk', sans-serif;">Latest
videos</h3>
<a href="https://www.youtube.com/@RobertAbbott-v7o/videos" target="_blank" rel="noopener"
class="dl-req-link">View all on YouTube</a>
</div>
<div id="ytVideoGrid" class="grid grid-cols-1 sm:grid-cols-3 gap-6"></div>
</div>
</div>
</section>
@ -3078,6 +3145,80 @@
});
}
// SOCIAL: latest YouTube uploads from @RobertAbbott-v7o
const YT_CHANNEL_ID = 'UCG_ZDOP21i0Ah26FxiuZmkg';
// Static snapshot — used only if /api/youtube/latest is unreachable, so the
// section never renders empty. Refresh occasionally as videos are posted.
const YT_FALLBACK_VIDEOS = [
{ id: 'Bw0tDBVo_XI', title: 'GLM 5.2 runs without a graphics card?!', published: '2026-11-04T01:11:20+00:00' },
{ id: 'RyDbc8bQ1o0', title: 'Run GLM 5.2 on a laptop', published: '2026-11-03T01:23:02+00:00' },
{ id: 'GPRSTGsTijo', title: 'Render 1080p AI videos in minutes with Moxiegen Multimedia #comfyui', published: '2026-10-20T07:25:29+00:00' }
];
function ytTimeAgo(iso) {
if (!iso) return '';
const s = Math.max(0, (Date.now() - new Date(iso).getTime()) / 1000);
const d = Math.floor(s / 86400);
if (d < 1) return 'today';
if (d === 1) return 'yesterday';
if (d < 30) return d + ' days ago';
const m = Math.floor(d / 30);
if (m < 12) return m + (m === 1 ? ' month ago' : ' months ago');
const y = Math.floor(d / 365);
return y + (y === 1 ? ' year ago' : ' years ago');
}
function ytEscape(s) {
return String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;')
.replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
}
function renderYtVideos(videos) {
const grid = document.getElementById('ytVideoGrid');
if (!grid) return;
grid.innerHTML = videos.map(v => {
if (!v || !/^[A-Za-z0-9_-]{11}$/.test(v.id)) return ''; // sanity guard on the id
return `
<article class="yt-video bg-slate-950 border border-slate-800 rounded-3xl overflow-hidden hover:border-emerald-400/30">
<div class="yt-video-thumb cursor-pointer" role="button" tabindex="0"
aria-label="Play video: ${ytEscape(v.title)}"
onclick="playYtVideo(this, '${v.id}')"
onkeydown="if(event.key==='Enter'||event.key===' '){event.preventDefault();playYtVideo(this,'${v.id}');}">
<img src="https://i.ytimg.com/vi/${v.id}/hqdefault.jpg" alt="${ytEscape(v.title)}" loading="lazy">
<span class="yt-play-chip">
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M8 5v14l11-7z"/></svg>
</span>
</div>
<div class="p-5">
<h4 class="yt-video-title font-medium leading-snug">${ytEscape(v.title)}</h4>
<p class="text-slate-500 text-sm mt-2">${ytTimeAgo(v.published)}</p>
</div>
</article>`;
}).join('');
}
function playYtVideo(el, videoId) {
if (!/^[A-Za-z0-9_-]{11}$/.test(videoId)) return;
const thumb = el.classList && el.classList.contains('yt-video-thumb') ? el : el.querySelector('.yt-video-thumb');
if (!thumb || thumb.querySelector('iframe')) return;
thumb.innerHTML = `<iframe class="yt-embed" src="https://www.youtube-nocookie.com/embed/${videoId}?autoplay=1&rel=0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>`;
}
async function initYtVideos() {
let videos = YT_FALLBACK_VIDEOS;
try {
const ctrl = new AbortController();
const timer = setTimeout(() => ctrl.abort(), 6000);
const res = await fetch('/api/youtube/latest', { signal: ctrl.signal });
clearTimeout(timer);
const json = await res.json();
if (res.ok && json && json.success && Array.isArray(json.data && json.data.videos) && json.data.videos.length) {
videos = json.data.videos;
}
} catch (err) { /* backend unreachable -> static snapshot */ }
renderYtVideos(videos);
}
window.addEventListener('load', () => {
initScrollAnimations();
initBalloon();
@ -3085,6 +3226,7 @@
initContactForm();
initCopyButtons();
renderHowtoVideos();
initYtVideos();
});
</script>
<script src="js/config.js"></script>