Files
indiekit-endpoint-youtube/views/youtube.njk
Ricardo 8139bef1d4 feat: multi-channel support in admin dashboard UI
- Dashboard now fetches and displays all configured channels
- Each channel shows its own header, live status, and videos
- Channels are separated by visual dividers
- Backward compatible with single-channel config
- Version bump to 1.2.0

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 17:08:37 +01:00

392 lines
12 KiB
Plaintext

{% extends "document.njk" %}
{% block content %}
<style>
.yt-section { margin-bottom: 2rem; }
.yt-section h2 { margin-bottom: 1rem; }
/* Channel header */
.yt-channel {
display: flex;
gap: 1rem;
padding: 1rem;
background: var(--color-offset, #f5f5f5);
border-radius: 0.5rem;
align-items: center;
margin-bottom: 1.5rem;
}
.yt-channel__avatar {
width: 64px;
height: 64px;
border-radius: 50%;
object-fit: cover;
flex-shrink: 0;
}
.yt-channel__info { flex: 1; }
.yt-channel__name {
font-weight: 600;
font-size: 1.125rem;
margin: 0 0 0.25rem 0;
}
.yt-channel__stats {
display: flex;
gap: 1rem;
font-size: 0.875rem;
color: var(--color-text-secondary, #666);
}
/* Live status badge */
.yt-live-badge {
display: inline-flex;
align-items: center;
gap: 0.5rem;
padding: 0.25rem 0.75rem;
border-radius: 2rem;
font-size: 0.75rem;
font-weight: 600;
text-transform: uppercase;
}
.yt-live-badge--live {
background: #ff0000;
color: white;
animation: yt-pulse 2s infinite;
}
.yt-live-badge--upcoming {
background: #065fd4;
color: white;
}
.yt-live-badge--offline {
background: var(--color-offset, #e5e5e5);
color: var(--color-text-secondary, #666);
}
@keyframes yt-pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.7; }
}
.yt-live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
}
/* Live stream card */
.yt-live-stream {
display: flex;
gap: 1rem;
padding: 1rem;
background: linear-gradient(135deg, #ff000010, #ff000005);
border: 1px solid #ff000030;
border-radius: 0.5rem;
margin-bottom: 1.5rem;
}
.yt-live-stream__thumb {
width: 160px;
height: 90px;
object-fit: cover;
border-radius: 0.25rem;
flex-shrink: 0;
}
.yt-live-stream__info { flex: 1; }
.yt-live-stream__title {
font-weight: 600;
margin: 0 0 0.5rem 0;
}
.yt-live-stream__title a {
color: inherit;
text-decoration: none;
}
.yt-live-stream__title a:hover { text-decoration: underline; }
/* Video grid */
.yt-video-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 1rem;
list-style: none;
padding: 0;
margin: 0;
}
.yt-video {
display: flex;
flex-direction: column;
background: var(--color-offset, #f5f5f5);
border-radius: 0.5rem;
overflow: hidden;
}
.yt-video__thumb-wrapper {
position: relative;
aspect-ratio: 16/9;
}
.yt-video__thumb {
width: 100%;
height: 100%;
object-fit: cover;
}
.yt-video__duration {
position: absolute;
bottom: 0.5rem;
right: 0.5rem;
background: rgba(0, 0, 0, 0.8);
color: white;
padding: 0.125rem 0.375rem;
border-radius: 0.25rem;
font-size: 0.75rem;
font-weight: 500;
}
.yt-video__info {
padding: 0.75rem;
flex: 1;
display: flex;
flex-direction: column;
}
.yt-video__title {
font-weight: 500;
font-size: 0.875rem;
margin: 0 0 0.5rem 0;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.yt-video__title a {
color: inherit;
text-decoration: none;
}
.yt-video__title a:hover { text-decoration: underline; }
.yt-video__meta {
font-size: 0.75rem;
color: var(--color-text-secondary, #666);
margin-top: auto;
}
/* Public link banner */
.yt-public-link {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1rem;
background: var(--color-offset, #f5f5f5);
border-radius: 0.5rem;
margin-top: 2rem;
}
.yt-public-link p {
margin: 0;
color: var(--color-text-secondary, #666);
}
</style>
{% if error %}
{{ prose({ text: error.message }) }}
{% elif isMultiChannel and channelsData %}
{# Multi-channel mode: show all channels #}
{% for chData in channelsData %}
<div class="yt-channel-section" style="{% if not loop.first %}margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--color-border, #e5e5e5);{% endif %}">
{# Channel Header #}
{% if chData.error %}
<div class="yt-channel" style="border: 1px solid #ff6b6b;">
<div class="yt-channel__info">
<h2 class="yt-channel__name">{{ chData.name }}</h2>
<p style="color: #ff6b6b; margin: 0;">Error: {{ chData.error }}</p>
</div>
</div>
{% elif chData.channel %}
<div class="yt-channel">
{% if chData.channel.thumbnail %}
<img src="{{ chData.channel.thumbnail }}" alt="" class="yt-channel__avatar">
{% endif %}
<div class="yt-channel__info">
<h2 class="yt-channel__name">{{ chData.channel.title }}</h2>
<div class="yt-channel__stats">
<span>{{ chData.channel.subscriberCount }} {{ __("youtube.subscribers") }}</span>
<span>{{ chData.channel.videoCount }} videos</span>
</div>
</div>
{% if chData.isLive %}
<span class="yt-live-badge yt-live-badge--live">
<span class="yt-live-dot"></span>
{{ __("youtube.live") }}
</span>
{% elif chData.isUpcoming %}
<span class="yt-live-badge yt-live-badge--upcoming">
{{ __("youtube.upcoming") }}
</span>
{% else %}
<span class="yt-live-badge yt-live-badge--offline">
{{ __("youtube.offline") }}
</span>
{% endif %}
</div>
{# Live Stream (if live) #}
{% if chData.liveStatus and (chData.liveStatus.isLive or chData.liveStatus.isUpcoming) %}
<section class="yt-section">
<h3>{% if chData.liveStatus.isLive %}{{ __("youtube.live") }}{% else %}{{ __("youtube.upcoming") }}{% endif %}</h3>
<div class="yt-live-stream">
{% if chData.liveStatus.thumbnail %}
<img src="{{ chData.liveStatus.thumbnail }}" alt="" class="yt-live-stream__thumb">
{% endif %}
<div class="yt-live-stream__info">
<h4 class="yt-live-stream__title">
<a href="https://www.youtube.com/watch?v={{ chData.liveStatus.videoId }}" target="_blank" rel="noopener">
{{ chData.liveStatus.title }}
</a>
</h4>
{{ button({
href: "https://www.youtube.com/watch?v=" + chData.liveStatus.videoId,
text: __("youtube.watchNow"),
target: "_blank"
}) }}
</div>
</div>
</section>
{% endif %}
{# Latest Videos #}
<section class="yt-section">
<h3>{{ __("youtube.videos") }}</h3>
{% if chData.videos and chData.videos.length > 0 %}
<ul class="yt-video-grid">
{% for video in chData.videos %}
<li class="yt-video">
<div class="yt-video__thumb-wrapper">
<a href="{{ video.url }}" target="_blank" rel="noopener">
<img src="{{ video.thumbnail }}" alt="" class="yt-video__thumb" loading="lazy">
</a>
{% if video.durationFormatted and not video.isLive %}
<span class="yt-video__duration">{{ video.durationFormatted }}</span>
{% elif video.isLive %}
<span class="yt-video__duration" style="background:#ff0000">LIVE</span>
{% endif %}
</div>
<div class="yt-video__info">
<h4 class="yt-video__title">
<a href="{{ video.url }}" target="_blank" rel="noopener">{{ video.title }}</a>
</h4>
<div class="yt-video__meta">
{{ video.viewCount }} {{ __("youtube.views") }}
</div>
</div>
</li>
{% endfor %}
</ul>
{% else %}
{{ prose({ text: __("youtube.noVideos") }) }}
{% endif %}
</section>
{# Link to YouTube channel #}
<div class="yt-public-link" style="margin-top: 1rem;">
<p>{{ __("youtube.widget.description") }}</p>
{{ button({
href: "https://www.youtube.com/channel/" + chData.channel.id,
text: __("youtube.widget.view"),
target: "_blank"
}) }}
</div>
{% endif %}
</div>
{% endfor %}
{% else %}
{# Single channel mode (backward compatible) #}
{# Channel Header #}
{% if channel %}
<div class="yt-channel">
{% if channel.thumbnail %}
<img src="{{ channel.thumbnail }}" alt="" class="yt-channel__avatar">
{% endif %}
<div class="yt-channel__info">
<h2 class="yt-channel__name">{{ channel.title }}</h2>
<div class="yt-channel__stats">
<span>{{ channel.subscriberCount }} {{ __("youtube.subscribers") }}</span>
<span>{{ channel.videoCount }} videos</span>
</div>
</div>
{% if isLive %}
<span class="yt-live-badge yt-live-badge--live">
<span class="yt-live-dot"></span>
{{ __("youtube.live") }}
</span>
{% elif isUpcoming %}
<span class="yt-live-badge yt-live-badge--upcoming">
{{ __("youtube.upcoming") }}
</span>
{% else %}
<span class="yt-live-badge yt-live-badge--offline">
{{ __("youtube.offline") }}
</span>
{% endif %}
</div>
{% endif %}
{# Live Stream (if live) #}
{% if liveStatus and (liveStatus.isLive or liveStatus.isUpcoming) %}
<section class="yt-section">
<h2>{% if liveStatus.isLive %}{{ __("youtube.live") }}{% else %}{{ __("youtube.upcoming") }}{% endif %}</h2>
<div class="yt-live-stream">
{% if liveStatus.thumbnail %}
<img src="{{ liveStatus.thumbnail }}" alt="" class="yt-live-stream__thumb">
{% endif %}
<div class="yt-live-stream__info">
<h3 class="yt-live-stream__title">
<a href="https://www.youtube.com/watch?v={{ liveStatus.videoId }}" target="_blank" rel="noopener">
{{ liveStatus.title }}
</a>
</h3>
{{ button({
href: "https://www.youtube.com/watch?v=" + liveStatus.videoId,
text: __("youtube.watchNow"),
target: "_blank"
}) }}
</div>
</div>
</section>
{% endif %}
{# Latest Videos #}
<section class="yt-section">
<h2>{{ __("youtube.videos") }}</h2>
{% if videos and videos.length > 0 %}
<ul class="yt-video-grid">
{% for video in videos %}
<li class="yt-video">
<div class="yt-video__thumb-wrapper">
<a href="{{ video.url }}" target="_blank" rel="noopener">
<img src="{{ video.thumbnail }}" alt="" class="yt-video__thumb" loading="lazy">
</a>
{% if video.durationFormatted and not video.isLive %}
<span class="yt-video__duration">{{ video.durationFormatted }}</span>
{% elif video.isLive %}
<span class="yt-video__duration" style="background:#ff0000">LIVE</span>
{% endif %}
</div>
<div class="yt-video__info">
<h3 class="yt-video__title">
<a href="{{ video.url }}" target="_blank" rel="noopener">{{ video.title }}</a>
</h3>
<div class="yt-video__meta">
{{ video.viewCount }} {{ __("youtube.views") }}
</div>
</div>
</li>
{% endfor %}
</ul>
{% else %}
{{ prose({ text: __("youtube.noVideos") }) }}
{% endif %}
</section>
{# Link to YouTube channel #}
{% if channel %}
<div class="yt-public-link">
<p>{{ __("youtube.widget.description") }}</p>
{{ button({
href: "https://www.youtube.com/channel/" + channel.id,
text: __("youtube.widget.view"),
target: "_blank"
}) }}
</div>
{% endif %}
{% endif %}
{% endblock %}