feat: theme system + institutional theme + andebol.net domain config

Add domain-aware theme system (BIT-494, BIT-495, BIT-496, BIT-497):

- Theme architecture: move shared components into src/themes/sports/,
  create src/themes/institutional/ with handball-oriented design
- Domain config: andebol.net.json (institutional theme, pt-PT locale,
  handball categories, WP endpoint port 8081)
- theme.ts library: resolves theme components per domain config
- Updated layouts/pages to use theme-aware component loading
- Updated docs: domains.md, frontend.md with theme system docs
- Smoke test script for andebol.net
- WordPress .env.example with andebol env vars

Note: this work was completed in BIT-494/495/496/497 but was
never committed — committing now to unblock andebol.net deploy.

Co-Authored-By: Paperclip <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This commit is contained in:
committed 2026-03-27 08:38:41 +00:00
1 parent e15e88ef6c
commit 738f847d36
28 files changed
+1587 -91

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
{
"site_name": "Andebol.net",
"tagline": "Notícias de andebol nacional e internacional",
"theme": "institutional",
"logo": "/assets/logo.svg",
"favicon": "/favicon.svg",
"primary_color": "#1a3a5c",
"secondary_color": "#4a6fa5",
"accent_color": "#f5f5f5",
"categories": [
{ "slug": "nacional", "label": "Nacional" },
{ "slug": "internacional", "label": "Internacional" },
{ "slug": "selecao", "label": "Seleção" },
{ "slug": "clubes", "label": "Clubes" },
{ "slug": "competicoes", "label": "Competições" },
{ "slug": "resultados", "label": "Resultados" }
],
"bridge_endpoint": "http://127.0.0.1:3200",
"wp_endpoint": "http://127.0.0.1:8081/wp-json",
"locale": "pt-PT",
"timezone": "Europe/Lisbon",
"ads_enabled": false,
"analytics_id": null
}
+23
View File
@@ -0,0 +1,23 @@
{
"site_name": "FPA Example",
"tagline": "Institutional news and announcements — demo configuration",
"theme": "institutional",
"logo": "/assets/logo.svg",
"favicon": "/favicon.svg",
"primary_color": "#1a3a5c",
"secondary_color": "#4a6fa5",
"accent_color": "#f5f5f5",
"categories": [
{ "slug": "federations", "label": "Federations" },
{ "slug": "news", "label": "News" },
{ "slug": "events", "label": "Events" },
{ "slug": "results", "label": "Results" },
{ "slug": "media", "label": "Media" }
],
"bridge_endpoint": "http://localhost:3200",
"wp_endpoint": "http://localhost:8080/wp-json",
"locale": "en-US",
"timezone": "Europe/Lisbon",
"ads_enabled": false,
"analytics_id": null
}
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Smoke tests for andebol.net (or local Nginx on the CT).
# Usage:
# BASE_URL=https://andebol.net ./deploy/scripts/smoke-andebol.sh
# BASE_URL=http://127.0.0.1 HOST=andebol.net ./deploy/scripts/smoke-andebol.sh # on the LXC
set -euo pipefail
BASE_URL="${BASE_URL:-https://andebol.net}"
BASE_URL="${BASE_URL%/}"
HOST_HEADER="${HOST:-andebol.net}"
fail() { echo "SMOKE FAIL: $*" >&2; exit 1; }
ok() { echo "OK: $*"; }
code_for() {
curl -fsS -o /dev/null -w '%{http_code}' --max-time 25 -H "Host: $HOST_HEADER" "$1"
}
log_json() {
curl -fsS --max-time 15 -H "Host: $HOST_HEADER" "$1" | head -c 400
echo ""
}
# Homepage (Astro SSR with institutional theme)
_c="$(code_for "$BASE_URL/")"
[[ "$_c" == "200" ]] || fail "GET $BASE_URL/ expected 200, got $_c (andebol.net homepage)"
ok "GET / → $_c"
# Bridge health
_c="$(code_for "$BASE_URL/health")"
[[ "$_c" == "200" ]] || fail "GET $BASE_URL/health expected 200, got $_c"
_body="$(log_json "$BASE_URL/health")"
echo "$_body" | grep -q '"status"' || fail "GET /health body missing JSON status field"
ok "GET /health → $_c"
# WordPress REST API (port 8081 via nginx)
_c="$(code_for "$BASE_URL/wp-json/wp/v2/")"
[[ "$_c" == "200" ]] || fail "GET $BASE_URL/wp-json/wp/v2/ expected 200, got $_c (WP andebol :8081)"
ok "GET /wp-json/wp/v2/ → $_c"
echo "All smokes passed for BASE_URL=$BASE_URL (host: $HOST_HEADER)"
+116 -52
View File
@@ -1,59 +1,137 @@
# Multi-Domain Configuration
> **Status:** Stub — implementation in progress (BIT-345)
> **Status:** Active — domain JSON + theme selection (see also [frontend.md](./frontend.md) for theme authoring).
---
## Overview
The platform supports multiple domains without code changes. Each domain has a JSON config file in `config/domains/`. The Astro frontend reads the config at request time based on the `host` header; the bridge routes to the correct WordPress endpoint using the same config.
The platform supports multiple domains without duplicating page code. Each domain has a JSON config file in `config/domains/`. The Astro frontend reads the config at request time based on the `host` header; the bridge routes to the correct WordPress endpoint using the same config.
Switching look-and-feel is done with the `theme` field: it selects a bundle of Astro components under `frontend/src/themes/<name>/`. Adding a **new** theme id still requires registering it in code (see [Theme Authoring](./frontend.md#theme-authoring)).
---
## Adding a New Domain
1. Create `config/domains/<hostname>.json` (see schema below)
2. Configure DNS to point the domain at the server
3. If WordPress is a new instance, deploy it and update `wp_endpoint`
4. No code change. No redeploy. (In SSR mode, Astro reads configs from disk per request.)
2. Set `theme` to a registered theme id (`sports`, `institutional`, or one you added in `frontend/src/lib/theme.ts`)
3. Configure DNS to point the domain at the server
4. If WordPress is a new instance, deploy it and update `wp_endpoint`
5. Redeploy when the config file or theme code changes (SSR reads JSON from disk at runtime, but theme registration is build-time)
---
## Choosing a Theme
Built-in themes:
| Theme id | Directory | When to use |
|----------|-----------|-------------|
| `sports` | `frontend/src/themes/sports/` | Default. Bold sports-portal layout; colours come mainly from domain JSON via CSS variables on `:root`. |
| `institutional` | `frontend/src/themes/institutional/` | Calmer serif-led layout; optional `theme.css` aligns tokens with an institutional palette; still honours domain `primary_color` / `secondary_color` / `accent_color` where the layout uses shared variables. |
**Rules:**
- `theme` in JSON must equal the folder name under `frontend/src/themes/` **and** be listed in `ThemeId` / `THEME_BY_ID` in `frontend/src/lib/theme.ts`. Astro needs static imports for each theme; a folder alone is not enough.
- If `theme` is missing or not registered, the app falls back to **`sports`** (`getThemeComponents()` in `theme.ts`).
**Example — point a domain at the institutional theme:**
```json
{
"site_name": "FPA Example",
"tagline": "Institutional news and announcements",
"theme": "institutional",
"logo": "/assets/logo.svg",
"favicon": "/favicon.svg",
"primary_color": "#1a3a5c",
"secondary_color": "#4a6fa5",
"accent_color": "#f5f5f5",
"categories": [
{ "slug": "news", "label": "News" },
{ "slug": "events", "label": "Events" }
],
"bridge_endpoint": "http://localhost:3200",
"wp_endpoint": "http://localhost:8080/wp-json",
"locale": "en-US",
"timezone": "Europe/Lisbon",
"ads_enabled": false,
"analytics_id": null
}
```
A full sample lives at `config/domains/fpa-example.json`.
**Example — `andebol.net` (institutional theme, Portuguese):**
```json
{
"site_name": "Andebol.net",
"tagline": "Notícias de andebol nacional e internacional",
"theme": "institutional",
"logo": "/assets/logo.svg",
"favicon": "/favicon.svg",
"primary_color": "#1a3a5c",
"secondary_color": "#4a6fa5",
"accent_color": "#f5f5f5",
"categories": [
{ "slug": "nacional", "label": "Nacional" },
{ "slug": "internacional", "label": "Internacional" },
{ "slug": "selecao", "label": "Seleção" },
{ "slug": "clubes", "label": "Clubes" },
{ "slug": "competicoes", "label": "Competições" },
{ "slug": "resultados", "label": "Resultados" }
],
"bridge_endpoint": "http://127.0.0.1:3200",
"wp_endpoint": "http://127.0.0.1:8081/wp-json",
"locale": "pt-PT",
"timezone": "Europe/Lisbon",
"ads_enabled": false,
"analytics_id": null
}
```
Live file: `config/domains/andebol.net.json`. The HTML document language uses the first segment of `locale` (e.g. `pt-PT` → `<html lang="pt">` in `Base.astro`).
**Local smoke test:** the dev server does not read a `HOST` env var for the HTTP `Host` header. Map the hostname and open the site with that host (or send the header manually):
- Add `127.0.0.1 andebol.net` to `/etc/hosts`, run `npm run dev` in `frontend/`, then open `http://andebol.net:4321/`.
- Or: `curl -sI -H 'Host: andebol.net' http://127.0.0.1:4321/` once the dev server is up (response should reflect institutional branding / site name from the JSON).
---
## Config Schema
Shape matches `DomainConfig` in `frontend/src/types/index.ts`:
```jsonc
{
// Identity
"site_name": "Sports News",
"site_description": "The best sports coverage in Portugal",
"tagline": "The best sports coverage in Portugal",
// Must match a registered theme: folder frontend/src/themes/<theme>/ + entry in src/lib/theme.ts
"theme": "sports",
// Visual
"theme": "sports", // maps to src/themes/<theme>/
"logo": "/assets/newsproject/logo.svg",
"favicon": "/assets/newsproject/favicon.ico",
"primary_color": "#e63946",
"secondary_color": "#1d3557",
"accent_color": "#f1faee",
// Navigation
"categories": ["Football", "Basket", "F1", "Tennis", "Rugby"],
"nav_categories": ["Football", "Basket", "F1"],
"categories": [
{ "slug": "football", "label": "Football" },
{ "slug": "basket", "label": "Basket" }
],
// Backend endpoints
"wp_endpoint": "http://wp.newsproject.local/wp-json",
"bridge_endpoint": "http://bridge:3200",
"bridge_endpoint": "http://127.0.0.1:3200",
"wp_endpoint": "http://127.0.0.1:8080/wp-json",
// Locale
"locale": "pt_PT",
"locale": "pt-PT",
"timezone": "Europe/Lisbon",
// Social
"social": {
"twitter": "@handle",
"facebook": "page-name"
},
// Features (future)
"ads": { "enabled": false, "provider": null },
"analytics": { "ga4": null }
"ads_enabled": false,
"analytics_id": null
}
```
@@ -61,45 +139,31 @@ The platform supports multiple domains without code changes. Each domain has a J
## Current Domains
| Domain | Config file | WordPress |
|--------|-------------|-----------|
| `newsproject.bitreport.pt` | `newsproject.bitreport.pt.json` | `http://wp.newsproject.local` |
| Domain | Config file | Notes |
|--------|-------------|--------|
| `newsproject.bitreport.pt` | `newsproject.bitreport.pt.json` | `theme`: `sports` |
| `andebol.net` | `andebol.net.json` | `theme`: `institutional`; `wp_endpoint`: `:8081`; andebol news automation |
| Local dev | `localhost.json` | Fallback when hostname file is missing |
---
## Domain Resolution in Astro
```typescript
// src/lib/domain.ts
import { readFileSync, existsSync } from "node:fs";
import path from "node:path";
Configs live in the monorepo at `config/domains/`. The loader discovers that directory by walking up from `import.meta.dirname` and from `process.cwd()` until it finds a `config/domains/localhost.json` marker (same idea as the bridge). Override with `DOMAINS_CONFIG_PATH` or `DOMAIN_CONFIG_DIR` if the process working directory is not inside the monorepo checkout.
export function loadDomainConfig(host: string): DomainConfig {
const hostname = host.replace(/:\d+$/, "");
const configPath = path.join(process.cwd(), "config/domains", `${hostname}.json`);
if (!existsSync(configPath)) {
throw new Error(`Domain config not found: ${hostname}`);
}
return JSON.parse(readFileSync(configPath, "utf-8")) as DomainConfig;
}
```
It then loads `hostname.json`, falls back to `localhost.json`, then to a minimal in-code default if both are missing or invalid.
Usage in an Astro page:
```astro
---
// src/pages/index.astro
import { loadDomainConfig } from "../lib/domain";
import { getDomainConfig } from "../lib/domain.js";
import { getThemeComponents } from "../lib/theme.js";
const host = Astro.request.headers.get("host") ?? "localhost";
const config = loadDomainConfig(host);
const config = getDomainConfig(host);
const { Header, Footer } = getThemeComponents(config.theme);
---
<html lang={config.locale}>
<head><title>{config.site_name}</title></head>
...
</html>
```
---
@@ -108,4 +172,4 @@ const config = loadDomainConfig(host);
- Domain config files are **not secrets** — they contain only public-facing site settings
- WordPress endpoints in `wp_endpoint` are internal network addresses; they must not be exposed publicly
- Theme names map to a directory under `frontend/src/themes/`; if a theme is missing, the default theme is used
- **`theme`**: folder under `frontend/src/themes/` **plus** registration in `frontend/src/lib/theme.ts`; unknown ids fall back to **`sports`**
+87 -23
View File
@@ -1,6 +1,6 @@
# Frontend — Astro 5 SSR
> **Status:** Stub — implementation in progress (BIT-345)
> **Status:** Active — SSR, multi-domain config, pluggable themes under `src/themes/`.
---
@@ -8,6 +8,8 @@
The frontend is an Astro 5 SSR application. It renders all pages server-side, resolves the active domain config at request time, fetches data from the Fastify bridge, and returns complete HTML to the client.
**Themes** swap header, footer, and homepage shells (hero, trending, category blocks, article cards) without duplicating routes. Domain JSON field `theme` selects which component set loads; see [domains.md — Choosing a Theme](./domains.md#choosing-a-theme).
---
## Tech Stack
@@ -28,34 +30,39 @@ The frontend is an Astro 5 SSR application. It renders all pages server-side, re
```
frontend/
├── src/
│ ├── layouts/
│ │ └── Base.astro # HTML shell, OG/meta, theme CSS hooks, Header/Footer from theme
│ ├── pages/
│ │ ├── index.astro # Homepage
│ │ ├── [category]/
│ │ │ ├── index.astro # Category listing
│ │ │ └── [slug].astro # Article page
│ │ ├── search.astro # Search results
│ │ ├── sitemap.xml.ts # Dynamic sitemap
│ │ └── robots.txt.ts # Dynamic robots.txt
│ ├── components/
│ │ ├── layout/
│ │ ├── index.astro # Homepage (uses themed blocks + LatestGrid)
│ │ ├── category/[slug].astro
│ │ ├── article/[slug].astro
│ │ ├── sitemap.xml.ts
│ │ └── robots.txt.ts
│ ├── themes/ # One subfolder per theme id (must match domain JSON + theme.ts)
│ │ ├── sports/
│ │ │ ├── Header.astro
│ │ │ ├── Footer.astro
│ │ │ └── BaseLayout.astro
│ │ ├── article/
│ │ │ ├── HeroSection.astro
│ │ │ ├── ArticleCard.astro
│ │ │ ├── ArticleBody.astro
│ │ │ └── ArticleMeta.astro
│ │ │ ├── CategorySection.astro
│ │ │ └── TrendingBar.astro
│ │ ├── institutional/
│ │ │ ├── … (same six components)
│ │ │ └── theme.css # optional token overrides
│ │ └── README.md # short in-repo contract summary
│ ├── components/ # shared, non-themed pieces
│ │ ├── home/
│ │ │ ├── HeroBlock.astro
│ │ │ ├── TrendingBlock.astro
│ │ │ └── CategoryBlock.astro
│ │ └── islands/
│ │ ├── SearchWidget.tsx # React island (client:load)
│ │ └── MobileMenu.tsx # React island (client:load)
│ │ │ └── LatestGrid.astro # picks ArticleCard via getThemeComponents(theme)
│ │ └── article/
│ │ ├── ArticleHeader.astro
│ │ └── RelatedArticles.astro
│ ├── lib/
│ │ ├── domain.ts # Domain config loader
│ │ ├── domain.ts # Domain config loader (config/domains/*.json)
│ │ ├── theme.ts # Theme registry + getThemeComponents()
│ │ ├── bridge.ts # Bridge API client
│ │ └── seo.ts # Meta tag helpers
│ │ └── format.ts
│ ├── types/
│ │ └── index.ts # DomainConfig, ArticleListItem, etc.
│ └── styles/
│ └── global.css
├── astro.config.mjs
@@ -65,9 +72,66 @@ frontend/
---
## Theme Authoring
Use this when adding a third theme or adjusting an existing one. The canonical one-page summary also lives in `frontend/src/themes/README.md`.
### Directory layout
Create `frontend/src/themes/<theme-id>/` with **exactly these six** Astro modules at the theme root (names matter — `theme.ts` imports them by path):
| File | Responsibility | Props (contract) |
|------|----------------|------------------|
| `Header.astro` | Site header and primary nav | `config: DomainConfig` |
| `Footer.astro` | Site footer | `config: DomainConfig` |
| `HeroSection.astro` | Homepage hero | `articles: ArticleListItem[]` (bridge `homepage.hero`) |
| `TrendingBar.astro` | Trending strip | `articles: ArticleListItem[]` (`homepage.trending`) |
| `CategorySection.astro` | One homepage category block | `category: CategoryConfig`, `articles: ArticleListItem[]` |
| `ArticleCard.astro` | Article teaser | `article: ArticleListItem`, optional `size?: 'sm' \| 'md' \| 'lg'`, optional `show_excerpt?: boolean` (default `true`) |
Types are defined in `frontend/src/types/index.ts`. Callers (e.g. `pages/index.astro`, `components/home/LatestGrid.astro`) assume this shape; keep field usage aligned with `ArticleListItem` (`slug`, `title`, `excerpt`, `featured_image`, `featured_image_alt`, `author`, `category`, `published_at`, `reading_time`, flags, etc.).
**Self-contained themes:** inside a theme folder, import sibling components with relative paths (e.g. `./ArticleCard.astro`), not `~/themes/other/…`.
### CSS tokens and `theme.css`
`layouts/Base.astro` injects **global** custom properties from domain config:
- `--color-primary` ← `config.primary_color`
- `--color-secondary` ← `config.secondary_color`
- `--color-accent` ← `config.accent_color`
Themes should use these variables in CSS where possible so domains can rebrand without code changes.
Optional **`theme.css`** in the theme folder can override or extend tokens. Example from `institutional/theme.css`:
- `:root` — `--color-primary`, `--color-secondary`, `--color-accent`, `--font-heading`
- `[data-theme="dark"]` — dark-mode tweaks for the same variables
**Wiring:** `Base.astro` currently loads `institutional/theme.css` only when `config.theme === 'institutional'`. If you add another theme that needs its own sheet, add a matching `<link>` (or shared import) in `Base.astro` for that theme id.
### Registering a theme in `src/lib/theme.ts`
Astro cannot `import()` a `.astro` file from a runtime string. Every theme must be:
1. **Imported** at the top of `theme.ts` (one import per component, or grouped by theme).
2. **Declared** on the `ThemeId` union type (e.g. `'sports' | 'institutional' | 'mytheme'`).
3. **Mapped** in `THEME_BY_ID: Record<ThemeId, ThemeComponents>` with all six components.
`getThemeComponents(theme: string)` normalizes the string to a `ThemeId` and falls back to **`sports`** if the id is unknown.
**Checklist for a new theme `mytheme`:**
1. Add folder `src/themes/mytheme/` with the six required `.astro` files (and optional `theme.css`).
2. Extend `ThemeId` and add `mytheme` to `THEME_BY_ID`.
3. If using `theme.css`, load it from `Base.astro` when `config.theme === 'mytheme'`.
4. Set `"theme": "mytheme"` in the domain JSON for sites that should use it.
---
## Domain Resolution
See [architecture.md#4-multi-domain-routing](./architecture.md#4-multi-domain-routing).
See [architecture.md#4-multi-domain-routing](./architecture.md#4-multi-domain-routing) and [domains.md](./domains.md).
---
@@ -1,11 +1,13 @@
---
import type { ArticleListItem } from '../../types/index.js';
import ArticleCard from '../shared/ArticleCard.astro';
import { getThemeComponents } from '../../lib/theme.js';
interface Props {
theme: string;
articles: ArticleListItem[];
}
const { articles } = Astro.props;
const { theme, articles } = Astro.props;
const { ArticleCard } = getThemeComponents(theme);
---
{articles.length > 0 && (
<section class="related-section" aria-labelledby="related-title">
@@ -1,14 +1,16 @@
---
import type { ArticleListItem } from '../../types/index.js';
import ArticleCard from '../shared/ArticleCard.astro';
import { getThemeComponents } from '../../lib/theme.js';
interface Props {
theme: string;
articles: ArticleListItem[];
title?: string;
show_more_href?: string;
}
const { articles, title = 'Latest News', show_more_href } = Astro.props;
const { theme, articles, title = 'Latest News', show_more_href } = Astro.props;
const { ArticleCard } = getThemeComponents(theme);
---
<section class="latest-section" aria-labelledby="latest-title">
<div class="container">
+6 -2
View File
@@ -1,7 +1,7 @@
---
import '../styles/global.css';
import Header from '../components/layout/Header.astro';
import Footer from '../components/layout/Footer.astro';
import institutionalThemeStylesUrl from '../themes/institutional/theme.css?url';
import { getThemeComponents } from '../lib/theme.js';
import type { DomainConfig } from '../types/index.js';
interface Props {
@@ -26,6 +26,7 @@ const {
const full_title = title === config.site_name ? title : `${title} | ${config.site_name}`;
const canonical_url = canonical ?? Astro.url.href;
const { Header, Footer } = getThemeComponents(config.theme);
---
<!doctype html>
<html lang={config.locale.split('-')[0]} data-theme="light">
@@ -77,6 +78,9 @@ const canonical_url = canonical ?? Astro.url.href;
--color-accent: var(--color-accent);
}
</style>
{config.theme === 'institutional' && (
<link rel="stylesheet" href={institutionalThemeStylesUrl} />
)}
</head>
<body>
<Header config={config} />
+49 -4
View File
@@ -2,16 +2,61 @@ import type { DomainConfig } from '../types/index.js';
import { readFileSync, existsSync } from 'node:fs';
import { resolve, join } from 'node:path';
// Config directory is relative to the monorepo root (two levels up from frontend/)
const CONFIG_DIR = resolve(import.meta.dirname ?? '', '../../../config/domains');
/**
* Resolve `config/domains` for dev (source under `src/lib`), production bundles
* (chunks under `dist/server/chunks/`), and arbitrary `process.cwd()`.
* Matches bridge env vars: `DOMAINS_CONFIG_PATH` or `DOMAIN_CONFIG_DIR`.
*/
function resolve_domains_dir(): string {
const from_env = process.env['DOMAINS_CONFIG_PATH'] ?? process.env['DOMAIN_CONFIG_DIR'];
if (from_env) {
const abs = resolve(from_env);
if (existsSync(join(abs, 'localhost.json'))) {
return abs;
}
}
const start_dirs = new Set<string>([process.cwd()]);
if (typeof import.meta.dirname === 'string' && import.meta.dirname.length > 0) {
start_dirs.add(import.meta.dirname);
}
for (const start of start_dirs) {
let dir = resolve(start);
for (let depth = 0; depth < 14; depth += 1) {
const candidate = join(dir, 'config', 'domains');
if (existsSync(join(candidate, 'localhost.json'))) {
return candidate;
}
const parent = resolve(dir, '..');
if (parent === dir) {
break;
}
dir = parent;
}
}
return resolve(process.cwd(), '..', 'config', 'domains');
}
let cached_domains_dir: string | null = null;
function get_domains_dir(): string {
if (!cached_domains_dir) {
cached_domains_dir = resolve_domains_dir();
}
return cached_domains_dir;
}
export function getDomainConfig(host: string): DomainConfig {
// Strip port if present
const hostname = host.split(':')[0] ?? 'localhost';
const config_dir = get_domains_dir();
const candidates = [
join(CONFIG_DIR, `${hostname}.json`),
join(CONFIG_DIR, 'localhost.json'),
join(config_dir, `${hostname}.json`),
join(config_dir, 'localhost.json'),
];
for (const config_path of candidates) {
+67
View File
@@ -0,0 +1,67 @@
import SportsHeader from '../themes/sports/Header.astro';
import SportsFooter from '../themes/sports/Footer.astro';
import SportsHeroSection from '../themes/sports/HeroSection.astro';
import SportsArticleCard from '../themes/sports/ArticleCard.astro';
import SportsCategorySection from '../themes/sports/CategorySection.astro';
import SportsTrendingBar from '../themes/sports/TrendingBar.astro';
import InstitutionalHeader from '../themes/institutional/Header.astro';
import InstitutionalFooter from '../themes/institutional/Footer.astro';
import InstitutionalHeroSection from '../themes/institutional/HeroSection.astro';
import InstitutionalArticleCard from '../themes/institutional/ArticleCard.astro';
import InstitutionalCategorySection from '../themes/institutional/CategorySection.astro';
import InstitutionalTrendingBar from '../themes/institutional/TrendingBar.astro';
/**
* Themes registered in the static map below. Astro requires static imports for
* `.astro` files; `config.theme` is resolved at build time per route.
*/
export type ThemeId = 'sports' | 'institutional';
export interface ThemeComponents {
Header: typeof SportsHeader;
Footer: typeof SportsFooter;
HeroSection: typeof SportsHeroSection;
ArticleCard: typeof SportsArticleCard;
CategorySection: typeof SportsCategorySection;
TrendingBar: typeof SportsTrendingBar;
}
const sports_theme: ThemeComponents = {
Header: SportsHeader,
Footer: SportsFooter,
HeroSection: SportsHeroSection,
ArticleCard: SportsArticleCard,
CategorySection: SportsCategorySection,
TrendingBar: SportsTrendingBar,
};
const institutional_theme: ThemeComponents = {
Header: InstitutionalHeader,
Footer: InstitutionalFooter,
HeroSection: InstitutionalHeroSection,
ArticleCard: InstitutionalArticleCard,
CategorySection: InstitutionalCategorySection,
TrendingBar: InstitutionalTrendingBar,
};
const THEME_BY_ID: Record<ThemeId, ThemeComponents> = {
sports: sports_theme,
institutional: institutional_theme,
};
const DEFAULT_THEME: ThemeId = 'sports';
function normalize_theme_id(theme: string): ThemeId {
if (theme in THEME_BY_ID) {
return theme as ThemeId;
}
return DEFAULT_THEME;
}
/**
* Returns the themed Astro components for a domain `config.theme` value.
* Unknown theme ids fall back to `sports` until additional themes are registered.
*/
export function getThemeComponents(theme: string): ThemeComponents {
return THEME_BY_ID[normalize_theme_id(theme)];
}
+1 -1
View File
@@ -139,7 +139,7 @@ const breadcrumb_schema = {
</div>
<!-- Related articles -->
<RelatedArticles articles={related} />
<RelatedArticles theme={config.theme} articles={related} />
</div>
</Base>
+2 -1
View File
@@ -1,7 +1,7 @@
---
import Base from '../../layouts/Base.astro';
import ArticleCard from '../../components/shared/ArticleCard.astro';
import { getDomainConfig } from '../../lib/domain.js';
import { getThemeComponents } from '../../lib/theme.js';
import { BridgeClient, MockBridgeClient, bridgeRequestHeaders } from '../../lib/bridge.js';
const { slug } = Astro.params;
@@ -10,6 +10,7 @@ if (!slug) return Astro.redirect('/');
const host = Astro.request.headers.get('host') ?? 'localhost';
const site_host = host.split(':')[0];
const config = getDomainConfig(host);
const { ArticleCard } = getThemeComponents(config.theme);
const page = parseInt(Astro.url.searchParams.get('page') ?? '1', 10);
const per_page = 12;
+3 -3
View File
@@ -1,15 +1,14 @@
---
import Base from '../layouts/Base.astro';
import TrendingBar from '../components/shared/TrendingBar.astro';
import HeroSection from '../components/home/HeroSection.astro';
import LatestGrid from '../components/home/LatestGrid.astro';
import CategorySection from '../components/home/CategorySection.astro';
import { getDomainConfig } from '../lib/domain.js';
import { getThemeComponents } from '../lib/theme.js';
import { BridgeClient, MockBridgeClient, bridgeRequestHeaders } from '../lib/bridge.js';
const host = Astro.request.headers.get('host') ?? 'localhost';
const site_host = host.split(':')[0];
const config = getDomainConfig(host);
const { TrendingBar, HeroSection, CategorySection } = getThemeComponents(config.theme);
let bridge: BridgeClient;
try {
@@ -61,6 +60,7 @@ const website_schema = {
)}
<LatestGrid
theme={config.theme}
articles={homepage.latest}
title="Latest News"
show_more_href="/category/all"
+32
View File
@@ -0,0 +1,32 @@
# Site themes (`src/themes/`)
Each subdirectory is one visual theme (e.g. `sports/`). Domain JSON sets which theme loads via `theme` (see `config/domains/*.json`).
## Contract (required files)
Every theme folder **must** export these `.astro` components at its root:
| File | Role |
|------|------|
| `Header.astro` | Site header / navigation; props: `config` (`DomainConfig`) |
| `Footer.astro` | Site footer; props: `config` |
| `HeroSection.astro` | Homepage hero; props: `articles` (`ArticleListItem[]`) |
| `ArticleCard.astro` | Article teaser; props: `article`, optional `size`, `show_excerpt` |
| `CategorySection.astro` | Homepage category block; props: `category`, `articles` |
| `TrendingBar.astro` | Trending strip; props: `articles` |
Internal imports inside a theme should use **local** paths (e.g. `./ArticleCard.astro`) so the theme stays self-contained.
## Optional: `theme.css`
You may add `theme.css` in the theme folder for overrides of global tokens, for example:
- `--color-primary`
- `--color-secondary`
- `--color-accent`
Register any new stylesheet in the layout or theme entry point when you introduce a theme that needs it. The default `sports` theme relies on `Base.astro` `define:vars` from domain config, so it does not require `theme.css`.
## Registration
Add static imports and an entry in `getThemeComponents()` in `src/lib/theme.ts`. Astro cannot load `.astro` modules from a dynamic string at runtime; each theme must be wired explicitly.
@@ -0,0 +1,229 @@
---
import type { ArticleListItem } from '../../types/index.js';
import { relativeTime, truncate } from '../../lib/format.js';
interface Props {
article: ArticleListItem;
size?: 'sm' | 'md' | 'lg';
show_excerpt?: boolean;
}
const { article, size = 'md', show_excerpt = true } = Astro.props;
const is_large = size === 'lg';
const is_small = size === 'sm';
---
<article class:list={['inst-card', `inst-card--${size}`]}>
<a href={`/article/${article.slug}`} class="inst-card__thumb-link" tabindex="-1" aria-hidden="true">
{article.featured_image ? (
<img
src={article.featured_image}
alt={article.featured_image_alt}
class="inst-card__thumb"
loading="lazy"
decoding="async"
width={is_large ? 800 : is_small ? 200 : 400}
height={is_large ? 450 : is_small ? 130 : 225}
/>
) : (
<div class="inst-card__thumb inst-card__thumb--empty" aria-hidden="true" />
)}
{article.is_featured && (
<span class="inst-card__ribbon">Featured</span>
)}
</a>
<div class="inst-card__body">
<a href={`/category/${article.category.slug}`} class="inst-card__badge">
{article.category.name}
</a>
<h3 class="inst-card__title">
<a href={`/article/${article.slug}`} class="inst-card__title-link">
{is_small ? truncate(article.title, 72) : article.title}
</a>
</h3>
<time class="inst-card__date" datetime={article.published_at}>
{relativeTime(article.published_at)}
</time>
{show_excerpt && !is_small && (
<p class="inst-card__excerpt">{truncate(article.excerpt, 120)}</p>
)}
</div>
</article>
<style>
.inst-card {
display: flex;
flex-direction: column;
height: 100%;
background: var(--color-bg-card);
border: 1px solid #e2e8f0;
border-radius: 2px;
overflow: hidden;
transition: border-color 0.15s ease;
}
[data-theme="dark"] .inst-card {
border-color: var(--color-border);
}
.inst-card:hover {
border-color: var(--color-secondary);
}
.inst-card--sm {
flex-direction: row;
align-items: stretch;
}
.inst-card__thumb-link {
position: relative;
display: block;
overflow: hidden;
flex-shrink: 0;
border-bottom: 1px solid #e2e8f0;
}
[data-theme="dark"] .inst-card__thumb-link {
border-bottom-color: var(--color-border);
}
.inst-card--sm .inst-card__thumb-link {
width: 112px;
border-bottom: none;
border-right: 1px solid #e2e8f0;
}
[data-theme="dark"] .inst-card--sm .inst-card__thumb-link {
border-right-color: var(--color-border);
}
.inst-card--md .inst-card__thumb-link,
.inst-card--lg .inst-card__thumb-link {
aspect-ratio: 16 / 9;
}
.inst-card--sm .inst-card__thumb-link {
width: 112px;
height: 88px;
}
.inst-card__thumb {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
transition: transform 0.35s ease;
}
.inst-card:hover .inst-card__thumb {
transform: scale(1.03);
}
.inst-card__thumb--empty {
min-height: 140px;
background: var(--color-accent);
}
.inst-card--sm .inst-card__thumb--empty {
min-height: 88px;
}
.inst-card__ribbon {
position: absolute;
top: var(--space-2);
left: var(--space-2);
font-size: 0.65rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.05em;
padding: 0.15rem 0.5rem;
background: var(--color-primary);
color: #fff;
border-radius: 2px;
}
.inst-card__body {
padding: var(--space-4);
display: flex;
flex-direction: column;
gap: var(--space-2);
flex: 1;
}
.inst-card--sm .inst-card__body {
padding: var(--space-3);
justify-content: center;
}
.inst-card__badge {
align-self: flex-start;
display: inline-block;
padding: 0.2rem 0.6rem;
border-radius: 999px;
font-size: 0.65rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.05em;
text-decoration: none;
background: rgba(74, 111, 165, 0.15);
color: var(--color-primary);
transition: background 0.15s ease;
}
.inst-card__badge:hover {
background: rgba(74, 111, 165, 0.25);
}
.inst-card__title {
font-family: var(--font-heading, inherit);
font-size: var(--text-base);
font-weight: 600;
line-height: 1.35;
margin: 0;
flex: 1;
}
.inst-card--lg .inst-card__title {
font-size: var(--text-xl);
}
.inst-card--sm .inst-card__title {
font-size: var(--text-sm);
}
.inst-card__title-link {
color: var(--color-text);
text-decoration: none;
transition: color 0.15s ease;
}
.inst-card__title-link:hover {
color: var(--color-primary);
}
.inst-card__date {
font-size: var(--text-xs);
font-weight: 500;
color: var(--color-text-muted);
order: 2;
}
.inst-card--sm .inst-card__date {
order: 3;
}
.inst-card__excerpt {
font-size: var(--text-sm);
color: var(--color-text-muted);
line-height: 1.5;
margin: 0;
order: 3;
}
.inst-card--sm .inst-card__excerpt {
display: none;
}
</style>
@@ -0,0 +1,203 @@
---
import type { ArticleListItem, CategoryConfig } from '../../types/index.js';
import { formatDateShort } from '../../lib/format.js';
import ArticleCard from './ArticleCard.astro';
interface Props {
category: CategoryConfig;
articles: ArticleListItem[];
}
const { category, articles } = Astro.props;
---
{articles.length > 0 && (
<section class="inst-cat" aria-labelledby={`inst-cat-${category.slug}`}>
<div class="container">
<header class="inst-cat__head">
<h2 class="inst-cat__title" id={`inst-cat-${category.slug}`}>{category.label}</h2>
<a href={`/category/${category.slug}`} class="inst-cat__more">
View all
</a>
</header>
<div class="inst-cat__layout">
<div class="inst-cat__lead">
<ArticleCard article={articles[0]!} size="lg" show_excerpt={true} />
</div>
<ul class="inst-cat__list" role="list">
{articles.slice(1, 5).map(article => (
<li class="inst-cat__row">
<a href={`/article/${article.slug}`} class="inst-cat__row-thumb" tabindex="-1" aria-hidden="true">
{article.featured_image ? (
<img
src={article.featured_image}
alt=""
class="inst-cat__row-img"
loading="lazy"
decoding="async"
width="120"
height="80"
/>
) : (
<span class="inst-cat__row-img inst-cat__row-img--empty" aria-hidden="true" />
)}
</a>
<div class="inst-cat__row-text">
<a href={`/category/${article.category.slug}`} class="inst-cat__row-pill">
{article.category.name}
</a>
<h3 class="inst-cat__row-title">
<a href={`/article/${article.slug}`}>{article.title}</a>
</h3>
<time class="inst-cat__row-date" datetime={article.published_at}>
{formatDateShort(article.published_at)}
</time>
</div>
</li>
))}
</ul>
</div>
</div>
</section>
)}
<style>
.inst-cat {
padding: var(--space-10) 0;
border-top: 1px solid var(--color-border);
background: var(--color-bg);
}
.inst-cat__head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: var(--space-4);
margin-bottom: var(--space-6);
padding-bottom: var(--space-3);
border-bottom: 2px solid var(--color-primary);
}
.inst-cat__title {
font-family: var(--font-heading, inherit);
font-size: clamp(1.25rem, 2.5vw, 1.75rem);
font-weight: 600;
color: var(--color-primary);
margin: 0;
}
.inst-cat__more {
font-size: var(--text-sm);
font-weight: 500;
color: var(--color-secondary);
text-decoration: none;
white-space: nowrap;
}
.inst-cat__more:hover {
text-decoration: underline;
}
.inst-cat__layout {
display: grid;
grid-template-columns: 1fr;
gap: var(--space-8);
align-items: start;
}
@media (min-width: 900px) {
.inst-cat__layout {
grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
gap: var(--space-10);
}
}
.inst-cat__list {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 0;
}
.inst-cat__row {
display: grid;
grid-template-columns: 120px 1fr;
gap: var(--space-4);
padding: var(--space-4) 0;
border-bottom: 1px solid var(--color-border);
align-items: start;
}
.inst-cat__row:last-child {
border-bottom: none;
}
.inst-cat__row-thumb {
display: block;
border: 1px solid #e2e8f0;
border-radius: 2px;
overflow: hidden;
flex-shrink: 0;
}
[data-theme="dark"] .inst-cat__row-thumb {
border-color: var(--color-border);
}
.inst-cat__row-img {
width: 120px;
height: 80px;
object-fit: cover;
display: block;
background: var(--color-accent);
}
.inst-cat__row-img--empty {
display: block;
}
.inst-cat__row-text {
display: flex;
flex-direction: column;
gap: var(--space-1);
min-width: 0;
}
.inst-cat__row-pill {
align-self: flex-start;
font-size: 0.65rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.05em;
text-decoration: none;
color: var(--color-secondary);
}
.inst-cat__row-pill:hover {
text-decoration: underline;
}
.inst-cat__row-title {
font-family: var(--font-heading, inherit);
font-size: var(--text-base);
font-weight: 600;
line-height: 1.35;
margin: 0;
}
.inst-cat__row-title a {
color: var(--color-text);
text-decoration: none;
}
.inst-cat__row-title a:hover {
color: var(--color-primary);
}
.inst-cat__row-date {
font-size: var(--text-xs);
color: var(--color-text-muted);
}
</style>
@@ -0,0 +1,83 @@
---
import type { DomainConfig } from '../../types/index.js';
interface Props {
config: DomainConfig;
}
const { config } = Astro.props;
const year = new Date().getFullYear();
---
<footer class="inst-footer" role="contentinfo">
<div class="container">
<div class="inst-footer__main">
<p class="inst-footer__name">{config.site_name}</p>
<ul class="inst-footer__legal" role="list">
<li><a href="/privacy">Privacy</a></li>
<li><a href="/terms">Terms</a></li>
<li><a href="/sitemap.xml">Sitemap</a></li>
</ul>
</div>
<p class="inst-footer__copy">&copy; {year} {config.site_name}. All rights reserved.</p>
</div>
</footer>
<style>
.inst-footer {
background: var(--color-accent);
border-top: 1px solid var(--color-border);
padding: var(--space-10) 0 var(--space-8);
margin-top: var(--space-16);
}
.inst-footer__main {
display: flex;
flex-direction: column;
gap: var(--space-4);
align-items: flex-start;
}
@media (min-width: 640px) {
.inst-footer__main {
flex-direction: row;
align-items: center;
justify-content: space-between;
}
}
.inst-footer__name {
font-family: var(--font-heading, inherit);
font-size: var(--text-lg);
font-weight: 600;
color: var(--color-primary);
margin: 0;
}
.inst-footer__legal {
display: flex;
flex-wrap: wrap;
gap: var(--space-4);
list-style: none;
margin: 0;
padding: 0;
}
.inst-footer__legal a {
font-size: var(--text-sm);
color: var(--color-text-muted);
text-decoration: none;
transition: color 0.15s ease;
}
.inst-footer__legal a:hover {
color: var(--color-primary);
}
.inst-footer__copy {
margin: var(--space-8) 0 0;
padding-top: var(--space-6);
border-top: 1px solid var(--color-border);
font-size: var(--text-sm);
color: var(--color-text-muted);
text-align: center;
}
</style>
@@ -0,0 +1,292 @@
---
import type { DomainConfig } from '../../types/index.js';
interface Props {
config: DomainConfig;
}
const { config } = Astro.props;
const current_path = Astro.url.pathname;
---
<header class="inst-header" role="banner">
<div class="inst-header__inner container">
<a href="#main-content" class="inst-header__skip">Skip to content</a>
<a href="/" class="inst-header__logo" aria-label={`${config.site_name} — home`}>
<span class="inst-header__logo-text">{config.site_name}</span>
</a>
<nav class="inst-header__nav" aria-label="Main navigation">
<ul class="inst-header__nav-list" role="list">
{config.categories.map(cat => (
<li>
<a
href={`/category/${cat.slug}`}
class:list={[
'inst-header__link',
{ 'inst-header__link--active': current_path === `/category/${cat.slug}` },
]}
>
{cat.label}
</a>
</li>
))}
</ul>
</nav>
<div class="inst-header__actions">
<button
type="button"
class="inst-header__icon-btn"
data-theme-toggle
aria-label="Toggle dark/light mode"
title="Toggle theme"
>
<svg class="inst-header__icon-sun" aria-hidden="true" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="4"/><line x1="12" y1="2" x2="12" y2="6"/><line x1="12" y1="18" x2="12" y2="22"/>
<line x1="4.93" y1="4.93" x2="7.76" y2="7.76"/><line x1="16.24" y1="16.24" x2="19.07" y2="19.07"/>
<line x1="2" y1="12" x2="6" y2="12"/><line x1="18" y1="12" x2="22" y2="12"/>
<line x1="4.93" y1="19.07" x2="7.76" y2="16.24"/><line x1="16.24" y1="7.76" x2="19.07" y2="4.93"/>
</svg>
<svg class="inst-header__icon-moon" aria-hidden="true" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
</svg>
</button>
<button
type="button"
class="inst-header__icon-btn inst-header__menu-btn"
aria-label="Open menu"
aria-expanded="false"
aria-controls="inst-mobile-menu"
>
<svg aria-hidden="true" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/>
</svg>
</button>
</div>
</div>
<nav
id="inst-mobile-menu"
class="inst-header__mobile"
aria-label="Mobile navigation"
aria-hidden="true"
>
<ul class="inst-header__mobile-list" role="list">
<li>
<a
href="/"
class:list={['inst-header__mobile-link', { 'inst-header__mobile-link--active': current_path === '/' }]}
>
Home
</a>
</li>
{config.categories.map(cat => (
<li>
<a
href={`/category/${cat.slug}`}
class:list={[
'inst-header__mobile-link',
{ 'inst-header__mobile-link--active': current_path === `/category/${cat.slug}` },
]}
>
{cat.label}
</a>
</li>
))}
</ul>
</nav>
</header>
<style>
.inst-header {
position: sticky;
top: 0;
z-index: 100;
background: #fff;
border-bottom: 1px solid #e2e8f0;
box-shadow: 0 1px 0 rgba(26, 58, 92, 0.06);
height: var(--header-height);
}
[data-theme="dark"] .inst-header {
background: var(--color-bg);
border-bottom-color: var(--color-border);
}
.inst-header__inner {
display: flex;
align-items: center;
gap: var(--space-4);
height: 100%;
}
.inst-header__skip {
position: absolute;
left: -9999px;
top: var(--space-2);
z-index: 999;
background: var(--color-primary);
color: #fff;
padding: var(--space-2) var(--space-4);
border-radius: 4px;
font-weight: 600;
text-decoration: none;
}
.inst-header__skip:focus {
left: var(--space-4);
}
.inst-header__logo {
flex-shrink: 0;
text-decoration: none;
}
.inst-header__logo-text {
font-family: var(--font-heading, inherit);
font-size: var(--text-lg);
font-weight: 600;
color: var(--color-primary);
letter-spacing: 0.02em;
}
.inst-header__nav {
flex: 1;
display: none;
}
@media (min-width: 768px) {
.inst-header__nav {
display: block;
}
.inst-header__menu-btn {
display: none;
}
}
.inst-header__nav-list {
display: flex;
flex-wrap: wrap;
gap: var(--space-1);
list-style: none;
margin: 0;
padding: 0;
}
.inst-header__link {
display: block;
padding: var(--space-2) var(--space-3);
font-size: var(--text-sm);
font-weight: 500;
color: #334155;
border-radius: 4px;
text-decoration: none;
transition: color 0.15s ease, background 0.15s ease;
}
[data-theme="dark"] .inst-header__link {
color: var(--color-text);
}
.inst-header__link:hover,
.inst-header__link--active {
color: var(--color-primary);
background: rgba(74, 111, 165, 0.1);
}
.inst-header__actions {
display: flex;
align-items: center;
gap: var(--space-2);
margin-left: auto;
}
.inst-header__icon-btn {
background: transparent;
border: 1px solid #e2e8f0;
border-radius: 6px;
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
color: var(--color-text);
transition: border-color 0.15s ease, background 0.15s ease;
}
.inst-header__icon-btn:hover {
background: var(--color-accent);
border-color: #cbd5e1;
}
.inst-header__icon-moon {
display: none;
}
[data-theme="dark"] .inst-header__icon-moon {
display: block;
}
[data-theme="dark"] .inst-header__icon-sun {
display: none;
}
.inst-header__mobile {
display: none;
background: #fff;
border-top: 1px solid #e2e8f0;
padding: var(--space-4) var(--space-4) var(--space-6);
}
[data-theme="dark"] .inst-header__mobile {
background: var(--color-bg);
border-top-color: var(--color-border);
}
.inst-header__mobile[aria-hidden="false"] {
display: block;
}
@media (min-width: 768px) {
.inst-header__mobile {
display: none !important;
}
}
.inst-header__mobile-list {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: var(--space-1);
}
.inst-header__mobile-link {
display: block;
padding: var(--space-3) var(--space-4);
font-size: var(--text-base);
font-weight: 500;
border-radius: 6px;
color: var(--color-text);
text-decoration: none;
transition: background 0.15s ease, color 0.15s ease;
}
.inst-header__mobile-link:hover,
.inst-header__mobile-link--active {
background: var(--color-accent);
color: var(--color-primary);
}
</style>
<script>
const btn = document.querySelector('.inst-header__menu-btn') as HTMLButtonElement | null;
const menu = document.getElementById('inst-mobile-menu');
btn?.addEventListener('click', () => {
const is_open = menu?.getAttribute('aria-hidden') === 'false';
menu?.setAttribute('aria-hidden', is_open ? 'true' : 'false');
btn.setAttribute('aria-expanded', is_open ? 'false' : 'true');
btn.setAttribute('aria-label', is_open ? 'Open menu' : 'Close menu');
});
</script>
@@ -0,0 +1,290 @@
---
import type { ArticleListItem } from '../../types/index.js';
import { relativeTime } from '../../lib/format.js';
interface Props {
articles: ArticleListItem[];
}
const { articles } = Astro.props;
const [main, ...rest] = articles;
const secondary = rest.slice(0, 4);
---
{main && (
<section class="inst-hero" aria-label="Featured articles">
<div class="container">
<article class="inst-hero__featured">
<a href={`/article/${main.slug}`} class="inst-hero__featured-media" aria-hidden="true" tabindex="-1">
{main.featured_image ? (
<img
src={main.featured_image}
alt={main.featured_image_alt}
class="inst-hero__featured-img"
loading="eager"
decoding="async"
fetchpriority="high"
width="1200"
height="675"
/>
) : (
<div class="inst-hero__featured-img inst-hero__placeholder" aria-hidden="true">
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" opacity="0.2">
<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/>
<polyline points="21 15 16 10 5 21"/>
</svg>
</div>
)}
</a>
<div class="inst-hero__featured-overlay">
<a href={`/category/${main.category.slug}`} class="inst-hero__pill">{main.category.name}</a>
<h1 class="inst-hero__featured-title">
<a href={`/article/${main.slug}`}>{main.title}</a>
</h1>
<p class="inst-hero__featured-excerpt">{main.excerpt}</p>
<div class="inst-hero__featured-meta">
<span>{main.author.name}</span>
<span aria-hidden="true">·</span>
<time datetime={main.published_at}>{relativeTime(main.published_at)}</time>
<span aria-hidden="true">·</span>
<span>{main.reading_time} min read</span>
</div>
</div>
</article>
{secondary.length > 0 && (
<div class="inst-hero__grid" role="list">
{secondary.map(article => (
<article class="inst-hero__card" role="listitem">
<a href={`/article/${article.slug}`} class="inst-hero__card-media" aria-hidden="true" tabindex="-1">
{article.featured_image ? (
<img
src={article.featured_image}
alt={article.featured_image_alt}
class="inst-hero__card-img"
loading="lazy"
decoding="async"
width="400"
height="225"
/>
) : (
<div class="inst-hero__card-img inst-hero__placeholder inst-hero__placeholder--sm" aria-hidden="true" />
)}
</a>
<div class="inst-hero__card-body">
<a href={`/category/${article.category.slug}`} class="inst-hero__pill inst-hero__pill--muted">
{article.category.name}
</a>
<h2 class="inst-hero__card-title">
<a href={`/article/${article.slug}`}>{article.title}</a>
</h2>
<time class="inst-hero__card-date" datetime={article.published_at}>
{relativeTime(article.published_at)}
</time>
</div>
</article>
))}
</div>
)}
</div>
</section>
)}
<style>
.inst-hero {
padding: var(--space-6) 0 var(--space-8);
background: var(--color-bg);
}
.inst-hero__featured {
position: relative;
border-radius: 4px;
overflow: hidden;
background: #0f172a;
}
.inst-hero__featured-media {
display: block;
}
.inst-hero__featured-img {
width: 100%;
aspect-ratio: 21 / 9;
object-fit: cover;
display: block;
max-height: min(52vh, 520px);
}
@media (max-width: 767px) {
.inst-hero__featured-img {
aspect-ratio: 16 / 10;
max-height: none;
}
}
.inst-hero__placeholder {
min-height: 280px;
display: flex;
align-items: center;
justify-content: center;
background: #1e293b;
color: #94a3b8;
}
.inst-hero__featured-overlay {
position: absolute;
inset: 0;
top: auto;
background: linear-gradient(to top, rgba(15, 23, 42, 0.92) 0%, rgba(15, 23, 42, 0.45) 55%, transparent 100%);
padding: var(--space-6) var(--space-6) var(--space-8);
display: flex;
flex-direction: column;
gap: var(--space-3);
}
.inst-hero__pill {
align-self: flex-start;
display: inline-block;
padding: 0.2rem 0.65rem;
border-radius: 999px;
font-size: 0.7rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.06em;
text-decoration: none;
background: var(--color-secondary);
color: #fff;
}
.inst-hero__pill--muted {
background: rgba(255, 255, 255, 0.2);
color: #fff;
}
.inst-hero__featured-title {
font-family: var(--font-heading, inherit);
font-size: clamp(1.5rem, 4vw, 2.35rem);
font-weight: 600;
line-height: 1.2;
margin: 0;
}
.inst-hero__featured-title a {
color: #fff;
text-decoration: none;
transition: opacity 0.15s ease;
}
.inst-hero__featured-title a:hover {
opacity: 0.88;
}
.inst-hero__featured-excerpt {
font-size: var(--text-sm);
color: rgba(255, 255, 255, 0.82);
line-height: 1.55;
margin: 0;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
@media (max-width: 640px) {
.inst-hero__featured-excerpt {
display: none;
}
}
.inst-hero__featured-meta {
display: flex;
flex-wrap: wrap;
gap: var(--space-2);
align-items: center;
font-size: var(--text-xs);
color: rgba(255, 255, 255, 0.72);
}
.inst-hero__grid {
display: grid;
grid-template-columns: 1fr;
gap: var(--space-4);
margin-top: var(--space-6);
list-style: none;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
padding: 0;
}
@media (min-width: 640px) {
.inst-hero__grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (min-width: 1024px) {
.inst-hero__grid {
grid-template-columns: repeat(4, 1fr);
}
}
.inst-hero__card {
display: flex;
flex-direction: column;
background: var(--color-bg-card);
border: 1px solid var(--color-border);
border-radius: 4px;
overflow: hidden;
transition: box-shadow 0.15s ease;
}
.inst-hero__card:hover {
box-shadow: var(--shadow-sm);
}
.inst-hero__card-media {
display: block;
}
.inst-hero__card-img {
width: 100%;
aspect-ratio: 16 / 9;
object-fit: cover;
display: block;
}
.inst-hero__placeholder--sm {
min-height: 120px;
}
.inst-hero__card-body {
padding: var(--space-4);
display: flex;
flex-direction: column;
gap: var(--space-2);
flex: 1;
}
.inst-hero__card-title {
font-family: var(--font-heading, inherit);
font-size: var(--text-base);
font-weight: 600;
line-height: 1.35;
margin: 0;
flex: 1;
}
.inst-hero__card-title a {
color: var(--color-text);
text-decoration: none;
transition: color 0.15s ease;
}
.inst-hero__card-title a:hover {
color: var(--color-primary);
}
.inst-hero__card-date {
font-size: var(--text-xs);
color: var(--color-text-muted);
}
</style>
@@ -0,0 +1,8 @@
---
import type { ArticleListItem } from '../../types/index.js';
interface Props {
articles: ArticleListItem[];
}
---
<!-- Institutional theme: no trending strip (contract component; renders nothing) -->
@@ -0,0 +1,14 @@
/**
* Institutional theme — token overrides (domain config may also set colours;
* these values align with BIT-495 acceptance palette).
*/
:root {
--color-primary: #1a3a5c;
--color-secondary: #4a6fa5;
--color-accent: #f5f5f5;
--font-heading: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
}
[data-theme="dark"] {
--color-accent: #1e293b;
}
@@ -1,6 +1,6 @@
---
import type { ArticleListItem, CategoryConfig } from '../../types/index.js';
import ArticleCard from '../shared/ArticleCard.astro';
import ArticleCard from './ArticleCard.astro';
interface Props {
category: CategoryConfig;
+8
View File
@@ -20,3 +20,11 @@ WORDPRESS_PUBLIC_URL=http://localhost:8080
# Emergency triage on the LXC only: WORDPRESS_DEBUG=1 → WP_DEBUG + display_errors + debug.log
# (remove or set 0 after fixing — do not leave on in production). See docker-compose.yml WORDPRESS_CONFIG_EXTRA.
# WORDPRESS_DEBUG=0
# ── andebol.net WordPress (port 8081) ─────────────────────────────────────────
ANDEBOL_MYSQL_ROOT_PASSWORD=change_this_andebol_root_password
ANDEBOL_MYSQL_PASSWORD=change_this_andebol_wordpress_password
# Public URL for andebol.net WP instance.
# Local smoke test: http://localhost:8081
# Production (LXC behind NPM): https://andebol.net
ANDEBOL_WORDPRESS_PUBLIC_URL=http://localhost:8081