feat(andebol): add /noticias news archive page with hero + category tabs (BIT-624)

New dedicated news listing page for andebol.net inspired by eurohandball.com/news:
- Hero banner with latest featured article (page 1, unfiltered)
- Horizontal category filter tabs (all + domain categories)
- Responsive 3-column article grid with pagination
- Full i18n support (pt-PT / en)
- Uses institutional theme tokens and existing ArticleCard component

Co-Authored-By: Paperclip <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This commit is contained in:
committed 2026-03-30 01:57:27 +00:00
1 parent 4ef03e52ea
commit 7869b25b2a
2 files changed
+444

No files matched your search

+12
View File
@@ -53,6 +53,12 @@ export type UiStrings = {
fpa_col_competition: string;
fpa_agenda_empty: string;
fpa_source_credit: string;
/** News archive page title */
news_archive_title: string;
/** "All" filter label for category tabs */
news_all_filter: string;
/** News archive page meta description */
news_archive_desc: string;
};
const en: UiStrings = {
@@ -104,6 +110,9 @@ const en: UiStrings = {
fpa_col_competition: 'Competition',
fpa_agenda_empty: 'Fixture list is temporarily unavailable.',
fpa_source_credit: 'Data: Portuguese Handball Federation (ws.fpa.pt).',
news_archive_title: 'News',
news_all_filter: 'All',
news_archive_desc: 'Latest news and stories across all sections.',
};
const pt: UiStrings = {
@@ -155,6 +164,9 @@ const pt: UiStrings = {
fpa_col_competition: 'Competição',
fpa_agenda_empty: 'A agenda não está disponível de momento.',
fpa_source_credit: 'Dados: Federação Portuguesa de Andebol (ws.fpa.pt).',
news_archive_title: 'Notícias',
news_all_filter: 'Todas',
news_archive_desc: 'Últimas notícias e histórias de todas as secções.',
};
export function getUiStrings(locale: string): UiStrings {
+432
View File
@@ -0,0 +1,432 @@
---
import Base from '../layouts/Base.astro';
import { getDomainConfig } from '../lib/domain.js';
import { getThemeComponents } from '../lib/theme.js';
import { BridgeClient, MockBridgeClient, bridgeRequestHeaders } from '../lib/bridge.js';
import { getUiStrings } from '../lib/ui-i18n.js';
import { relativeTime, truncate } from '../lib/format.js';
const host = Astro.request.headers.get('host') ?? 'localhost';
const site_host = host.split(':')[0];
const config = getDomainConfig(host);
const { ArticleCard } = getThemeComponents(config.theme);
const ui = getUiStrings(config.locale);
const active_cat = Astro.url.searchParams.get('cat') ?? '';
const page = parseInt(Astro.url.searchParams.get('page') ?? '1', 10);
const per_page = 12;
let bridge: BridgeClient;
try {
bridge = new BridgeClient(config.bridge_endpoint, site_host);
await fetch(`${config.bridge_endpoint}/health`, {
headers: bridgeRequestHeaders(site_host),
signal: AbortSignal.timeout(2000),
});
} catch {
bridge = new MockBridgeClient();
}
/* Hero: show on first page without category filter */
let hero: Awaited<ReturnType<BridgeClient['getHomepage']>>['hero'][number] | null = null;
if (page === 1 && !active_cat) {
try {
const homepage = await bridge.getHomepage();
hero = homepage.hero[0] ?? null;
} catch {
/* fall through */
}
}
/* Paginated article list */
let paginated: Awaited<ReturnType<BridgeClient['getArticles']>>;
try {
paginated = await bridge.getArticles({
category: active_cat || undefined,
page,
per_page,
});
} catch {
paginated = { items: [], total: 0, page: 1, per_page, total_pages: 0 };
}
/* Deduplicate hero from grid */
const grid_items = hero
? paginated.items.filter(a => a.slug !== hero!.slug)
: paginated.items;
const total_pages = paginated.total_pages;
const has_prev = page > 1;
const has_next = page < total_pages;
const categories = config.categories;
/* Canonical URL */
const qs_parts: string[] = [];
if (active_cat) qs_parts.push(`cat=${active_cat}`);
if (page > 1) qs_parts.push(`page=${page}`);
const canonical = `${Astro.url.origin}/noticias${qs_parts.length ? '?' + qs_parts.join('&') : ''}`;
/* Active category label for meta */
const active_cat_label = active_cat
? categories.find(c => c.slug === active_cat)?.label ?? active_cat
: '';
const page_title = active_cat_label
? `${active_cat_label} — ${ui.news_archive_title} — ${config.site_name}`
: `${ui.news_archive_title} — ${config.site_name}`;
/* Pagination link builder */
function paginationHref(p: number): string {
const parts: string[] = [];
if (active_cat) parts.push(`cat=${active_cat}`);
if (p > 1) parts.push(`page=${p}`);
return `/noticias${parts.length ? '?' + parts.join('&') : ''}`;
}
const breadcrumb_schema = {
'@context': 'https://schema.org',
'@type': 'BreadcrumbList',
itemListElement: [
{ '@type': 'ListItem', position: 1, name: ui.breadcrumb_home, item: Astro.url.origin },
{ '@type': 'ListItem', position: 2, name: ui.news_archive_title, item: `${Astro.url.origin}/noticias` },
],
};
---
<Base
config={config}
title={page_title}
description={ui.news_archive_desc}
canonical={canonical}
schema={breadcrumb_schema}
>
{/* ── Hero banner (page 1, no filter) ── */}
{hero && (
<section class="na-hero" aria-label={ui.featured}>
<a href={`/article/${hero.slug}`} class="na-hero__media" aria-hidden="true" tabindex="-1">
{hero.featured_image ? (
<img
src={hero.featured_image}
alt={hero.featured_image_alt}
class="na-hero__img"
loading="eager"
decoding="async"
fetchpriority="high"
width="1200"
height="520"
/>
) : (
<div class="na-hero__img na-hero__placeholder" aria-hidden="true">
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" opacity="0.2">
<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/>
<polyline points="21 15 16 10 5 21"/>
</svg>
</div>
)}
</a>
<div class="na-hero__overlay">
<div class="container">
<a href={`/category/${hero.category.slug}`} class="na-hero__pill">{hero.category.name}</a>
<h1 class="na-hero__title">
<a href={`/article/${hero.slug}`}>{hero.title}</a>
</h1>
<p class="na-hero__excerpt">{truncate(hero.excerpt, 160)}</p>
<div class="na-hero__meta">
<span>{hero.author.name}</span>
<span aria-hidden="true">&middot;</span>
<time datetime={hero.published_at}>{relativeTime(hero.published_at, config.locale)}</time>
<span aria-hidden="true">&middot;</span>
<span>{hero.reading_time} {ui.min_read}</span>
</div>
</div>
</div>
</section>
)}
<div class="container">
{/* ── Page heading (shown when no hero, or when filtering) ── */}
{!hero && (
<header class="na-header">
<h1 class="na-header__title">{active_cat_label || ui.news_archive_title}</h1>
{total_pages > 1 && (
<p class="na-header__count text-muted text-sm">
{paginated.total} {paginated.total === 1 ? ui.article_one : ui.articles_many}
{` — ${ui.pageOf(page, total_pages)}`}
</p>
)}
</header>
)}
{/* ── Category filter tabs ── */}
<nav class="na-tabs" aria-label={ui.sections_categories}>
<div class="na-tabs__scroll">
<a
href="/noticias"
class:list={['na-tabs__pill', !active_cat && 'na-tabs__pill--active']}
aria-current={!active_cat ? 'page' : undefined}
>
{ui.news_all_filter}
</a>
{categories.map(cat => (
<a
href={`/noticias?cat=${cat.slug}`}
class:list={['na-tabs__pill', active_cat === cat.slug && 'na-tabs__pill--active']}
aria-current={active_cat === cat.slug ? 'page' : undefined}
>
{cat.label}
</a>
))}
</div>
</nav>
{/* ── Article grid ── */}
<div class="na-grid" aria-label={`${ui.news_archive_title} articles`}>
{grid_items.map(article => (
<ArticleCard article={article} size="md" show_excerpt={true} locale={config.locale} />
))}
</div>
{grid_items.length === 0 && (
<p class="na-empty">{ui.no_articles_category}</p>
)}
{/* ── Pagination ── */}
{total_pages > 1 && (
<nav class="pagination" aria-label="Pagination">
{has_prev && (
<a
href={paginationHref(page - 1)}
class="pagination__item"
aria-label={ui.prev_page}
>&larr;</a>
)}
{Array.from({ length: Math.min(total_pages, 7) }, (_, i) => {
const p = i + 1;
return (
<a
href={paginationHref(p)}
class="pagination__item"
aria-current={p === page ? 'page' : undefined}
>
{p}
</a>
);
})}
{has_next && (
<a
href={paginationHref(page + 1)}
class="pagination__item"
aria-label={ui.next_page}
>&rarr;</a>
)}
</nav>
)}
</div>
</Base>
<style>
/* ── Hero banner ── */
.na-hero {
position: relative;
overflow: hidden;
background: #0f172a;
}
.na-hero__media {
display: block;
}
.na-hero__img {
width: 100%;
aspect-ratio: 21 / 9;
object-fit: cover;
display: block;
max-height: min(48vh, 480px);
}
@media (max-width: 767px) {
.na-hero__img {
aspect-ratio: 16 / 10;
max-height: none;
}
}
.na-hero__placeholder {
min-height: 260px;
display: flex;
align-items: center;
justify-content: center;
background: #1e293b;
color: #94a3b8;
}
.na-hero__overlay {
position: absolute;
inset: 0;
top: auto;
background: linear-gradient(
to top,
rgba(15, 23, 42, 0.94) 0%,
rgba(15, 23, 42, 0.50) 55%,
transparent 100%
);
padding: var(--space-6) 0 var(--space-8);
display: flex;
flex-direction: column;
}
.na-hero__pill {
align-self: flex-start;
display: inline-block;
padding: 0.2rem 0.65rem;
border-radius: 999px;
font-size: 0.7rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.06em;
text-decoration: none;
background: var(--color-secondary);
color: #fff;
}
.na-hero__title {
font-family: var(--font-heading, inherit);
font-size: clamp(1.5rem, 4vw, 2.35rem);
font-weight: 600;
line-height: 1.2;
margin: var(--space-3) 0 0;
}
.na-hero__title a {
color: #fff;
text-decoration: none;
transition: opacity 0.15s ease;
}
.na-hero__title a:hover {
opacity: 0.88;
}
.na-hero__excerpt {
font-size: var(--text-sm);
color: rgba(255, 255, 255, 0.82);
line-height: 1.55;
margin: var(--space-2) 0 0;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
@media (max-width: 640px) {
.na-hero__excerpt {
display: none;
}
}
.na-hero__meta {
display: flex;
flex-wrap: wrap;
gap: var(--space-2);
align-items: center;
font-size: var(--text-xs);
color: rgba(255, 255, 255, 0.72);
margin-top: var(--space-3);
}
/* ── Page header (no hero) ── */
.na-header {
padding: var(--space-6) 0 var(--space-4);
border-bottom: 3px solid var(--color-primary);
margin-bottom: var(--space-2);
}
.na-header__title {
font-family: var(--font-heading, inherit);
font-size: clamp(1.75rem, 4vw, 3rem);
font-weight: 900;
margin-bottom: var(--space-2);
}
.na-header__count {
margin: 0;
}
/* ── Category tabs ── */
.na-tabs {
padding: var(--space-5) 0 var(--space-6);
border-bottom: 1px solid var(--color-border);
margin-bottom: var(--space-6);
}
.na-tabs__scroll {
display: flex;
gap: var(--space-2);
overflow-x: auto;
-webkit-overflow-scrolling: touch;
scrollbar-width: none;
padding-bottom: var(--space-1);
}
.na-tabs__scroll::-webkit-scrollbar {
display: none;
}
.na-tabs__pill {
flex-shrink: 0;
display: inline-flex;
align-items: center;
padding: 0.45rem 1rem;
border-radius: 999px;
font-family: var(--font-heading, inherit);
font-size: var(--text-sm);
font-weight: 600;
text-decoration: none;
color: var(--color-text-muted);
background: var(--color-bg-secondary);
border: 1px solid var(--color-border);
transition:
background 0.15s ease,
color 0.15s ease,
border-color 0.15s ease;
}
.na-tabs__pill:hover {
color: var(--color-primary);
border-color: var(--color-secondary);
background: var(--color-bg);
}
.na-tabs__pill--active {
color: #fff;
background: var(--color-primary);
border-color: var(--color-primary);
}
.na-tabs__pill--active:hover {
color: #fff;
background: var(--color-primary);
border-color: var(--color-primary);
}
/* ── Article grid ── */
.na-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: var(--space-5);
margin-bottom: var(--space-8);
}
@media (min-width: 1024px) {
.na-grid {
grid-template-columns: repeat(3, 1fr);
}
}
.na-empty {
text-align: center;
padding: var(--space-12);
color: var(--color-text-muted);
font-size: var(--text-lg);
}
</style>