fix(frontend): force pt-PT locale and handball-only for andebol.net (BIT-25555) #24
No files matched your search
@@ -2,13 +2,9 @@ import type { FastifyRequest } from 'fastify';
|
||||
|
||||
/**
|
||||
* Public site hostname for domain config + cache keys.
|
||||
* SSR calls the bridge on loopback; the browser Host is forwarded via X-Site-Host.
|
||||
* Resolved from the HTTP Host header (nginx preserves $host on /api/ proxy).
|
||||
*/
|
||||
export function resolve_site_host(req: FastifyRequest): string {
|
||||
const raw = req.headers['x-site-host'];
|
||||
if (typeof raw === 'string' && raw.trim()) {
|
||||
return raw.split(':')[0].toLowerCase();
|
||||
}
|
||||
const hostname = req.hostname ?? 'localhost';
|
||||
return hostname.replace(/:\d+$/, '').toLowerCase();
|
||||
}
|
||||
@@ -4,9 +4,7 @@
|
||||
"role": "AI News Writer",
|
||||
"domain": "andebol.net",
|
||||
"topics": [
|
||||
"Andebol",
|
||||
"Futebol",
|
||||
"Desportos"
|
||||
"Andebol"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
|
||||
@@ -5,8 +5,15 @@
|
||||
HOST=0.0.0.0
|
||||
PORT=4321
|
||||
|
||||
# Bridge API base URL (internal, from Astro server-side)
|
||||
# Bridge API base URL — used by Astro SSR when BRIDGE_INTERNAL_URL is not set.
|
||||
BRIDGE_API_URL=http://127.0.0.1:3200
|
||||
|
||||
# Domain JSON directory (SSR must resolve andebol.net vs newsproject — BIT-25555)
|
||||
DOMAINS_CONFIG_PATH=/opt/news-platform/config/domains
|
||||
|
||||
# Direct loopback override for bridge calls. Set this when the CT cannot resolve the
|
||||
# public hostname (e.g. andebol.net) back to itself via DNS. Overrides nginx-routed calls.
|
||||
BRIDGE_INTERNAL_URL=http://127.0.0.1:3200
|
||||
|
||||
# Site domain (used for canonical URLs, sitemaps, etc.)
|
||||
SITE_URL=https://newsproject.bitreport.pt
|
||||
@@ -8,36 +8,49 @@ interface Props {
|
||||
locale: string;
|
||||
/** When false, parent layout already renders a localized breadcrumb (e.g. institutional theme). */
|
||||
showBreadcrumb?: boolean;
|
||||
/** meta-only: skip title/excerpt (rendered in masthead/hero); full: default article header */
|
||||
variant?: 'full' | 'meta-only';
|
||||
/** Light text for hero overlay */
|
||||
theme?: 'default' | 'dark';
|
||||
}
|
||||
const { article, locale, showBreadcrumb = true } = Astro.props;
|
||||
|
||||
const {
|
||||
article,
|
||||
locale,
|
||||
showBreadcrumb = true,
|
||||
variant = 'full',
|
||||
theme = 'default',
|
||||
} = Astro.props;
|
||||
const ui = getUiStrings(locale);
|
||||
const is_meta_only = variant === 'meta-only';
|
||||
const is_dark = theme === 'dark';
|
||||
---
|
||||
<header class="article-header">
|
||||
{showBreadcrumb && (
|
||||
<nav class="breadcrumb" aria-label={ui.aria_breadcrumb}>
|
||||
<a href="/">{ui.breadcrumb_home}</a>
|
||||
<span class="breadcrumb__sep" aria-hidden="true">/</span>
|
||||
<a href={`/category/${article.category.slug}`}>{article.category.name}</a>
|
||||
<span class="breadcrumb__sep" aria-hidden="true">/</span>
|
||||
<span aria-current="page">{article.title}</span>
|
||||
</nav>
|
||||
<header class:list={['article-header', is_meta_only && 'article-header--meta', is_dark && 'article-header--dark']}>
|
||||
{showBreadcrumb && !is_meta_only && (
|
||||
<nav class="breadcrumb" aria-label={ui.aria_breadcrumb}>
|
||||
<a href="/">{ui.breadcrumb_home}</a>
|
||||
<span class="breadcrumb__sep" aria-hidden="true">/</span>
|
||||
<a href={`/category/${article.category.slug}`}>{article.category.name}</a>
|
||||
<span class="breadcrumb__sep" aria-hidden="true">/</span>
|
||||
<span aria-current="page">{article.title}</span>
|
||||
</nav>
|
||||
)}
|
||||
|
||||
<!-- Category -->
|
||||
<div class="article-header__cats">
|
||||
<a href={`/category/${article.category.slug}`} class="badge">{article.category.name}</a>
|
||||
{article.tags.slice(0, 3).map(tag => (
|
||||
<span class="badge badge--muted">{tag.name}</span>
|
||||
))}
|
||||
</div>
|
||||
{!is_meta_only && (
|
||||
<>
|
||||
<div class="article-header__cats">
|
||||
<a href={`/category/${article.category.slug}`} class="badge">{article.category.name}</a>
|
||||
{article.tags.slice(0, 3).map(tag => (
|
||||
<span class="badge badge--muted">{tag.name}</span>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<!-- Title -->
|
||||
<h1 class="article-header__title">{article.title}</h1>
|
||||
<h1 class="article-header__title">{article.title}</h1>
|
||||
|
||||
<!-- Excerpt -->
|
||||
<p class="article-header__excerpt">{article.excerpt}</p>
|
||||
{article.excerpt && <p class="article-header__excerpt">{article.excerpt}</p>}
|
||||
</>
|
||||
)}
|
||||
|
||||
<!-- Meta -->
|
||||
<div class="article-header__meta">
|
||||
<div class="article-header__author">
|
||||
{article.author.avatar ? (
|
||||
@@ -89,6 +102,24 @@ const ui = getUiStrings(locale);
|
||||
margin-bottom: var(--space-6);
|
||||
}
|
||||
|
||||
.article-header--meta {
|
||||
padding-bottom: 0;
|
||||
border-bottom: none;
|
||||
margin-bottom: 0;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.article-header--dark .article-header__author-name,
|
||||
.article-header--dark .article-header__date,
|
||||
.article-header--dark .article-header__reading {
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
}
|
||||
|
||||
.article-header--dark .article-header__avatar--placeholder {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border: 2px solid rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
.article-header__cats {
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
@@ -167,5 +198,23 @@ const ui = getUiStrings(locale);
|
||||
font-size: var(--text-sm);
|
||||
color: var(--color-text-muted);
|
||||
white-space: nowrap;
|
||||
padding: 0.35em 0.75em;
|
||||
background: var(--color-bg-secondary);
|
||||
border-radius: 999px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.article-header--dark .article-header__reading {
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
}
|
||||
|
||||
.article-header--meta .article-header__reading {
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.article-header--dark.article-header--meta .article-header__reading {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
padding: 0.35em 0.75em;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,143 @@
|
||||
---
|
||||
import { getUiStrings } from '../../lib/ui-i18n.js';
|
||||
|
||||
interface Props {
|
||||
url: string;
|
||||
title: string;
|
||||
locale: string;
|
||||
}
|
||||
|
||||
const { url, title, locale } = Astro.props;
|
||||
const ui = getUiStrings(locale);
|
||||
const encoded_url = encodeURIComponent(url);
|
||||
const encoded_title = encodeURIComponent(title);
|
||||
---
|
||||
<div class="article-share" role="group" aria-label={ui.share_heading}>
|
||||
<span class="article-share__label">{ui.share_heading}</span>
|
||||
<div class="article-share__actions">
|
||||
<button type="button" class="article-share__btn" data-share="copy" data-url={url} title={ui.share_copy}>
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
||||
<rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
|
||||
</svg>
|
||||
<span class="article-share__btn-text">{ui.share_copy}</span>
|
||||
</button>
|
||||
<a
|
||||
href={`https://twitter.com/intent/tweet?url=${encoded_url}&text=${encoded_title}`}
|
||||
class="article-share__btn"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
title={ui.share_twitter}
|
||||
>
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
||||
<path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/>
|
||||
</svg>
|
||||
<span class="sr-only">{ui.share_twitter}</span>
|
||||
</a>
|
||||
<a
|
||||
href={`https://www.facebook.com/sharer/sharer.php?u=${encoded_url}`}
|
||||
class="article-share__btn"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
title={ui.share_facebook}
|
||||
>
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
||||
<path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/>
|
||||
</svg>
|
||||
<span class="sr-only">{ui.share_facebook}</span>
|
||||
</a>
|
||||
<a
|
||||
href={`https://wa.me/?text=${encoded_title}%20${encoded_url}`}
|
||||
class="article-share__btn"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
title={ui.share_whatsapp}
|
||||
>
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
||||
<path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 0 1-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 0 1-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 0 1 2.893 6.994c-.003 5.45-4.435 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0 0 12.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 0 0 5.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 0 0-3.48-8.413z"/>
|
||||
</svg>
|
||||
<span class="sr-only">{ui.share_whatsapp}</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.querySelectorAll('[data-share="copy"]').forEach(btn => {
|
||||
btn.addEventListener('click', async () => {
|
||||
const url = btn.getAttribute('data-url');
|
||||
if (!url) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(url);
|
||||
btn.classList.add('article-share__btn--copied');
|
||||
setTimeout(() => btn.classList.remove('article-share__btn--copied'), 2000);
|
||||
} catch {
|
||||
/* clipboard unavailable */
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.article-share {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-3);
|
||||
padding: var(--space-4);
|
||||
background: var(--inst-surface-muted, var(--color-bg-secondary));
|
||||
border-radius: 10px;
|
||||
border: 1px solid var(--color-border);
|
||||
margin-bottom: var(--space-6);
|
||||
}
|
||||
|
||||
.article-share__label {
|
||||
font-size: var(--text-xs);
|
||||
font-weight: 800;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--color-text-muted);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.article-share__actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.article-share__btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
padding: 0.45em 0.75em;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--color-border);
|
||||
background: var(--color-bg);
|
||||
color: var(--color-text);
|
||||
font-size: var(--text-xs);
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
|
||||
}
|
||||
|
||||
.article-share__btn:hover {
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.article-share__btn--copied {
|
||||
border-color: var(--color-primary);
|
||||
background: color-mix(in srgb, var(--color-primary) 12%, var(--color-bg));
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.article-share__btn-text {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
.article-share__btn-text {
|
||||
display: inline;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,288 @@
|
||||
---
|
||||
import type { Article, ArticleListItem, CategoryConfig } from '../../types/index.js';
|
||||
import { truncate } from '../../lib/format.js';
|
||||
import { getUiStrings } from '../../lib/ui-i18n.js';
|
||||
|
||||
interface Props {
|
||||
article: Article;
|
||||
trending: ArticleListItem[];
|
||||
categories: CategoryConfig[];
|
||||
locale: string;
|
||||
ads_enabled?: boolean;
|
||||
}
|
||||
|
||||
const { article, trending, categories, locale, ads_enabled = false } = Astro.props;
|
||||
const ui = getUiStrings(locale);
|
||||
const filtered_trending = trending.filter(t => t.slug !== article.slug).slice(0, 5);
|
||||
---
|
||||
<aside class="article-sidebar" aria-label={ui.aria_article_sidebar}>
|
||||
{filtered_trending.length > 0 && (
|
||||
<section class="article-sidebar__panel">
|
||||
<div class="article-sidebar__header">
|
||||
<h2 class="article-sidebar__title">{ui.news_most_read}</h2>
|
||||
</div>
|
||||
<ol class="article-sidebar__list">
|
||||
{filtered_trending.map((item, i) => (
|
||||
<li class="article-sidebar__item">
|
||||
<span class="article-sidebar__rank">{String(i + 1).padStart(2, '0')}</span>
|
||||
<div class="article-sidebar__body">
|
||||
<a href={`/category/${item.category.slug}`} class="article-sidebar__cat">
|
||||
{item.category.name}
|
||||
</a>
|
||||
<h3 class="article-sidebar__headline">
|
||||
<a href={`/article/${item.slug}`}>{truncate(item.title, 80)}</a>
|
||||
</h3>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{categories.length > 0 && (
|
||||
<section class="article-sidebar__panel article-sidebar__panel--muted">
|
||||
<div class="article-sidebar__header">
|
||||
<h2 class="article-sidebar__title">{ui.explore_sections}</h2>
|
||||
</div>
|
||||
<ul class="article-sidebar__chips">
|
||||
{categories.map(cat => (
|
||||
<li>
|
||||
<a
|
||||
href={`/category/${cat.slug}`}
|
||||
class:list={['article-sidebar__chip', cat.slug === article.category.slug && 'article-sidebar__chip--active']}
|
||||
>
|
||||
{cat.label}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<section class="article-sidebar__panel article-sidebar__panel--author">
|
||||
<div class="article-sidebar__header">
|
||||
<h2 class="article-sidebar__title">{ui.written_by}</h2>
|
||||
</div>
|
||||
<div class="article-sidebar__author">
|
||||
{article.author.avatar ? (
|
||||
<img
|
||||
src={article.author.avatar}
|
||||
alt=""
|
||||
width="48"
|
||||
height="48"
|
||||
class="article-sidebar__avatar"
|
||||
loading="lazy"
|
||||
/>
|
||||
) : (
|
||||
<div class="article-sidebar__avatar article-sidebar__avatar--placeholder" aria-hidden="true">
|
||||
{article.author.name.charAt(0).toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<p class="article-sidebar__author-name">{article.author.name}</p>
|
||||
<a href={`/category/${article.category.slug}`} class="article-sidebar__author-more">
|
||||
{ui.more_from_category(article.category.name)}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{ads_enabled && (
|
||||
<div class="ad-slot ad-slot--sidebar sticky-top" aria-label={ui.ad_slot_aria}>{ui.ad_slot_text}</div>
|
||||
)}
|
||||
</aside>
|
||||
|
||||
<style>
|
||||
.article-sidebar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-5);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
.article-sidebar {
|
||||
position: sticky;
|
||||
top: calc(var(--header-height) + var(--space-4));
|
||||
align-self: start;
|
||||
}
|
||||
}
|
||||
|
||||
.article-sidebar__panel {
|
||||
background: var(--color-bg-card);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 10px;
|
||||
padding: var(--space-4);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.article-sidebar__panel--muted {
|
||||
background: var(--inst-surface-muted, var(--color-bg-secondary));
|
||||
}
|
||||
|
||||
.article-sidebar__header {
|
||||
padding-bottom: var(--space-3);
|
||||
border-bottom: 3px solid var(--color-primary);
|
||||
margin-bottom: var(--space-3);
|
||||
}
|
||||
|
||||
.article-sidebar__title {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: var(--text-sm);
|
||||
font-weight: 800;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--color-primary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.article-sidebar__list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.article-sidebar__item {
|
||||
display: flex;
|
||||
gap: var(--space-3);
|
||||
padding: var(--space-3) 0;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.article-sidebar__item:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.article-sidebar__rank {
|
||||
flex-shrink: 0;
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: 1.35rem;
|
||||
font-weight: 800;
|
||||
line-height: 1;
|
||||
color: var(--color-primary);
|
||||
opacity: 0.3;
|
||||
min-width: 2ch;
|
||||
}
|
||||
|
||||
.article-sidebar__body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.article-sidebar__cat {
|
||||
font-size: 0.6rem;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
text-decoration: none;
|
||||
color: var(--color-secondary);
|
||||
}
|
||||
|
||||
.article-sidebar__cat:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.article-sidebar__headline {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: var(--text-sm);
|
||||
font-weight: 700;
|
||||
line-height: 1.35;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.article-sidebar__headline a {
|
||||
color: var(--color-text);
|
||||
text-decoration: none;
|
||||
transition: color var(--transition-fast);
|
||||
}
|
||||
|
||||
.article-sidebar__headline a:hover {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.article-sidebar__chips {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.article-sidebar__chip {
|
||||
display: inline-block;
|
||||
padding: 0.35em 0.75em;
|
||||
border-radius: 999px;
|
||||
font-size: var(--text-xs);
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
background: var(--color-bg);
|
||||
color: var(--color-text);
|
||||
border: 1px solid var(--color-border);
|
||||
transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
|
||||
}
|
||||
|
||||
.article-sidebar__chip:hover {
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.article-sidebar__chip--active {
|
||||
background: var(--color-primary);
|
||||
color: #fff;
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.article-sidebar__author {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.article-sidebar__avatar {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.article-sidebar__avatar--placeholder {
|
||||
background: var(--color-primary);
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 800;
|
||||
font-size: var(--text-lg);
|
||||
}
|
||||
|
||||
.article-sidebar__author-name {
|
||||
font-weight: 700;
|
||||
font-size: var(--text-sm);
|
||||
margin: 0 0 var(--space-1);
|
||||
}
|
||||
|
||||
.article-sidebar__author-more {
|
||||
font-size: var(--text-xs);
|
||||
color: var(--color-secondary);
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.article-sidebar__author-more:hover {
|
||||
text-decoration: underline;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.sticky-top {
|
||||
position: sticky;
|
||||
top: calc(var(--header-height) + var(--space-4));
|
||||
}
|
||||
</style>
|
||||
@@ -1,6 +1,7 @@
|
||||
---
|
||||
import type { ArticleListItem } from '../../types/index.js';
|
||||
import { getThemeComponents } from '../../lib/theme.js';
|
||||
import { relativeTime, truncate } from '../../lib/format.js';
|
||||
import { getUiStrings } from '../../lib/ui-i18n.js';
|
||||
|
||||
interface Props {
|
||||
@@ -14,8 +15,51 @@ const ui = getUiStrings(locale);
|
||||
---
|
||||
{articles.length > 0 && (
|
||||
<section class="related-section" aria-labelledby="related-title">
|
||||
<h2 class="section-title" id="related-title">{ui.related_articles_title}</h2>
|
||||
<div class="related-grid">
|
||||
<div class="related-section__header">
|
||||
<h2 class="related-section__title" id="related-title">{ui.related_articles_title}</h2>
|
||||
<span class="related-section__accent" aria-hidden="true"></span>
|
||||
</div>
|
||||
<div class="related-grid related-grid--rich">
|
||||
{articles.map((article, i) => (
|
||||
<article class="related-card">
|
||||
<a href={`/article/${article.slug}`} class="related-card__media" tabindex="-1" aria-hidden="true">
|
||||
{article.featured_image ? (
|
||||
<img
|
||||
src={article.featured_image}
|
||||
alt={article.featured_image_alt}
|
||||
class="related-card__img"
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
width="400"
|
||||
height="225"
|
||||
/>
|
||||
) : (
|
||||
<div class="related-card__img img-placeholder" aria-hidden="true">
|
||||
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" opacity="0.3">
|
||||
<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>
|
||||
)}
|
||||
<span class="related-card__index">{String(i + 1).padStart(2, '0')}</span>
|
||||
</a>
|
||||
<div class="related-card__body">
|
||||
<a href={`/category/${article.category.slug}`} class="related-card__cat">{article.category.name}</a>
|
||||
<h3 class="related-card__title">
|
||||
<a href={`/article/${article.slug}`}>{truncate(article.title, 90)}</a>
|
||||
</h3>
|
||||
<p class="related-card__excerpt">{truncate(article.excerpt, 100)}</p>
|
||||
<footer class="related-card__meta">
|
||||
<span>{article.author.name}</span>
|
||||
<span aria-hidden="true">·</span>
|
||||
<time datetime={article.published_at}>{relativeTime(article.published_at, locale)}</time>
|
||||
</footer>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div class="related-grid related-grid--compact">
|
||||
{articles.map(article => (
|
||||
<ArticleCard article={article} size="md" show_excerpt={false} locale={locale} />
|
||||
))}
|
||||
@@ -30,10 +74,154 @@ const ui = getUiStrings(locale);
|
||||
border-top: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.related-grid {
|
||||
.related-section__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-4);
|
||||
margin-bottom: var(--space-6);
|
||||
}
|
||||
|
||||
.related-section__title {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: clamp(1.25rem, 3vw, 1.75rem);
|
||||
font-weight: 900;
|
||||
letter-spacing: -0.02em;
|
||||
margin: 0;
|
||||
color: var(--color-primary);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.related-section__accent {
|
||||
flex: 1;
|
||||
height: 3px;
|
||||
background: linear-gradient(90deg, var(--color-primary), transparent);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.related-grid--rich {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||||
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
|
||||
gap: var(--space-5);
|
||||
margin-top: var(--space-5);
|
||||
}
|
||||
|
||||
.related-grid--compact {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 639px) {
|
||||
.related-grid--rich {
|
||||
display: none;
|
||||
}
|
||||
.related-grid--compact {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: var(--space-4);
|
||||
}
|
||||
}
|
||||
|
||||
.related-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--color-bg-card);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
transition: box-shadow var(--transition-fast), transform var(--transition-fast);
|
||||
}
|
||||
|
||||
.related-card:hover {
|
||||
box-shadow: var(--shadow-md);
|
||||
transform: translateY(-3px);
|
||||
}
|
||||
|
||||
.related-card__media {
|
||||
position: relative;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.related-card__img {
|
||||
width: 100%;
|
||||
aspect-ratio: 16 / 9;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
transition: transform 0.4s ease;
|
||||
}
|
||||
|
||||
.related-card:hover .related-card__img {
|
||||
transform: scale(1.04);
|
||||
}
|
||||
|
||||
.related-card__index {
|
||||
position: absolute;
|
||||
top: var(--space-3);
|
||||
left: var(--space-3);
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: 1.5rem;
|
||||
font-weight: 900;
|
||||
color: #fff;
|
||||
text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.related-card__body {
|
||||
padding: var(--space-4);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-2);
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.related-card__cat {
|
||||
font-size: 0.65rem;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--color-secondary);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.related-card__cat:hover {
|
||||
color: var(--color-primary);
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.related-card__title {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: var(--text-base);
|
||||
font-weight: 800;
|
||||
line-height: 1.3;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.related-card__title a {
|
||||
color: var(--color-text);
|
||||
text-decoration: none;
|
||||
transition: color var(--transition-fast);
|
||||
}
|
||||
|
||||
.related-card__title a:hover {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.related-card__excerpt {
|
||||
font-size: var(--text-sm);
|
||||
color: var(--color-text-muted);
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.related-card__meta {
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
font-size: var(--text-xs);
|
||||
color: var(--color-text-muted);
|
||||
margin-top: auto;
|
||||
padding-top: var(--space-2);
|
||||
}
|
||||
</style>
|
||||
@@ -29,14 +29,32 @@ const ui = getUiStrings(locale);
|
||||
const heading = title ?? ui.latest_news;
|
||||
---
|
||||
<section
|
||||
class:list={['latest-section', variant === 'band' && 'latest-section--band']}
|
||||
class:list={[
|
||||
'latest-section',
|
||||
variant === 'band' && 'latest-section--band',
|
||||
theme === 'institutional' && 'latest-section--institutional',
|
||||
]}
|
||||
aria-labelledby={titleId}
|
||||
>
|
||||
<div class="container">
|
||||
<div class="latest-header">
|
||||
<h2 class="section-title" id={titleId}>{heading}</h2>
|
||||
<h2
|
||||
class:list={[
|
||||
theme === 'institutional' ? 'latest-section__title' : 'section-title',
|
||||
]}
|
||||
id={titleId}
|
||||
>
|
||||
{heading}
|
||||
</h2>
|
||||
{show_more_href && (
|
||||
<a href={show_more_href} class="btn btn--ghost latest-more">{ui.view_all}</a>
|
||||
<a
|
||||
href={show_more_href}
|
||||
class:list={[
|
||||
theme === 'institutional' ? 'latest-section__more' : 'btn btn--ghost latest-more',
|
||||
]}
|
||||
>
|
||||
{ui.view_all}
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -65,8 +83,46 @@ const heading = title ?? ui.latest_news;
|
||||
gap: var(--space-4);
|
||||
}
|
||||
|
||||
.latest-header .section-title { margin-bottom: 0; }
|
||||
.latest-more { white-space: nowrap; }
|
||||
.latest-header .section-title,
|
||||
.latest-header .latest-section__title { margin-bottom: 0; }
|
||||
.latest-more,
|
||||
.latest-section__more { white-space: nowrap; }
|
||||
|
||||
.latest-section--institutional .latest-header {
|
||||
align-items: baseline;
|
||||
padding-bottom: var(--space-3);
|
||||
border-bottom: 2px solid var(--color-primary);
|
||||
margin-bottom: var(--space-2);
|
||||
}
|
||||
|
||||
.latest-section__title {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: clamp(1.25rem, 2.5vw, 1.75rem);
|
||||
font-weight: 800;
|
||||
letter-spacing: -0.01em;
|
||||
color: var(--color-primary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.latest-section__more {
|
||||
font-size: var(--text-sm);
|
||||
font-weight: 500;
|
||||
color: var(--color-secondary);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.latest-section__more:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.latest-section--institutional.latest-section--band {
|
||||
background: linear-gradient(
|
||||
180deg,
|
||||
color-mix(in srgb, var(--color-primary) 5%, var(--color-bg)) 0%,
|
||||
var(--color-bg-secondary) 40%,
|
||||
var(--color-bg) 100%
|
||||
);
|
||||
}
|
||||
|
||||
.latest-grid {
|
||||
display: grid;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
bridgeBaseForSite,
|
||||
bridgeHealthUrl,
|
||||
swrCacheKey,
|
||||
} from './bridge.ts';
|
||||
|
||||
test('bridgeBaseForSite uses nginx vhost path for production domains', () => {
|
||||
assert.equal(
|
||||
bridgeBaseForSite('andebol.net', 'http://127.0.0.1:3200'),
|
||||
'http://andebol.net/api',
|
||||
);
|
||||
assert.equal(
|
||||
bridgeBaseForSite('newsproject.bitreport.pt', 'http://127.0.0.1:3200'),
|
||||
'http://newsproject.bitreport.pt/api',
|
||||
);
|
||||
});
|
||||
|
||||
test('bridgeBaseForSite keeps loopback for local dev', () => {
|
||||
assert.equal(
|
||||
bridgeBaseForSite('localhost', 'http://localhost:3200'),
|
||||
'http://localhost:3200',
|
||||
);
|
||||
assert.equal(
|
||||
bridgeBaseForSite('127.0.0.1', 'http://127.0.0.1:3200'),
|
||||
'http://127.0.0.1:3200',
|
||||
);
|
||||
});
|
||||
|
||||
test('bridgeHealthUrl uses vhost /health for production domains', () => {
|
||||
assert.equal(
|
||||
bridgeHealthUrl('andebol.net', 'http://127.0.0.1:3200'),
|
||||
'http://andebol.net/health',
|
||||
);
|
||||
});
|
||||
|
||||
test('swrCacheKey scopes cache entries per site host', () => {
|
||||
const url = 'http://andebol.net/api/homepage';
|
||||
assert.equal(swrCacheKey(url, 'andebol.net'), 'andebol.net|http://andebol.net/api/homepage');
|
||||
assert.notEqual(swrCacheKey(url, 'andebol.net'), swrCacheKey(url, 'newsproject.bitreport.pt'));
|
||||
});
|
||||
+88
-24
@@ -18,19 +18,71 @@ const cache = new Map<string, CacheEntry>();
|
||||
const FRESH_TTL = 60_000; // 60s before stale
|
||||
const STALE_TTL = 300_000; // 5min before hard expiry
|
||||
|
||||
/** Forward public Host so the bridge loads the correct domain JSON on loopback SSR. */
|
||||
export function bridgeRequestHeaders(site_host?: string | null): HeadersInit {
|
||||
const headers: Record<string, string> = { Accept: 'application/json' };
|
||||
const hostname = site_host?.split(':')[0];
|
||||
if (hostname) {
|
||||
headers['X-Site-Host'] = hostname;
|
||||
}
|
||||
return headers;
|
||||
function isLoopbackHostname(hostname: string): boolean {
|
||||
return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1';
|
||||
}
|
||||
|
||||
async function fetchWithSWR<T>(url: string, req_headers: HeadersInit): Promise<T> {
|
||||
/**
|
||||
* SSR bridge base URL.
|
||||
* - `BRIDGE_INTERNAL_URL` env overrides everything — use when hostname DNS doesn't resolve
|
||||
* from inside the LXC (e.g. `http://127.0.0.1:3200`).
|
||||
* - Production multi-domain without override: call nginx via the public hostname so the
|
||||
* `Host` header selects the correct domain JSON — no X-Site-Host (BIT-25555).
|
||||
* - Local dev / loopback: direct to `bridge_endpoint`.
|
||||
*/
|
||||
export function bridgeBaseForSite(
|
||||
site_host: string | null | undefined,
|
||||
bridge_endpoint: string,
|
||||
): string {
|
||||
const internalUrl = typeof process !== 'undefined'
|
||||
? process.env['BRIDGE_INTERNAL_URL']?.trim()
|
||||
: undefined;
|
||||
if (internalUrl) {
|
||||
return internalUrl.replace(/\/$/, '');
|
||||
}
|
||||
const hostname = site_host?.split(':')[0]?.toLowerCase();
|
||||
if (!hostname || isLoopbackHostname(hostname)) {
|
||||
return bridge_endpoint.replace(/\/$/, '');
|
||||
}
|
||||
return `http://${hostname}/api`;
|
||||
}
|
||||
|
||||
/** Health probe URL — nginx exposes /health per vhost on the CT. */
|
||||
export function bridgeHealthUrl(
|
||||
site_host: string | null | undefined,
|
||||
bridge_endpoint: string,
|
||||
): string {
|
||||
const internalUrl = typeof process !== 'undefined'
|
||||
? process.env['BRIDGE_INTERNAL_URL']?.trim()
|
||||
: undefined;
|
||||
if (internalUrl) {
|
||||
return `${internalUrl.replace(/\/$/, '')}/health`;
|
||||
}
|
||||
const hostname = site_host?.split(':')[0]?.toLowerCase();
|
||||
if (!hostname || isLoopbackHostname(hostname)) {
|
||||
return `${bridge_endpoint.replace(/\/$/, '')}/health`;
|
||||
}
|
||||
return `http://${hostname}/health`;
|
||||
}
|
||||
|
||||
export function bridgeRequestHeaders(): HeadersInit {
|
||||
return { Accept: 'application/json' };
|
||||
}
|
||||
|
||||
/** SWR keys must include site host — one Node process serves every domain (BIT-25555). */
|
||||
export function swrCacheKey(url: string, site_host: string | null | undefined): string {
|
||||
const hostname = site_host?.split(':')[0]?.toLowerCase();
|
||||
return hostname ? `${hostname}|${url}` : url;
|
||||
}
|
||||
|
||||
async function fetchWithSWR<T>(
|
||||
url: string,
|
||||
site_host: string | null | undefined,
|
||||
req_headers: HeadersInit,
|
||||
): Promise<T> {
|
||||
const cache_key = swrCacheKey(url, site_host);
|
||||
const now = Date.now();
|
||||
const entry = cache.get(url);
|
||||
const entry = cache.get(cache_key);
|
||||
|
||||
if (entry && now < entry.stale_at) {
|
||||
return entry.data as T;
|
||||
@@ -38,15 +90,20 @@ async function fetchWithSWR<T>(url: string, req_headers: HeadersInit): Promise<T
|
||||
|
||||
// Revalidate in background if stale but not expired
|
||||
if (entry && now < entry.expires) {
|
||||
revalidate(url, req_headers).catch(() => null);
|
||||
revalidate(cache_key, url, site_host, req_headers).catch(() => null);
|
||||
return entry.data as T;
|
||||
}
|
||||
|
||||
// Blocking fetch (cold or hard-expired)
|
||||
return revalidate<T>(url, req_headers);
|
||||
return revalidate<T>(cache_key, url, site_host, req_headers);
|
||||
}
|
||||
|
||||
async function revalidate<T>(url: string, req_headers: HeadersInit): Promise<T> {
|
||||
async function revalidate<T>(
|
||||
cache_key: string,
|
||||
url: string,
|
||||
site_host: string | null | undefined,
|
||||
req_headers: HeadersInit,
|
||||
): Promise<T> {
|
||||
const res = await fetch(url, {
|
||||
headers: req_headers,
|
||||
});
|
||||
@@ -54,7 +111,7 @@ async function revalidate<T>(url: string, req_headers: HeadersInit): Promise<T>
|
||||
throw new Error(`Bridge API ${res.status}: ${url}`);
|
||||
}
|
||||
const data: T = await res.json();
|
||||
cache.set(url, {
|
||||
cache.set(cache_key, {
|
||||
data,
|
||||
stale_at: Date.now() + FRESH_TTL,
|
||||
expires: Date.now() + STALE_TTL,
|
||||
@@ -64,15 +121,17 @@ async function revalidate<T>(url: string, req_headers: HeadersInit): Promise<T>
|
||||
|
||||
export class BridgeClient {
|
||||
private base: string;
|
||||
private site_host: string | null | undefined;
|
||||
private req_headers: HeadersInit;
|
||||
|
||||
constructor(bridge_endpoint: string, site_host?: string | null) {
|
||||
this.base = bridge_endpoint.replace(/\/$/, '');
|
||||
this.req_headers = bridgeRequestHeaders(site_host);
|
||||
this.site_host = site_host ?? undefined;
|
||||
this.base = bridgeBaseForSite(this.site_host, bridge_endpoint);
|
||||
this.req_headers = bridgeRequestHeaders();
|
||||
}
|
||||
|
||||
async getHomepage(): Promise<HomepageData> {
|
||||
return fetchWithSWR<HomepageData>(`${this.base}/homepage`, this.req_headers);
|
||||
return fetchWithSWR<HomepageData>(`${this.base}/homepage`, this.site_host, this.req_headers);
|
||||
}
|
||||
|
||||
async getArticles(params: {
|
||||
@@ -87,28 +146,33 @@ export class BridgeClient {
|
||||
if (params.per_page) qs.set('per_page', String(params.per_page));
|
||||
if (params.search) qs.set('search', params.search);
|
||||
const url = `${this.base}/articles?${qs.toString()}`;
|
||||
return fetchWithSWR<PaginatedResponse<ArticleListItem>>(url, this.req_headers);
|
||||
return fetchWithSWR<PaginatedResponse<ArticleListItem>>(url, this.site_host, this.req_headers);
|
||||
}
|
||||
|
||||
async getArticle(slug: string): Promise<Article> {
|
||||
return fetchWithSWR<Article>(`${this.base}/articles/${slug}`, this.req_headers);
|
||||
return fetchWithSWR<Article>(`${this.base}/articles/${slug}`, this.site_host, this.req_headers);
|
||||
}
|
||||
|
||||
async getCategories(): Promise<Category[]> {
|
||||
return fetchWithSWR<Category[]>(`${this.base}/categories`, this.req_headers);
|
||||
return fetchWithSWR<Category[]>(`${this.base}/categories`, this.site_host, this.req_headers);
|
||||
}
|
||||
|
||||
async getCategory(slug: string): Promise<Category> {
|
||||
return fetchWithSWR<Category>(`${this.base}/categories/${slug}`, this.req_headers);
|
||||
return fetchWithSWR<Category>(`${this.base}/categories/${slug}`, this.site_host, this.req_headers);
|
||||
}
|
||||
|
||||
async getTrending(limit = 5): Promise<ArticleListItem[]> {
|
||||
return fetchWithSWR<ArticleListItem[]>(`${this.base}/trending?limit=${limit}`, this.req_headers);
|
||||
return fetchWithSWR<ArticleListItem[]>(
|
||||
`${this.base}/trending?limit=${limit}`,
|
||||
this.site_host,
|
||||
this.req_headers,
|
||||
);
|
||||
}
|
||||
|
||||
async getRelated(slug: string, limit = 4): Promise<ArticleListItem[]> {
|
||||
return fetchWithSWR<ArticleListItem[]>(
|
||||
`${this.base}/articles/${slug}/related?limit=${limit}`,
|
||||
this.site_host,
|
||||
this.req_headers,
|
||||
);
|
||||
}
|
||||
@@ -261,9 +325,9 @@ export async function resolveSsrBridge(
|
||||
): Promise<BridgeClient> {
|
||||
try {
|
||||
const bridge = new BridgeClient(bridge_endpoint, site_host ?? undefined);
|
||||
const health_url = `${bridge_endpoint.replace(/\/$/, '')}/health`;
|
||||
const health_url = bridgeHealthUrl(site_host, bridge_endpoint);
|
||||
const res = await fetch(health_url, {
|
||||
headers: bridgeRequestHeaders(site_host),
|
||||
headers: bridgeRequestHeaders(),
|
||||
signal: AbortSignal.timeout(2000),
|
||||
});
|
||||
if (!res.ok) {
|
||||
|
||||
@@ -55,6 +55,9 @@ export type UiStrings = {
|
||||
fpa_col_competition: string;
|
||||
fpa_agenda_empty: string;
|
||||
fpa_source_credit: string;
|
||||
fpa_status_finished: string;
|
||||
fpa_status_upcoming: string;
|
||||
fpa_games_on_date: (count: number) => string;
|
||||
/** News archive page title */
|
||||
news_archive_title: string;
|
||||
/** "All" filter label for category tabs */
|
||||
@@ -80,6 +83,15 @@ export type UiStrings = {
|
||||
tags_heading: string;
|
||||
/** Prefix before updated timestamp in article byline */
|
||||
article_updated_prefix: string;
|
||||
/** Share bar heading on article pages */
|
||||
share_heading: string;
|
||||
share_copy: string;
|
||||
share_twitter: string;
|
||||
share_facebook: string;
|
||||
share_whatsapp: string;
|
||||
/** Sidebar author panel */
|
||||
written_by: string;
|
||||
more_from_category: (sectionName: string) => string;
|
||||
/** Meta description when category has no WP description */
|
||||
category_meta_latest: (sectionName: string) => string;
|
||||
/** Search results could not be loaded from bridge */
|
||||
@@ -135,6 +147,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).',
|
||||
fpa_status_finished: 'FT',
|
||||
fpa_status_upcoming: 'Upcoming',
|
||||
fpa_games_on_date: count => (count === 1 ? '1 match' : `${count} matches`),
|
||||
news_archive_title: 'News',
|
||||
news_all_filter: 'All',
|
||||
news_archive_desc: 'Latest news and stories across all sections.',
|
||||
@@ -149,6 +164,13 @@ const en: UiStrings = {
|
||||
aria_article_sidebar: 'Article sidebar',
|
||||
tags_heading: 'Tags:',
|
||||
article_updated_prefix: 'Updated',
|
||||
share_heading: 'Share',
|
||||
share_copy: 'Copy link',
|
||||
share_twitter: 'Share on X',
|
||||
share_facebook: 'Share on Facebook',
|
||||
share_whatsapp: 'Share on WhatsApp',
|
||||
written_by: 'Written by',
|
||||
more_from_category: name => `More from ${name}`,
|
||||
category_meta_latest: name => `Latest ${name} news`,
|
||||
search_upstream_error: 'Results could not be loaded. Please try again shortly.',
|
||||
};
|
||||
@@ -202,6 +224,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).',
|
||||
fpa_status_finished: 'Fim',
|
||||
fpa_status_upcoming: 'Por jogar',
|
||||
fpa_games_on_date: count => (count === 1 ? '1 jogo' : `${count} jogos`),
|
||||
news_archive_title: 'Notícias',
|
||||
news_all_filter: 'Todas',
|
||||
news_archive_desc: 'Últimas notícias e histórias de todas as secções.',
|
||||
@@ -216,6 +241,13 @@ const pt: UiStrings = {
|
||||
aria_article_sidebar: 'Barra lateral do artigo',
|
||||
tags_heading: 'Etiquetas:',
|
||||
article_updated_prefix: 'Atualizado',
|
||||
share_heading: 'Partilhar',
|
||||
share_copy: 'Copiar link',
|
||||
share_twitter: 'Partilhar no X',
|
||||
share_facebook: 'Partilhar no Facebook',
|
||||
share_whatsapp: 'Partilhar no WhatsApp',
|
||||
written_by: 'Escrito por',
|
||||
more_from_category: name => `Mais de ${name}`,
|
||||
category_meta_latest: name => `Últimas notícias: ${name}`,
|
||||
search_upstream_error:
|
||||
'Não foi possível obter resultados. Tenta novamente dentro de momentos.',
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
---
|
||||
import Base from '../../layouts/Base.astro';
|
||||
import ArticleHeader from '../../components/article/ArticleHeader.astro';
|
||||
import ArticleSidebar from '../../components/article/ArticleSidebar.astro';
|
||||
import ArticleShareBar from '../../components/article/ArticleShareBar.astro';
|
||||
import RelatedArticles from '../../components/article/RelatedArticles.astro';
|
||||
import { getDomainConfig } from '../../lib/domain.js';
|
||||
import { BridgeClient, resolveSsrBridge } from '../../lib/bridge.js';
|
||||
@@ -15,7 +17,6 @@ const host = Astro.request.headers.get('host') ?? 'localhost';
|
||||
const site_host = host.split(':')[0];
|
||||
const config = getDomainConfig(host);
|
||||
|
||||
// Set cache headers for CDN
|
||||
Astro.response.headers.set('Cache-Control', 's-maxage=60, stale-while-revalidate=300');
|
||||
|
||||
let bridge: BridgeClient;
|
||||
@@ -27,11 +28,13 @@ try {
|
||||
|
||||
let article;
|
||||
let related;
|
||||
let trending;
|
||||
|
||||
try {
|
||||
[article, related] = await Promise.all([
|
||||
[article, related, trending] = await Promise.all([
|
||||
bridge.getArticle(slug),
|
||||
bridge.getRelated(slug, 4),
|
||||
bridge.getTrending(6),
|
||||
]);
|
||||
} catch {
|
||||
return Astro.redirect('/');
|
||||
@@ -41,6 +44,7 @@ const public_origin = getPublicOrigin(Astro.request);
|
||||
const canonical = `${public_origin}/article/${slug}`;
|
||||
const ui = getUiStrings(config.locale);
|
||||
const is_institutional = config.theme === 'institutional';
|
||||
const has_hero_image = Boolean(article.featured_image);
|
||||
|
||||
const news_article_schema = {
|
||||
'@context': 'https://schema.org',
|
||||
@@ -90,26 +94,76 @@ const breadcrumb_schema = {
|
||||
canonical={canonical}
|
||||
schema={news_article_schema}
|
||||
>
|
||||
<!-- Additional schema for breadcrumbs -->
|
||||
<script type="application/ld+json" set:html={JSON.stringify(breadcrumb_schema)} slot="head" />
|
||||
|
||||
<div class:list={['article-page', 'container', is_institutional && 'article-page--inst']}>
|
||||
{is_institutional && (
|
||||
<nav class="article-breadcrumb" aria-label={ui.aria_breadcrumb}>
|
||||
<a href="/">{ui.breadcrumb_home}</a>
|
||||
<span class="article-breadcrumb__sep" aria-hidden="true">/</span>
|
||||
<a href={`/category/${article.category.slug}`}>{article.category.name}</a>
|
||||
<span class="article-breadcrumb__sep" aria-hidden="true">/</span>
|
||||
<span class="article-breadcrumb__current" aria-current="page">{article.title}</span>
|
||||
</nav>
|
||||
)}
|
||||
<div class="article-layout">
|
||||
<!-- Main article column -->
|
||||
<div class="article-main">
|
||||
<ArticleHeader article={article} locale={config.locale} showBreadcrumb={!is_institutional} />
|
||||
<article class:list={['article-page', is_institutional && 'article-page--inst']}>
|
||||
{is_institutional ? (
|
||||
<header class="article-masthead">
|
||||
<div class="container article-masthead__inner">
|
||||
<nav class="article-breadcrumb" aria-label={ui.aria_breadcrumb}>
|
||||
<a href="/">{ui.breadcrumb_home}</a>
|
||||
<span class="article-breadcrumb__sep" aria-hidden="true">/</span>
|
||||
<a href={`/category/${article.category.slug}`}>{article.category.name}</a>
|
||||
<span class="article-breadcrumb__sep" aria-hidden="true">/</span>
|
||||
<span class="article-breadcrumb__current" aria-current="page">{article.title}</span>
|
||||
</nav>
|
||||
<a href={`/category/${article.category.slug}`} class="article-masthead__cat badge">
|
||||
{article.category.name}
|
||||
</a>
|
||||
<h1 class="article-masthead__title">{article.title}</h1>
|
||||
{article.excerpt && <p class="article-masthead__excerpt">{article.excerpt}</p>}
|
||||
<ArticleHeader article={article} locale={config.locale} variant="meta-only" />
|
||||
</div>
|
||||
</header>
|
||||
) : has_hero_image ? (
|
||||
<header class="article-hero">
|
||||
<img
|
||||
src={article.featured_image!}
|
||||
alt={article.featured_image_alt}
|
||||
class="article-hero__img"
|
||||
loading="eager"
|
||||
decoding="async"
|
||||
fetchpriority="high"
|
||||
width="1280"
|
||||
height="720"
|
||||
/>
|
||||
<div class="article-hero__overlay">
|
||||
<div class="container article-hero__content">
|
||||
<nav class="article-breadcrumb article-breadcrumb--light" aria-label={ui.aria_breadcrumb}>
|
||||
<a href="/">{ui.breadcrumb_home}</a>
|
||||
<span class="article-breadcrumb__sep" aria-hidden="true">/</span>
|
||||
<a href={`/category/${article.category.slug}`}>{article.category.name}</a>
|
||||
</nav>
|
||||
<a href={`/category/${article.category.slug}`} class="badge">{article.category.name}</a>
|
||||
<h1 class="article-hero__title">{article.title}</h1>
|
||||
<ArticleHeader article={article} locale={config.locale} variant="meta-only" theme="dark" />
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
) : null}
|
||||
|
||||
<!-- Featured image -->
|
||||
{article.featured_image && (
|
||||
<div class="container article-layout">
|
||||
<div class="article-main">
|
||||
{!is_institutional && !has_hero_image && (
|
||||
<ArticleHeader article={article} locale={config.locale} showBreadcrumb />
|
||||
)}
|
||||
|
||||
{is_institutional && has_hero_image && (
|
||||
<figure class="article-figure article-figure--masthead">
|
||||
<img
|
||||
src={article.featured_image!}
|
||||
alt={article.featured_image_alt}
|
||||
class="article-figure__img"
|
||||
loading="eager"
|
||||
decoding="async"
|
||||
fetchpriority="high"
|
||||
width="900"
|
||||
height="506"
|
||||
/>
|
||||
</figure>
|
||||
)}
|
||||
|
||||
{!is_institutional && !has_hero_image && article.featured_image && (
|
||||
<figure class="article-figure">
|
||||
<img
|
||||
src={article.featured_image}
|
||||
@@ -124,48 +178,173 @@ const breadcrumb_schema = {
|
||||
</figure>
|
||||
)}
|
||||
|
||||
<!-- Ad slot: top of article -->
|
||||
<ArticleShareBar url={canonical} title={article.title} locale={config.locale} />
|
||||
|
||||
{config.ads_enabled && (
|
||||
<div class="ad-slot ad-slot--in-article" aria-label={ui.ad_slot_aria}>{ui.ad_slot_text}</div>
|
||||
)}
|
||||
|
||||
<!-- Article body -->
|
||||
<div class="article-body" set:html={article.content} />
|
||||
|
||||
<!-- Tags -->
|
||||
{article.tags.length > 0 && (
|
||||
<div class="article-tags">
|
||||
<footer class="article-tags">
|
||||
<span class="article-tags__label">{ui.tags_heading}</span>
|
||||
{article.tags.map(tag => (
|
||||
<span class="badge badge--muted">{tag.name}</span>
|
||||
))}
|
||||
</div>
|
||||
</footer>
|
||||
)}
|
||||
|
||||
<div class="article-byline-footer">
|
||||
<div class="article-byline-footer__author">
|
||||
{article.author.avatar ? (
|
||||
<img
|
||||
src={article.author.avatar}
|
||||
alt=""
|
||||
width="56"
|
||||
height="56"
|
||||
class="article-byline-footer__avatar"
|
||||
loading="lazy"
|
||||
/>
|
||||
) : (
|
||||
<div class="article-byline-footer__avatar article-byline-footer__avatar--placeholder" aria-hidden="true">
|
||||
{article.author.name.charAt(0).toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<p class="article-byline-footer__label">{ui.written_by}</p>
|
||||
<p class="article-byline-footer__name">{article.author.name}</p>
|
||||
<p class="article-byline-footer__date">
|
||||
<time datetime={article.published_at}>{formatDate(article.published_at, config.locale)}</time>
|
||||
{article.updated_at !== article.published_at && (
|
||||
<span> · {ui.article_updated_prefix}{' '}
|
||||
<time datetime={article.updated_at}>{formatDate(article.updated_at, config.locale)}</time>
|
||||
</span>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sidebar -->
|
||||
<aside class="article-sidebar" aria-label={ui.aria_article_sidebar}>
|
||||
{config.ads_enabled && (
|
||||
<div class="ad-slot ad-slot--sidebar sticky-top" aria-label={ui.ad_slot_aria}>{ui.ad_slot_text}</div>
|
||||
)}
|
||||
</aside>
|
||||
<ArticleSidebar
|
||||
article={article}
|
||||
trending={trending}
|
||||
categories={config.categories}
|
||||
locale={config.locale}
|
||||
ads_enabled={config.ads_enabled}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Related articles -->
|
||||
<RelatedArticles theme={config.theme} articles={related} locale={config.locale} />
|
||||
</div>
|
||||
<div class="container">
|
||||
<RelatedArticles theme={config.theme} articles={related} locale={config.locale} />
|
||||
</div>
|
||||
</article>
|
||||
</Base>
|
||||
|
||||
<style>
|
||||
.article-page {
|
||||
padding-top: var(--space-6);
|
||||
padding-bottom: var(--space-12);
|
||||
}
|
||||
|
||||
.article-page--inst {
|
||||
.article-page--inst .article-layout {
|
||||
padding-top: var(--space-8);
|
||||
}
|
||||
|
||||
.article-masthead {
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
var(--color-primary-dark, #0f2640) 0%,
|
||||
var(--color-primary) 55%,
|
||||
color-mix(in srgb, var(--color-secondary) 80%, #000) 100%
|
||||
);
|
||||
color: #fff;
|
||||
padding: var(--space-8) 0 var(--space-10);
|
||||
border-bottom: 4px solid color-mix(in srgb, var(--color-secondary) 65%, #fff);
|
||||
}
|
||||
|
||||
.article-masthead__inner {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-4);
|
||||
max-width: min(900px, 100%);
|
||||
}
|
||||
|
||||
.article-masthead__cat {
|
||||
align-self: flex-start;
|
||||
}
|
||||
|
||||
.article-masthead__title {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: clamp(1.85rem, 5vw, 3rem);
|
||||
font-weight: 900;
|
||||
line-height: 1.08;
|
||||
letter-spacing: -0.03em;
|
||||
margin: 0;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.article-masthead__excerpt {
|
||||
font-size: var(--text-lg);
|
||||
line-height: 1.55;
|
||||
color: rgba(255, 255, 255, 0.88);
|
||||
margin: 0;
|
||||
max-width: 65ch;
|
||||
border-left: 3px solid rgba(255, 255, 255, 0.35);
|
||||
padding-left: var(--space-4);
|
||||
}
|
||||
|
||||
.article-hero {
|
||||
position: relative;
|
||||
min-height: clamp(280px, 50vw, 520px);
|
||||
background: var(--color-bg-secondary);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.article-hero__img {
|
||||
width: 100%;
|
||||
height: clamp(280px, 50vw, 520px);
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.article-hero__overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: linear-gradient(
|
||||
to top,
|
||||
rgba(0, 0, 0, 0.92) 0%,
|
||||
rgba(0, 0, 0, 0.55) 45%,
|
||||
rgba(0, 0, 0, 0.15) 100%
|
||||
);
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
padding-bottom: var(--space-8);
|
||||
}
|
||||
|
||||
.article-hero__content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.article-hero__title {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: clamp(1.75rem, 4.5vw, 2.85rem);
|
||||
font-weight: 900;
|
||||
line-height: 1.1;
|
||||
letter-spacing: -0.025em;
|
||||
color: #fff;
|
||||
margin: 0;
|
||||
max-width: 18ch;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.article-hero__title {
|
||||
max-width: 22ch;
|
||||
}
|
||||
}
|
||||
|
||||
.article-breadcrumb {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
@@ -173,9 +352,10 @@ const breadcrumb_schema = {
|
||||
gap: var(--space-2);
|
||||
font-size: var(--text-sm);
|
||||
color: var(--color-text-muted);
|
||||
padding-bottom: var(--space-4);
|
||||
margin-bottom: var(--space-2);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.article-breadcrumb--light {
|
||||
color: rgba(255, 255, 255, 0.75);
|
||||
}
|
||||
|
||||
.article-breadcrumb a {
|
||||
@@ -184,16 +364,28 @@ const breadcrumb_schema = {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.article-breadcrumb--light a {
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.article-breadcrumb a:hover {
|
||||
text-decoration: underline;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.article-breadcrumb--light a:hover {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.article-breadcrumb__sep {
|
||||
color: var(--color-border);
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.article-breadcrumb--light .article-breadcrumb__sep {
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
.article-breadcrumb__current {
|
||||
color: var(--color-text);
|
||||
font-weight: 600;
|
||||
@@ -208,25 +400,35 @@ const breadcrumb_schema = {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: var(--space-8);
|
||||
padding-top: var(--space-6);
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
.article-layout {
|
||||
grid-template-columns: minmax(0, 2.5fr) 280px;
|
||||
grid-template-columns: minmax(0, 1fr) 300px;
|
||||
align-items: start;
|
||||
gap: var(--space-10);
|
||||
}
|
||||
}
|
||||
|
||||
.article-figure {
|
||||
margin-bottom: var(--space-8);
|
||||
border-radius: 8px;
|
||||
margin-bottom: var(--space-6);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
box-shadow: var(--inst-shadow-feature, var(--shadow-md));
|
||||
}
|
||||
|
||||
.article-figure--masthead {
|
||||
margin-top: 0;
|
||||
margin-bottom: var(--space-8);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.article-figure__img {
|
||||
width: 100%;
|
||||
max-height: 520px;
|
||||
max-height: 560px;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.article-tags {
|
||||
@@ -241,20 +443,63 @@ const breadcrumb_schema = {
|
||||
|
||||
.article-tags__label {
|
||||
font-size: var(--text-sm);
|
||||
font-weight: 600;
|
||||
font-weight: 700;
|
||||
color: var(--color-text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.sticky-top {
|
||||
position: sticky;
|
||||
top: calc(var(--header-height) + var(--space-4));
|
||||
.article-byline-footer {
|
||||
margin-top: var(--space-8);
|
||||
padding: var(--space-5);
|
||||
background: var(--inst-surface-muted, var(--color-bg-secondary));
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.article-sidebar {
|
||||
display: none;
|
||||
.article-byline-footer__author {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-4);
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
.article-sidebar { display: block; }
|
||||
.article-byline-footer__avatar {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.article-byline-footer__avatar--placeholder {
|
||||
background: var(--color-primary);
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 800;
|
||||
font-size: var(--text-xl);
|
||||
}
|
||||
|
||||
.article-byline-footer__label {
|
||||
font-size: var(--text-xs);
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--color-text-muted);
|
||||
margin: 0 0 var(--space-1);
|
||||
}
|
||||
|
||||
.article-byline-footer__name {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: var(--text-lg);
|
||||
font-weight: 800;
|
||||
margin: 0 0 var(--space-1);
|
||||
}
|
||||
|
||||
.article-byline-footer__date {
|
||||
font-size: var(--text-sm);
|
||||
color: var(--color-text-muted);
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -339,22 +339,38 @@ img {
|
||||
.article-body {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 1.125rem;
|
||||
line-height: 1.8;
|
||||
line-height: 1.85;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.article-body > p:first-of-type::first-letter {
|
||||
font-family: var(--font-heading, var(--font-sans));
|
||||
font-size: 3.2em;
|
||||
font-weight: 800;
|
||||
float: left;
|
||||
line-height: 0.85;
|
||||
margin: 0.05em 0.12em 0 0;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.article-body h2 {
|
||||
font-family: var(--font-sans);
|
||||
font-family: var(--font-heading, var(--font-sans));
|
||||
font-size: var(--text-2xl);
|
||||
margin-top: var(--space-8);
|
||||
font-weight: 800;
|
||||
margin-top: var(--space-10);
|
||||
margin-bottom: var(--space-4);
|
||||
padding-bottom: var(--space-2);
|
||||
border-bottom: 2px solid var(--color-border);
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.article-body h3 {
|
||||
font-family: var(--font-sans);
|
||||
font-family: var(--font-heading, var(--font-sans));
|
||||
font-size: var(--text-xl);
|
||||
margin-top: var(--space-6);
|
||||
font-weight: 700;
|
||||
margin-top: var(--space-8);
|
||||
margin-bottom: var(--space-3);
|
||||
color: var(--color-secondary);
|
||||
}
|
||||
|
||||
.article-body p {
|
||||
@@ -370,19 +386,92 @@ img {
|
||||
margin-bottom: var(--space-2);
|
||||
}
|
||||
|
||||
.article-body li::marker {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.article-body a {
|
||||
color: var(--color-primary);
|
||||
text-decoration: underline;
|
||||
text-decoration-thickness: 1px;
|
||||
text-underline-offset: 3px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.article-body a:hover {
|
||||
color: var(--color-primary-dark, var(--color-secondary));
|
||||
}
|
||||
|
||||
.article-body blockquote {
|
||||
border-left: 4px solid var(--color-primary);
|
||||
padding-left: var(--space-4);
|
||||
margin: var(--space-6) 0;
|
||||
padding: var(--space-4) var(--space-5);
|
||||
margin: var(--space-8) 0;
|
||||
font-style: italic;
|
||||
color: var(--color-text-muted);
|
||||
background: var(--inst-surface-muted, var(--color-bg-secondary));
|
||||
border-radius: 0 10px 10px 0;
|
||||
font-size: 1.15em;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.article-body img,
|
||||
.article-body figure img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border-radius: 10px;
|
||||
margin: var(--space-6) auto;
|
||||
display: block;
|
||||
box-shadow: var(--shadow-md);
|
||||
}
|
||||
|
||||
.article-body figure {
|
||||
margin: var(--space-8) 0;
|
||||
}
|
||||
|
||||
.article-body figcaption {
|
||||
font-family: var(--font-sans);
|
||||
font-size: var(--text-sm);
|
||||
color: var(--color-text-muted);
|
||||
text-align: center;
|
||||
margin-top: var(--space-2);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.article-body hr {
|
||||
border: none;
|
||||
height: 2px;
|
||||
background: linear-gradient(90deg, var(--color-primary), transparent);
|
||||
margin: var(--space-10) 0;
|
||||
}
|
||||
|
||||
.article-body table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: var(--space-6) 0;
|
||||
font-family: var(--font-sans);
|
||||
font-size: var(--text-sm);
|
||||
}
|
||||
|
||||
.article-body th,
|
||||
.article-body td {
|
||||
border: 1px solid var(--color-border);
|
||||
padding: var(--space-3);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.article-body th {
|
||||
background: var(--color-bg-secondary);
|
||||
font-weight: 700;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.article-body strong {
|
||||
font-weight: 700;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.article-body em {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* ---- Scrollbar ---- */
|
||||
|
||||
@@ -10,54 +10,132 @@ interface Props {
|
||||
const { games, locale } = Astro.props;
|
||||
const ui = getUiStrings(locale);
|
||||
|
||||
function format_score(game: FpaAgendaGame): string {
|
||||
if (game.home_goals !== null && game.away_goals !== null) {
|
||||
return `${game.home_goals} – ${game.away_goals}`;
|
||||
}
|
||||
return '—';
|
||||
function team_initials(name: string): string {
|
||||
const parts = name.trim().split(/\s+/).filter(Boolean);
|
||||
if (parts.length === 0) return '?';
|
||||
if (parts.length === 1) return parts[0]!.slice(0, 2).toUpperCase();
|
||||
return (parts[0]![0]! + parts[parts.length - 1]![0]!).toUpperCase();
|
||||
}
|
||||
|
||||
function is_finished(game: FpaAgendaGame): boolean {
|
||||
return game.home_goals !== null && game.away_goals !== null;
|
||||
}
|
||||
|
||||
function format_score(game: FpaAgendaGame): string | null {
|
||||
if (!is_finished(game)) return null;
|
||||
return `${game.home_goals} – ${game.away_goals}`;
|
||||
}
|
||||
|
||||
const by_date = new Map<string, FpaAgendaGame[]>();
|
||||
for (const game of games) {
|
||||
const list = by_date.get(game.date) ?? [];
|
||||
list.push(game);
|
||||
by_date.set(game.date, list);
|
||||
}
|
||||
const date_groups = [...by_date.entries()];
|
||||
---
|
||||
<section class="fpa-agenda" aria-labelledby="fpa-agenda-title">
|
||||
<div class="container">
|
||||
<header class="fpa-agenda__head">
|
||||
<h2 id="fpa-agenda-title" class="fpa-agenda__title">{ui.fpa_agenda_title}</h2>
|
||||
<p class="fpa-agenda__lead">{ui.fpa_agenda_lead}</p>
|
||||
</header>
|
||||
<header class="fpa-agenda__masthead">
|
||||
<div class="container">
|
||||
<div class="fpa-agenda__masthead-inner">
|
||||
<div class="fpa-agenda__masthead-text">
|
||||
<p class="fpa-agenda__eyebrow">{ui.fpa_col_competition}</p>
|
||||
<h2 id="fpa-agenda-title" class="fpa-agenda__title">{ui.fpa_agenda_title}</h2>
|
||||
<p class="fpa-agenda__lead">{ui.fpa_agenda_lead}</p>
|
||||
</div>
|
||||
{games.length > 0 && (
|
||||
<div class="fpa-agenda__stat" aria-hidden="true">
|
||||
<span class="fpa-agenda__stat-value">{games.length}</span>
|
||||
<span class="fpa-agenda__stat-label">{ui.fpa_games_on_date(games.length)}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="container fpa-agenda__body">
|
||||
{games.length === 0 ? (
|
||||
<p class="fpa-agenda__empty" role="status">{ui.fpa_agenda_empty}</p>
|
||||
) : (
|
||||
<div class="fpa-agenda__scroll" tabindex="0">
|
||||
<table class="fpa-agenda__table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">{ui.fpa_col_when}</th>
|
||||
<th scope="col">{ui.fpa_col_match}</th>
|
||||
<th scope="col">{ui.fpa_col_score}</th>
|
||||
<th scope="col" class="fpa-agenda__hide-narrow">{ui.fpa_col_venue}</th>
|
||||
<th scope="col" class="fpa-agenda__hide-narrow">{ui.fpa_col_competition}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{games.map((g) => (
|
||||
<tr>
|
||||
<td class="fpa-agenda__when">
|
||||
<span class="fpa-agenda__date">{g.date}</span>
|
||||
<span class="fpa-agenda__time">{g.time}</span>
|
||||
</td>
|
||||
<td class="fpa-agenda__match">
|
||||
<span class="fpa-agenda__team fpa-agenda__team--home">{g.home_team}</span>
|
||||
<span class="fpa-agenda__vs" aria-hidden="true">vs</span>
|
||||
<span class="fpa-agenda__team fpa-agenda__team--away">{g.away_team}</span>
|
||||
{g.phase && <span class="fpa-agenda__phase">{g.phase}</span>}
|
||||
</td>
|
||||
<td class="fpa-agenda__score">{format_score(g)}</td>
|
||||
<td class="fpa-agenda__hide-narrow">{g.venue}</td>
|
||||
<td class="fpa-agenda__hide-narrow fpa-agenda__comp">{g.competition}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="fpa-agenda__days">
|
||||
{date_groups.map(([date, day_games]) => (
|
||||
<section class="fpa-agenda__day" aria-label={`${date}`}>
|
||||
<header class="fpa-agenda__day-head">
|
||||
<time class="fpa-agenda__day-date" datetime={date}>{date}</time>
|
||||
<span class="fpa-agenda__day-count">{ui.fpa_games_on_date(day_games.length)}</span>
|
||||
</header>
|
||||
|
||||
<ul class="fpa-agenda__cards" role="list">
|
||||
{day_games.map((g) => {
|
||||
const finished = is_finished(g);
|
||||
const score = format_score(g);
|
||||
return (
|
||||
<li class="fpa-agenda__card" role="listitem">
|
||||
<article class="fpa-agenda__match">
|
||||
<header class="fpa-agenda__match-head">
|
||||
<span class="fpa-agenda__comp">{g.competition}</span>
|
||||
{g.phase && <span class="fpa-agenda__phase">{g.phase}</span>}
|
||||
<span
|
||||
class:list={[
|
||||
'fpa-agenda__status',
|
||||
finished && 'fpa-agenda__status--finished',
|
||||
]}
|
||||
>
|
||||
{finished ? ui.fpa_status_finished : ui.fpa_status_upcoming}
|
||||
</span>
|
||||
</header>
|
||||
|
||||
<div class="fpa-agenda__faceoff">
|
||||
<div class="fpa-agenda__side fpa-agenda__side--home">
|
||||
<span class="fpa-agenda__crest" aria-hidden="true">
|
||||
{team_initials(g.home_team)}
|
||||
</span>
|
||||
<span class="fpa-agenda__team">{g.home_team}</span>
|
||||
</div>
|
||||
|
||||
<div class="fpa-agenda__center">
|
||||
{score ? (
|
||||
<span class="fpa-agenda__score" aria-label={`${ui.fpa_col_score}: ${score}`}>
|
||||
{score}
|
||||
</span>
|
||||
) : (
|
||||
<span class="fpa-agenda__kickoff">
|
||||
<span class="fpa-agenda__kickoff-time">{g.time}</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div class="fpa-agenda__side fpa-agenda__side--away">
|
||||
<span class="fpa-agenda__crest" aria-hidden="true">
|
||||
{team_initials(g.away_team)}
|
||||
</span>
|
||||
<span class="fpa-agenda__team">{g.away_team}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="fpa-agenda__meta">
|
||||
<span class="fpa-agenda__meta-item">
|
||||
<svg class="fpa-agenda__icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/>
|
||||
</svg>
|
||||
<span>{g.time}</span>
|
||||
</span>
|
||||
{g.venue && g.venue !== '—' && (
|
||||
<span class="fpa-agenda__meta-item">
|
||||
<svg class="fpa-agenda__icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
||||
<path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"/><circle cx="12" cy="10" r="3"/>
|
||||
</svg>
|
||||
<span>{g.venue}</span>
|
||||
</span>
|
||||
)}
|
||||
</footer>
|
||||
</article>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</section>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -67,142 +145,370 @@ function format_score(game: FpaAgendaGame): string {
|
||||
|
||||
<style>
|
||||
.fpa-agenda {
|
||||
padding: var(--space-10) 0;
|
||||
background: var(--color-bg-card);
|
||||
border-block: 1px solid var(--color-border);
|
||||
background: var(--color-bg);
|
||||
}
|
||||
|
||||
.fpa-agenda__head {
|
||||
margin-bottom: var(--space-6);
|
||||
max-width: 40rem;
|
||||
.fpa-agenda__masthead {
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
var(--color-primary-dark, #0f2640) 0%,
|
||||
var(--color-primary) 52%,
|
||||
color-mix(in srgb, var(--color-secondary) 80%, #000) 100%
|
||||
);
|
||||
color: #fff;
|
||||
padding: var(--space-8) 0;
|
||||
border-bottom: 4px solid color-mix(in srgb, var(--color-secondary) 65%, #fff);
|
||||
}
|
||||
|
||||
.fpa-agenda__masthead-inner {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: space-between;
|
||||
gap: var(--space-6);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.fpa-agenda__eyebrow {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: var(--text-xs);
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.14em;
|
||||
opacity: 0.82;
|
||||
margin: 0 0 var(--space-2);
|
||||
}
|
||||
|
||||
.fpa-agenda__title {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: clamp(1.25rem, 2.2vw, 1.65rem);
|
||||
font-weight: 600;
|
||||
color: var(--color-primary);
|
||||
font-size: clamp(1.5rem, 3.5vw, 2.25rem);
|
||||
font-weight: 900;
|
||||
line-height: 1.1;
|
||||
letter-spacing: -0.02em;
|
||||
text-transform: uppercase;
|
||||
margin: 0 0 var(--space-2);
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.fpa-agenda__lead {
|
||||
margin: 0;
|
||||
font-size: var(--text-sm);
|
||||
line-height: 1.55;
|
||||
color: var(--color-text-muted);
|
||||
color: rgba(255, 255, 255, 0.86);
|
||||
max-width: 36rem;
|
||||
}
|
||||
|
||||
.fpa-agenda__stat {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 5.5rem;
|
||||
padding: var(--space-3) var(--space-4);
|
||||
border-radius: var(--inst-radius-lg, 10px);
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
|
||||
.fpa-agenda__stat-value {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: clamp(1.75rem, 4vw, 2.5rem);
|
||||
font-weight: 900;
|
||||
line-height: 1;
|
||||
letter-spacing: -0.03em;
|
||||
}
|
||||
|
||||
.fpa-agenda__stat-label {
|
||||
margin-top: var(--space-1);
|
||||
font-size: var(--text-xs);
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
opacity: 0.85;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.fpa-agenda__body {
|
||||
padding: var(--space-8) 0 var(--space-10);
|
||||
}
|
||||
|
||||
.fpa-agenda__empty {
|
||||
margin: 0 0 var(--space-4);
|
||||
padding: var(--space-8);
|
||||
text-align: center;
|
||||
color: var(--color-text-muted);
|
||||
font-size: var(--text-sm);
|
||||
font-size: var(--text-base);
|
||||
background: var(--color-bg-secondary);
|
||||
border: 1px dashed var(--color-border);
|
||||
border-radius: var(--inst-radius-lg, 8px);
|
||||
}
|
||||
|
||||
.fpa-agenda__scroll {
|
||||
overflow-x: auto;
|
||||
.fpa-agenda__days {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-8);
|
||||
}
|
||||
|
||||
.fpa-agenda__day-head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: var(--space-4);
|
||||
margin-bottom: var(--space-4);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
background: var(--color-bg, #fff);
|
||||
padding-bottom: var(--space-3);
|
||||
border-bottom: 2px solid var(--color-primary);
|
||||
}
|
||||
|
||||
.fpa-agenda__table {
|
||||
width: 100%;
|
||||
min-width: 520px;
|
||||
border-collapse: collapse;
|
||||
font-size: var(--text-sm);
|
||||
}
|
||||
|
||||
.fpa-agenda__table th {
|
||||
text-align: left;
|
||||
padding: var(--space-3) var(--space-3);
|
||||
.fpa-agenda__day-date {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-weight: 600;
|
||||
font-size: clamp(1rem, 2vw, 1.2rem);
|
||||
font-weight: 800;
|
||||
letter-spacing: -0.01em;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.fpa-agenda__day-count {
|
||||
font-size: var(--text-xs);
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.fpa-agenda__cards {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: var(--space-4);
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
.fpa-agenda__cards {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1100px) {
|
||||
.fpa-agenda__cards {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
.fpa-agenda__match {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
background: var(--color-bg-card);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--inst-radius-lg, 10px);
|
||||
box-shadow: var(--shadow-sm);
|
||||
overflow: hidden;
|
||||
transition:
|
||||
box-shadow 0.2s ease,
|
||||
border-color 0.15s ease,
|
||||
transform 0.2s ease;
|
||||
}
|
||||
|
||||
.fpa-agenda__match:hover {
|
||||
border-color: color-mix(in srgb, var(--color-secondary) 55%, var(--color-border));
|
||||
box-shadow: var(--inst-shadow-feature, var(--shadow-md));
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.fpa-agenda__match-head {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
padding: var(--space-3) var(--space-4);
|
||||
background: var(--inst-surface-muted, var(--color-bg-secondary));
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.fpa-agenda__table td {
|
||||
padding: var(--space-3) var(--space-3);
|
||||
vertical-align: top;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.fpa-agenda__table tbody tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.fpa-agenda__when {
|
||||
white-space: nowrap;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.fpa-agenda__date {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.fpa-agenda__time {
|
||||
display: block;
|
||||
font-size: var(--text-xs);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.fpa-agenda__match {
|
||||
min-width: 12rem;
|
||||
}
|
||||
|
||||
.fpa-agenda__team {
|
||||
display: block;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.fpa-agenda__vs {
|
||||
display: block;
|
||||
font-size: var(--text-xs);
|
||||
color: var(--color-text-muted);
|
||||
margin: 0.15rem 0;
|
||||
text-transform: lowercase;
|
||||
.fpa-agenda__comp {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: 0.65rem;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--color-secondary);
|
||||
line-height: 1.3;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.fpa-agenda__phase {
|
||||
display: block;
|
||||
margin-top: var(--space-2);
|
||||
font-size: var(--text-xs);
|
||||
color: var(--color-secondary);
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.fpa-agenda__score {
|
||||
font-variant-numeric: tabular-nums;
|
||||
font-size: 0.65rem;
|
||||
font-weight: 600;
|
||||
padding: 0.15rem 0.5rem;
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--color-primary) 10%, var(--color-bg-card));
|
||||
color: var(--color-primary);
|
||||
border: 1px solid color-mix(in srgb, var(--color-primary) 20%, transparent);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.fpa-agenda__comp {
|
||||
max-width: 14rem;
|
||||
line-height: 1.35;
|
||||
.fpa-agenda__status {
|
||||
margin-left: auto;
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: 0.6rem;
|
||||
font-weight: 800;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
padding: 0.2rem 0.55rem;
|
||||
border-radius: 4px;
|
||||
background: color-mix(in srgb, var(--color-secondary) 14%, var(--color-bg-card));
|
||||
color: var(--color-secondary);
|
||||
border: 1px solid color-mix(in srgb, var(--color-secondary) 25%, transparent);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.fpa-agenda__credit {
|
||||
margin: 0;
|
||||
.fpa-agenda__status--finished {
|
||||
background: color-mix(in srgb, var(--color-primary) 12%, var(--color-bg-card));
|
||||
color: var(--color-primary);
|
||||
border-color: color-mix(in srgb, var(--color-primary) 22%, transparent);
|
||||
}
|
||||
|
||||
.fpa-agenda__faceoff {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto 1fr;
|
||||
align-items: center;
|
||||
gap: var(--space-3);
|
||||
padding: var(--space-5) var(--space-4) var(--space-4);
|
||||
}
|
||||
|
||||
.fpa-agenda__side {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
min-width: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.fpa-agenda__crest {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 2.75rem;
|
||||
height: 2.75rem;
|
||||
border-radius: 50%;
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: 0.8rem;
|
||||
font-weight: 800;
|
||||
letter-spacing: 0.02em;
|
||||
color: #fff;
|
||||
background: linear-gradient(
|
||||
145deg,
|
||||
var(--color-primary) 0%,
|
||||
color-mix(in srgb, var(--color-secondary) 70%, var(--color-primary)) 100%
|
||||
);
|
||||
box-shadow: 0 4px 12px color-mix(in srgb, var(--color-primary) 25%, transparent);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.fpa-agenda__side--away .fpa-agenda__crest {
|
||||
background: linear-gradient(
|
||||
145deg,
|
||||
var(--color-secondary) 0%,
|
||||
color-mix(in srgb, var(--color-primary) 55%, var(--color-secondary)) 100%
|
||||
);
|
||||
}
|
||||
|
||||
.fpa-agenda__team {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: var(--text-sm);
|
||||
font-weight: 700;
|
||||
line-height: 1.25;
|
||||
letter-spacing: -0.01em;
|
||||
color: var(--color-text);
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.fpa-agenda__center {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 4.5rem;
|
||||
}
|
||||
|
||||
.fpa-agenda__score {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: clamp(1.25rem, 3vw, 1.6rem);
|
||||
font-weight: 900;
|
||||
font-variant-numeric: tabular-nums;
|
||||
letter-spacing: -0.02em;
|
||||
color: var(--color-primary);
|
||||
padding: var(--space-2) var(--space-3);
|
||||
border-radius: 8px;
|
||||
background: color-mix(in srgb, var(--color-primary) 8%, var(--color-bg-card));
|
||||
border: 1px solid color-mix(in srgb, var(--color-primary) 18%, transparent);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.fpa-agenda__kickoff {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.15rem;
|
||||
}
|
||||
|
||||
.fpa-agenda__kickoff-time {
|
||||
font-family: var(--font-heading, inherit);
|
||||
font-size: var(--text-lg);
|
||||
font-weight: 800;
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: var(--color-secondary);
|
||||
padding: var(--space-2) var(--space-3);
|
||||
border-radius: 8px;
|
||||
border: 1px dashed color-mix(in srgb, var(--color-secondary) 40%, var(--color-border));
|
||||
background: var(--color-bg);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.fpa-agenda__meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-3) var(--space-4);
|
||||
margin-top: auto;
|
||||
padding: var(--space-3) var(--space-4);
|
||||
border-top: 1px solid var(--color-border);
|
||||
font-size: var(--text-xs);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.fpa-agenda__hide-narrow {
|
||||
display: none;
|
||||
}
|
||||
.fpa-agenda__meta-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.fpa-agenda__table {
|
||||
min-width: 0;
|
||||
}
|
||||
.fpa-agenda__meta-item span:last-child {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
max-width: 14rem;
|
||||
}
|
||||
|
||||
.fpa-agenda__icon {
|
||||
flex-shrink: 0;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.fpa-agenda__credit {
|
||||
margin: var(--space-6) 0 0;
|
||||
font-size: var(--text-xs);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,378 @@
|
||||
/**
|
||||
* Smart backfill: attach featured images to andebol.net posts using source URL extraction.
|
||||
*
|
||||
* Strategy:
|
||||
* 1. Fetch WP posts without featured_media (with content)
|
||||
* 2. Extract source URL from post content (FPA, IHF, EHF, Handball-Planet links)
|
||||
* 3. For FPA sources: query FPA WP API for the article's featured image
|
||||
* 4. For other sources: scrape og:image from the source page HTML
|
||||
* 5. For FPA posts without source URL: title-based search on FPA API
|
||||
* 6. Upload image to WP and set featured_media
|
||||
*
|
||||
* Usage:
|
||||
* node dist/backfill-featured-smart.js [--dry-run] [--limit N] [--post-id N] [--skip-sourceless]
|
||||
*
|
||||
* Requires ANDEBOL_WP_USER + ANDEBOL_WP_APP_PASSWORD (see wp-site-env.ts).
|
||||
* Optional: WRITER_WEBDAV_* for WebDAV archive fallback.
|
||||
*/
|
||||
|
||||
import { attachFeaturedImageToPost, resolveFeaturedImageForDraft, type WpPublishConfig } from './wp-publish.js';
|
||||
import { wpCredentialsForSite } from './wp-site-env.js';
|
||||
import { fetchArticleHtmlForMeta } from './legacy-fetch.js';
|
||||
import { absolutizeImageUrl, extractFeaturedImageFromHtml } from './html-meta.js';
|
||||
import { readWebDavArchiveFromEnv, resolveFeaturedFromWebDavArchive, type WebDavArchiveConfig } from './webdav-archive.js';
|
||||
|
||||
const FPA_WP_BASE = 'https://portal.fpa.pt/wp-json';
|
||||
const SITE_DOMAIN = 'andebol.net';
|
||||
|
||||
function argFlag(name: string, argv: string[]): boolean {
|
||||
return argv.includes(name);
|
||||
}
|
||||
|
||||
function argValue(name: string, argv: string[]): string | undefined {
|
||||
const i = argv.indexOf(name);
|
||||
return i >= 0 ? argv[i + 1] : undefined;
|
||||
}
|
||||
|
||||
function wpHeaders(cfg: WpPublishConfig): Record<string, string> {
|
||||
const auth = Buffer.from(`${cfg.username}:${cfg.appPassword}`, 'utf8').toString('base64');
|
||||
const h: Record<string, string> = {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Basic ${auth}`,
|
||||
};
|
||||
if (cfg.siteDomain) h['X-Site-Domain'] = cfg.siteDomain;
|
||||
return h;
|
||||
}
|
||||
|
||||
function toPublishConfig(creds: ReturnType<typeof wpCredentialsForSite>): WpPublishConfig {
|
||||
return {
|
||||
wpBase: creds.wpBase,
|
||||
username: creds.wpUser,
|
||||
appPassword: creds.wpPass,
|
||||
siteDomain: creds.siteDomain ?? SITE_DOMAIN,
|
||||
};
|
||||
}
|
||||
|
||||
interface WpPostWithContent {
|
||||
id: number;
|
||||
slug: string;
|
||||
featured_media: number;
|
||||
status: string;
|
||||
content: { rendered: string };
|
||||
title: { rendered: string };
|
||||
}
|
||||
|
||||
/** Extract source URLs from post content HTML */
|
||||
function extractSourceUrls(html: string): { fpa: string[]; other: string[] } {
|
||||
const fpa: string[] = [];
|
||||
const other: string[] = [];
|
||||
const hrefRe = /href="(https?:\/\/[^"]+)"/gi;
|
||||
let m: RegExpExecArray | null;
|
||||
while ((m = hrefRe.exec(html)) !== null) {
|
||||
const url = m[1];
|
||||
if (/portal\.fpa\.pt/.test(url) && !/\/feed\/?$/.test(url)) {
|
||||
fpa.push(url);
|
||||
} else if (!/andebol\.net/.test(url) && !/wordpress\.org/.test(url)) {
|
||||
other.push(url);
|
||||
}
|
||||
}
|
||||
// Dedupe
|
||||
return {
|
||||
fpa: [...new Set(fpa)],
|
||||
other: [...new Set(other)],
|
||||
};
|
||||
}
|
||||
|
||||
async function listPostsMissingFeatured(cfg: WpPublishConfig, limit: number): Promise<WpPostWithContent[]> {
|
||||
const base = cfg.wpBase.replace(/\/$/, '');
|
||||
const out: WpPostWithContent[] = [];
|
||||
let page = 1;
|
||||
while (out.length < limit) {
|
||||
const qs = new URLSearchParams({
|
||||
per_page: '100',
|
||||
page: String(page),
|
||||
status: 'publish',
|
||||
_fields: 'id,slug,featured_media,status,content,title',
|
||||
});
|
||||
const res = await fetch(`${base}/wp/v2/posts?${qs}`, {
|
||||
headers: wpHeaders(cfg),
|
||||
signal: AbortSignal.timeout(20_000),
|
||||
});
|
||||
if (!res.ok) throw new Error(`WP list posts ${res.status}: ${await res.text().catch(() => '')}`);
|
||||
const rows = (await res.json()) as WpPostWithContent[];
|
||||
if (rows.length === 0) break;
|
||||
for (const row of rows) {
|
||||
if (!row.featured_media && row.status === 'publish') {
|
||||
out.push(row);
|
||||
}
|
||||
if (out.length >= limit) break;
|
||||
}
|
||||
if (rows.length < 100) break;
|
||||
page += 1;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Fetch FPA featured image by article URL (not slug) */
|
||||
async function fpaFeaturedForUrl(fpaUrl: string): Promise<{ url: string; credit?: string } | null> {
|
||||
// Try to get the FPA post by its URL
|
||||
const parsed = new URL(fpaUrl);
|
||||
const pathParts = parsed.pathname.replace(/^\/|\/$/g, '').split('/');
|
||||
// FPA URLs are like /2026/06/slug/ — extract the last path segment as potential slug
|
||||
const slug = pathParts[pathParts.length - 1] || pathParts[pathParts.length - 2];
|
||||
if (!slug) return null;
|
||||
|
||||
// Try searching by slug
|
||||
const qs = new URLSearchParams({ slug, _embed: 'wp:featuredmedia' });
|
||||
const res = await fetch(`${FPA_WP_BASE}/wp/v2/posts?${qs}`, {
|
||||
headers: { Accept: 'application/json' },
|
||||
signal: AbortSignal.timeout(15_000),
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
const rows = (await res.json()) as Array<{
|
||||
link?: string;
|
||||
_embedded?: { 'wp:featuredmedia'?: Array<{ source_url?: string; alt_text?: string }> };
|
||||
}>;
|
||||
|
||||
// Find the row that matches our URL
|
||||
const match = rows.find(r => r.link && r.link.replace(/\/$/, '') === fpaUrl.replace(/\/$/, ''));
|
||||
if (!match && rows.length > 0) {
|
||||
// Slug search might return a different article; try first result as best match
|
||||
const first = rows[0];
|
||||
const media = first?._embedded?.['wp:featuredmedia']?.[0];
|
||||
const url = media?.source_url?.trim();
|
||||
if (url) {
|
||||
return { url, credit: media?.alt_text?.trim() || undefined };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
const media = match?._embedded?.['wp:featuredmedia']?.[0];
|
||||
const url = media?.source_url?.trim();
|
||||
if (!url) return null;
|
||||
return { url, credit: media?.alt_text?.trim() || undefined };
|
||||
}
|
||||
|
||||
/** Search FPA by title keywords */
|
||||
async function fpaFeaturedForTitle(title: string): Promise<{ url: string; credit?: string } | null> {
|
||||
// Extract key words from title
|
||||
const clean = title
|
||||
.replace(/<[^>]+>/g, '')
|
||||
.replace(/[^\wÀ-ÿ\s]/g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
const search = clean.split(/\s+/).slice(0, 6).join('+');
|
||||
|
||||
const qs = new URLSearchParams({
|
||||
search,
|
||||
per_page: '5',
|
||||
_embed: 'wp:featuredmedia',
|
||||
});
|
||||
const res = await fetch(`${FPA_WP_BASE}/wp/v2/posts?${qs}`, {
|
||||
headers: { Accept: 'application/json' },
|
||||
signal: AbortSignal.timeout(15_000),
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
const rows = (await res.json()) as Array<{
|
||||
title?: { rendered?: string };
|
||||
_embedded?: { 'wp:featuredmedia'?: Array<{ source_url?: string; alt_text?: string }> };
|
||||
}>;
|
||||
if (rows.length === 0) return null;
|
||||
|
||||
const media = rows[0]._embedded?.['wp:featuredmedia']?.[0];
|
||||
const url = media?.source_url?.trim();
|
||||
if (!url) return null;
|
||||
return { url, credit: media?.alt_text?.trim() || undefined };
|
||||
}
|
||||
|
||||
/** Scrape og:image from a non-FPA source URL */
|
||||
async function scrapeFeaturedFromUrl(sourceUrl: string): Promise<{ url: string; credit?: string } | null> {
|
||||
const html = await fetchArticleHtmlForMeta(sourceUrl);
|
||||
if (!html) return null;
|
||||
const parsed = extractFeaturedImageFromHtml(html);
|
||||
if (!parsed.url) return null;
|
||||
const abs = absolutizeImageUrl(parsed.url, sourceUrl);
|
||||
if (!abs) return null;
|
||||
return { url: abs, credit: parsed.credit };
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const argv = process.argv.slice(2);
|
||||
const dryRun = argFlag('--dry-run', argv);
|
||||
const limit = Math.max(1, parseInt(argValue('--limit', argv) ?? '200', 10));
|
||||
const postIdFilter = argValue('--post-id', argv) ? parseInt(argValue('--post-id', argv)!, 10) : undefined;
|
||||
const skipSourceless = argFlag('--skip-sourceless', argv);
|
||||
|
||||
const creds = wpCredentialsForSite('andebol.net');
|
||||
if (!creds.wpUser || !creds.wpPass) {
|
||||
console.error(`Missing credentials: set ${creds.envHint}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const cfg = toPublishConfig(creds);
|
||||
|
||||
// Optional WebDAV fallback
|
||||
let webDavCfg: WebDavArchiveConfig | null = null;
|
||||
try {
|
||||
webDavCfg = readWebDavArchiveFromEnv();
|
||||
} catch {
|
||||
// WebDAV not configured — that's fine
|
||||
}
|
||||
|
||||
console.log(`=== Smart Backfill: Featured Images for andebol.net ===`);
|
||||
console.log(`Mode: ${dryRun ? 'DRY-RUN' : 'LIVE'}`);
|
||||
console.log(`WebDAV: ${webDavCfg ? 'configured' : 'not configured'}`);
|
||||
console.log();
|
||||
|
||||
const posts = await listPostsMissingFeatured(cfg, limit);
|
||||
console.log(`Published posts without featured_media: ${posts.length}\n`);
|
||||
|
||||
let updated = 0;
|
||||
let skipped = 0;
|
||||
let failed = 0;
|
||||
const errors: string[] = [];
|
||||
|
||||
for (const post of posts) {
|
||||
if (postIdFilter && post.id !== postIdFilter) continue;
|
||||
|
||||
const title = post.title.rendered.replace(/<[^>]+>/g, '').trim();
|
||||
console.log(`\n[${post.id}] ${post.slug}`);
|
||||
console.log(` Title: ${title.slice(0, 80)}${title.length > 80 ? '…' : ''}`);
|
||||
|
||||
// Step 1: Extract source URLs from content
|
||||
const content = post.content?.rendered || '';
|
||||
const sources = extractSourceUrls(content);
|
||||
|
||||
let imageUrl: string | undefined;
|
||||
let imageCredit: string | undefined;
|
||||
let imageSource: string = 'none';
|
||||
|
||||
// Step 2: Try FPA source URL
|
||||
if (sources.fpa.length > 0) {
|
||||
const fpaUrl = sources.fpa[0];
|
||||
console.log(` Source (FPA): ${fpaUrl}`);
|
||||
const featured = await fpaFeaturedForUrl(fpaUrl);
|
||||
if (featured) {
|
||||
imageUrl = featured.url;
|
||||
imageCredit = featured.credit;
|
||||
imageSource = 'fpa-url';
|
||||
console.log(` → Found FPA featured image: ${featured.url.slice(0, 70)}…`);
|
||||
} else {
|
||||
console.log(` → FPA article has no featured image`);
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Try other source URLs (IHF, EHF, Handball-Planet) for og:image
|
||||
if (!imageUrl && sources.other.length > 0) {
|
||||
for (const srcUrl of sources.other.slice(0, 3)) {
|
||||
console.log(` Source (other): ${srcUrl}`);
|
||||
const featured = await scrapeFeaturedFromUrl(srcUrl);
|
||||
if (featured) {
|
||||
imageUrl = featured.url;
|
||||
imageCredit = featured.credit || imageCredit;
|
||||
imageSource = 'og-image';
|
||||
console.log(` → Found og:image: ${featured.url.slice(0, 70)}…`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 4: Try FPA title search for Portuguese articles
|
||||
if (!imageUrl && !sources.fpa.length && !sources.other.length) {
|
||||
// Only search FPA if the title looks Portuguese (contains accented chars or common PT words)
|
||||
const looksPortuguese = /[àáâãéêíóôõúüç]/i.test(title) ||
|
||||
/\b(e|de|do|da|no|na|em|para|com|por|segu|campe|selec|nacional|andebol)\b/i.test(title);
|
||||
|
||||
if (looksPortuguese && !skipSourceless) {
|
||||
console.log(` Trying FPA title search for: ${title.slice(0, 50)}`);
|
||||
const featured = await fpaFeaturedForTitle(title);
|
||||
if (featured) {
|
||||
imageUrl = featured.url;
|
||||
imageCredit = featured.credit;
|
||||
imageSource = 'fpa-title';
|
||||
console.log(` → Found via FPA title search: ${featured.url.slice(0, 70)}…`);
|
||||
}
|
||||
}
|
||||
|
||||
// Step 5: Try WebDAV archive
|
||||
if (!imageUrl && webDavCfg && !skipSourceless) {
|
||||
console.log(` Trying WebDAV archive`);
|
||||
try {
|
||||
const davResult = await resolveFeaturedFromWebDavArchive(webDavCfg, {
|
||||
id: `backfill-${post.id}`,
|
||||
site: 'andebol.net',
|
||||
title,
|
||||
url: `https://andebol.net/${post.slug}/`,
|
||||
sourceFeedId: 'backfill',
|
||||
summary: '',
|
||||
publishedAt: new Date().toISOString(),
|
||||
ingestedAt: new Date().toISOString(),
|
||||
});
|
||||
imageUrl = davResult.url;
|
||||
imageCredit = davResult.credit;
|
||||
imageSource = 'webdav';
|
||||
console.log(` → Found WebDAV image: ${davResult.url.slice(0, 70)}…`);
|
||||
} catch (e) {
|
||||
console.log(` → WebDAV: ${(e as Error).message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 6: Skip "html" and test posts
|
||||
if (!imageUrl && /^(html|bit-|test)/i.test(post.slug)) {
|
||||
console.log(` → Skipping test/html post`);
|
||||
skipped += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!imageUrl) {
|
||||
if (skipSourceless) {
|
||||
console.log(` → No image found (skip-sourceless)`);
|
||||
} else {
|
||||
console.log(` → No image found from any source`);
|
||||
}
|
||||
skipped += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dryRun) {
|
||||
console.log(` → [DRY-RUN] Would attach: ${imageUrl.slice(0, 80)}…`);
|
||||
updated += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const mediaId = await attachFeaturedImageToPost(
|
||||
post.id,
|
||||
imageUrl,
|
||||
cfg,
|
||||
imageCredit,
|
||||
);
|
||||
updated += 1;
|
||||
console.log(` → OK: media_id=${mediaId} (source: ${imageSource})`);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : String(e);
|
||||
errors.push(`${post.slug}: ${msg}`);
|
||||
console.error(` → FAIL: ${msg}`);
|
||||
failed += 1;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\n=== BACKFILL SUMMARY ===`);
|
||||
console.log(JSON.stringify({
|
||||
total: posts.length,
|
||||
updated,
|
||||
skipped,
|
||||
failed,
|
||||
dryRun,
|
||||
}, null, 2));
|
||||
|
||||
if (errors.length > 0) {
|
||||
console.error(`\nErrors:\n${errors.join('\n')}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(e => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in new issue
Block a user