Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b97b768057 | ||
|
|
fe9a19603c | ||
|
|
b23ca87102 | ||
|
|
dc1b6dd4f0 | ||
|
|
ded3c71ed6 | ||
|
|
c7329a7ea5 | ||
|
|
de19fb7e1a | ||
|
|
e43f04705a | ||
|
|
c61c19216c | ||
|
|
da539f33aa |
No files matched your search
+4
-4
@@ -2,11 +2,11 @@
|
||||
# Replace/add owners as needed per repository domain.
|
||||
|
||||
# CI and forge metadata
|
||||
/.gitea/ @tiago-neves @david-santos
|
||||
/.gitea/workflows/ @tiago-neves @david-santos
|
||||
/.gitea/ @devops-engineer @founding-engineer
|
||||
/.gitea/workflows/ @devops-engineer @founding-engineer
|
||||
|
||||
# Documentation
|
||||
/docs/ @david-santos @planner
|
||||
/docs/ @founding-engineer
|
||||
|
||||
# Catch-all
|
||||
* @david-santos
|
||||
* @founding-engineer
|
||||
+4
-4
@@ -2,11 +2,11 @@
|
||||
# Replace/add owners as needed per repository domain.
|
||||
|
||||
# CI and forge metadata
|
||||
/.gitea/ @tiago-neves @david-santos
|
||||
/.gitea/workflows/ @tiago-neves @david-santos
|
||||
/.gitea/ @devops-engineer @founding-engineer
|
||||
/.gitea/workflows/ @devops-engineer @founding-engineer
|
||||
|
||||
# Documentation
|
||||
/docs/ @david-santos @planner
|
||||
/docs/ @founding-engineer
|
||||
|
||||
# Catch-all
|
||||
* @david-santos
|
||||
* @founding-engineer
|
||||
+2
-2
@@ -9,8 +9,8 @@
|
||||
"build": "tsc",
|
||||
"start": "node dist/server.js",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "npm run build && node --test dist/lib/sanitize-html.test.js dist/services/ranking.test.js dist/services/aggregator-mapper.test.js dist/services/andeboltv.test.js dist/services/fpa-stream-match.test.js",
|
||||
"test:coverage": "npm run build && node --experimental-test-coverage --test dist/lib/sanitize-html.test.js dist/services/ranking.test.js dist/services/aggregator-mapper.test.js dist/services/andeboltv.test.js dist/services/fpa-stream-match.test.js"
|
||||
"test": "npm run build && node --test dist/lib/sanitize-html.test.js dist/services/ranking.test.js dist/services/aggregator-mapper.test.js dist/services/andeboltv.test.js dist/services/fpa-stream-match.test.js dist/services/fpa-standings-url.test.js",
|
||||
"test:coverage": "npm run build && node --experimental-test-coverage --test dist/lib/sanitize-html.test.js dist/services/ranking.test.js dist/services/aggregator-mapper.test.js dist/services/andeboltv.test.js dist/services/fpa-stream-match.test.js dist/services/fpa-standings-url.test.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fastify/cors": "^9.0.1",
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { AndebolTvStreamEvent } from '../services/andeboltv.js';
|
||||
import { fetch_andeboltv_stream_events } from '../services/andeboltv.js';
|
||||
import { get_fpa_agenda_from_store } from '../services/fpa-agenda.js';
|
||||
import { enrich_fpa_agenda_with_streams } from '../services/fpa-stream-match.js';
|
||||
import { enrich_fpa_agenda_with_standings_urls } from '../services/fpa-standings-url.js';
|
||||
|
||||
// Number of articles per section
|
||||
const HERO_COUNT = 3;
|
||||
@@ -151,7 +152,8 @@ export async function homepage_routes(app: FastifyInstance): Promise<void> {
|
||||
}
|
||||
}),
|
||||
]);
|
||||
return enrich_fpa_agenda_with_streams(games, streams);
|
||||
const with_streams = enrich_fpa_agenda_with_streams(games, streams);
|
||||
return enrich_fpa_agenda_with_standings_urls(with_streams);
|
||||
} catch (err) {
|
||||
app.log.warn({ err, host }, 'FPA agenda fetch failed');
|
||||
return [];
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
enrich_fpa_agenda_with_standings_urls,
|
||||
extract_fpa_competition_code,
|
||||
FPA_STANDINGS_FALLBACK_URL,
|
||||
resolve_fpa_standings_url,
|
||||
} from './fpa-standings-url.js';
|
||||
|
||||
test('extract_fpa_competition_code reads leading PO codes', () => {
|
||||
assert.equal(extract_fpa_competition_code('PO01 - Campeonato Betclic Masculino'), 'PO01');
|
||||
assert.equal(extract_fpa_competition_code('PO01A - Divisao de Honra Masculina'), 'PO01A');
|
||||
assert.equal(extract_fpa_competition_code('PO09 - Campeonato Betclic Feminino'), 'PO09');
|
||||
assert.equal(extract_fpa_competition_code('PARTICULARES SELECOES NACIONAIS'), null);
|
||||
});
|
||||
|
||||
test('resolve_fpa_standings_url maps Betclic leagues to Flashscore tables', () => {
|
||||
assert.match(
|
||||
resolve_fpa_standings_url('PO01 - Campeonato Betclic Masculino'),
|
||||
/campeonato-betclic-masculino\/classificacao\/$/,
|
||||
);
|
||||
assert.match(
|
||||
resolve_fpa_standings_url('PO09 - Campeonato Betclic Feminino'),
|
||||
/campeonato-betclic-feminino\/classificacao\/$/,
|
||||
);
|
||||
});
|
||||
|
||||
test('resolve_fpa_standings_url falls back by gender then national hub', () => {
|
||||
assert.match(
|
||||
resolve_fpa_standings_url('PO02 - Campeonato Nacional 2a Divisao Masculina'),
|
||||
/competicoes-nacionais-andebol-masculino\/$/,
|
||||
);
|
||||
assert.match(
|
||||
resolve_fpa_standings_url('PO10 - Campeonato Nacional 2a Divisao Feminina'),
|
||||
/competicoes-nacionais-andebol-feminino\/$/,
|
||||
);
|
||||
assert.equal(resolve_fpa_standings_url('PARTICULARES SELECOES NACIONAIS'), FPA_STANDINGS_FALLBACK_URL);
|
||||
});
|
||||
|
||||
test('enrich_fpa_agenda_with_standings_urls always sets standings_url', () => {
|
||||
const games: Array<{ competition: string; standings_url?: string | null }> = [
|
||||
{ competition: 'PO01 - Campeonato Betclic Masculino' },
|
||||
{ competition: 'Unknown cup', standings_url: null },
|
||||
];
|
||||
const enriched = enrich_fpa_agenda_with_standings_urls(games);
|
||||
assert.ok(enriched[0]?.standings_url.startsWith('https://'));
|
||||
assert.equal(enriched[1]?.standings_url, FPA_STANDINGS_FALLBACK_URL);
|
||||
});
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Resolve a public standings (classificação) URL for an FPA agenda competition name.
|
||||
*
|
||||
* Agenda rows only expose `PROVA` as a free-text label (e.g. "PO01 - Campeonato Betclic
|
||||
* Masculino"). There is no competition id in the feed. We map known competition codes to
|
||||
* public standings pages (Flashscore for top leagues that publish tables; FPA portal hubs
|
||||
* otherwise), with a national competitions fallback.
|
||||
*/
|
||||
|
||||
const FLASHSCORE_PT = 'https://www.flashscore.pt/andebol/portugal';
|
||||
const PORTAL_FPA = 'https://portal.fpa.pt';
|
||||
|
||||
/** General FPA national competitions hub (final fallback). */
|
||||
export const FPA_STANDINGS_FALLBACK_URL = `${PORTAL_FPA}/competicoes-nacionais/`;
|
||||
|
||||
const PORTAL_MASCULINO = `${PORTAL_FPA}/competicoes-nacionais-andebol-masculino/`;
|
||||
const PORTAL_FEMININO = `${PORTAL_FPA}/competicoes-nacionais-andebol-feminino/`;
|
||||
|
||||
/**
|
||||
* Competition code (from PROVA prefix) → public standings page.
|
||||
* Prefer pages that actually render a league table when available.
|
||||
*/
|
||||
const STANDINGS_BY_CODE: Record<string, string> = {
|
||||
PO01: `${FLASHSCORE_PT}/campeonato-betclic-masculino/classificacao/`,
|
||||
PO01A: PORTAL_MASCULINO,
|
||||
PO02: PORTAL_MASCULINO,
|
||||
PO03: PORTAL_MASCULINO,
|
||||
PO06: PORTAL_MASCULINO,
|
||||
PO09: `${FLASHSCORE_PT}/campeonato-betclic-feminino/classificacao/`,
|
||||
PO09A: PORTAL_FEMININO,
|
||||
PO10: PORTAL_FEMININO,
|
||||
PO12: PORTAL_FEMININO,
|
||||
PO20: `${FLASHSCORE_PT}/taca-de-portugal/`,
|
||||
PO23: PORTAL_FEMININO,
|
||||
};
|
||||
|
||||
/** Extract leading competition code such as PO01 / PO01A / PO09A from a PROVA label. */
|
||||
export function extract_fpa_competition_code(competition: string): string | null {
|
||||
const m = competition.trim().match(/^([A-Z]{1,3}\d{1,3}[A-Z]?)\b/i);
|
||||
return m?.[1] ? m[1].toUpperCase() : null;
|
||||
}
|
||||
|
||||
function gender_hub_url(competition: string): string | null {
|
||||
const lower = competition.toLowerCase();
|
||||
if (/\bfemin/i.test(lower)) {
|
||||
return PORTAL_FEMININO;
|
||||
}
|
||||
if (/\bmascul/i.test(lower)) {
|
||||
return PORTAL_MASCULINO;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns a URL suitable for an external "Classificação" link.
|
||||
*/
|
||||
export function resolve_fpa_standings_url(competition: string): string {
|
||||
const code = extract_fpa_competition_code(competition);
|
||||
if (code && STANDINGS_BY_CODE[code]) {
|
||||
return STANDINGS_BY_CODE[code]!;
|
||||
}
|
||||
|
||||
return gender_hub_url(competition) ?? FPA_STANDINGS_FALLBACK_URL;
|
||||
}
|
||||
|
||||
/** Attach `standings_url` to each agenda game (idempotent). */
|
||||
export function enrich_fpa_agenda_with_standings_urls<T extends { competition: string; standings_url?: string | null }>(
|
||||
games: T[],
|
||||
): Array<T & { standings_url: string }> {
|
||||
return games.map((game) => ({
|
||||
...game,
|
||||
standings_url: game.standings_url || resolve_fpa_standings_url(game.competition),
|
||||
}));
|
||||
}
|
||||
@@ -40,6 +40,11 @@ export interface FpaAgendaGame {
|
||||
stream_status?: 'live' | 'upcoming' | null;
|
||||
/** Convenience flag when `stream_status === 'live'`. */
|
||||
is_live?: boolean;
|
||||
/**
|
||||
* Public standings (classificação) page for this competition.
|
||||
* Resolved from the PROVA label (code map + gender hub + FPA national fallback).
|
||||
*/
|
||||
standings_url?: string | null;
|
||||
}
|
||||
|
||||
export interface CategoryConfig {
|
||||
|
||||
@@ -60,6 +60,7 @@ export type UiStrings = {
|
||||
fpa_status_live: string;
|
||||
fpa_watch_live: string;
|
||||
fpa_watch_stream: string;
|
||||
fpa_standings_link: string;
|
||||
fpa_games_on_date: (count: number) => string;
|
||||
/** News archive page title */
|
||||
news_archive_title: string;
|
||||
@@ -172,6 +173,7 @@ const en: UiStrings = {
|
||||
fpa_status_live: 'Live',
|
||||
fpa_watch_live: 'Watch live',
|
||||
fpa_watch_stream: 'Watch on AndebolTV',
|
||||
fpa_standings_link: 'Standings',
|
||||
fpa_games_on_date: count => (count === 1 ? '1 match' : `${count} matches`),
|
||||
news_archive_title: 'News',
|
||||
news_all_filter: 'All',
|
||||
@@ -268,6 +270,7 @@ const pt: UiStrings = {
|
||||
fpa_status_live: 'Em direto',
|
||||
fpa_watch_live: 'Ver em direto',
|
||||
fpa_watch_stream: 'Ver na AndebolTV',
|
||||
fpa_standings_link: 'Classificação',
|
||||
fpa_games_on_date: count => (count === 1 ? '1 jogo' : `${count} jogos`),
|
||||
news_archive_title: 'Notícias',
|
||||
news_all_filter: 'Todas',
|
||||
|
||||
@@ -70,6 +70,7 @@ const date_groups = [...by_date.entries()];
|
||||
const finished = is_finished(g);
|
||||
const score = format_score(g);
|
||||
const has_stream = Boolean(g.stream_url);
|
||||
const standings_url = g.standings_url || 'https://portal.fpa.pt/competicoes-nacionais/';
|
||||
const is_live = Boolean(g.is_live);
|
||||
const status_label = finished
|
||||
? ui.fpa_status_finished
|
||||
@@ -173,6 +174,14 @@ const date_groups = [...by_date.entries()];
|
||||
<span>{g.venue}</span>
|
||||
</span>
|
||||
)}
|
||||
<a
|
||||
class="fpa-agenda__standings-link"
|
||||
href={standings_url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{ui.fpa_standings_link}
|
||||
</a>
|
||||
{has_stream && (
|
||||
<a
|
||||
class="fpa-agenda__stream-link"
|
||||
@@ -603,15 +612,24 @@ const date_groups = [...by_date.entries()];
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.fpa-agenda__standings-link,
|
||||
.fpa-agenda__stream-link {
|
||||
margin-left: auto;
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 700;
|
||||
color: #a20c17;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.fpa-agenda__standings-link {
|
||||
margin-left: auto;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.fpa-agenda__stream-link {
|
||||
color: #a20c17;
|
||||
}
|
||||
|
||||
.fpa-agenda__standings-link:hover,
|
||||
.fpa-agenda__stream-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,11 @@ export interface FpaAgendaGame {
|
||||
stream_status?: 'live' | 'upcoming' | null;
|
||||
/** Convenience flag when `stream_status === 'live'`. */
|
||||
is_live?: boolean;
|
||||
/**
|
||||
* Public standings (classificação) page for this competition.
|
||||
* Resolved from the PROVA label (code map + gender hub + FPA national fallback).
|
||||
*/
|
||||
standings_url?: string | null;
|
||||
}
|
||||
|
||||
export interface Article {
|
||||
|
||||
@@ -22,9 +22,28 @@ describe('cycleErrorMessageLevel', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps whole-source sitemap failures as error', () => {
|
||||
it('downgrades whole-source sitemap gateway blips to warning (BIT-30847)', () => {
|
||||
assert.equal(
|
||||
cycleErrorMessageLevel(
|
||||
'sitemap eurohandball_sitemap (https://www.eurohandball.com/google-news-sitemap.xml): HTTP 502',
|
||||
),
|
||||
'warning',
|
||||
);
|
||||
assert.equal(
|
||||
cycleErrorMessageLevel('sitemap eurohandball_sitemap (https://www.eurohandball.com/sitemap.xml): HTTP 503'),
|
||||
'warning',
|
||||
);
|
||||
assert.equal(
|
||||
cycleErrorMessageLevel(
|
||||
'sitemap eurohandball_sitemap (https://www.eurohandball.com/google-news-sitemap.xml): HTTP 504',
|
||||
),
|
||||
'warning',
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps whole-source sitemap HTTP 500 as error (actionable upstream/config)', () => {
|
||||
assert.equal(
|
||||
cycleErrorMessageLevel('sitemap eurohandball_sitemap (https://www.eurohandball.com/sitemap.xml): HTTP 500'),
|
||||
'error',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
titleFromArticleUrl,
|
||||
} from './html-listing.js';
|
||||
import {
|
||||
decodeJsonUnicodeEscapes,
|
||||
extractRevistaPdfUrls,
|
||||
isHandballRevistaLead,
|
||||
leadUrlForRevistaEntry,
|
||||
@@ -88,6 +89,21 @@ test('extractRevistaPdfUrls finds absolute and relative PDF hrefs', () => {
|
||||
assert.ok(urls[0].includes('18.06.2026'));
|
||||
});
|
||||
|
||||
test('decodeJsonUnicodeEscapes turns literal \\u2013 into en-dash (BIT-31118)', () => {
|
||||
assert.equal(decodeJsonUnicodeEscapes('Revista-de-Imprensa-\\u2013-12.10.2026.pdf'), 'Revista-de-Imprensa-\u2013-12.10.2026.pdf');
|
||||
});
|
||||
|
||||
test('extractRevistaPdfUrls decodes literal \\u2013 so URL is not /u2013 (BIT-31118)', () => {
|
||||
const html = `
|
||||
"pdf":"https://portal.fpa.pt/wp-content/uploads/2026/10/Revista-de-Imprensa-\\u2013-12.10.2026.pdf"
|
||||
`;
|
||||
const urls = extractRevistaPdfUrls(html, 'https://portal.fpa.pt/media/');
|
||||
assert.equal(urls.length, 1);
|
||||
assert.ok(!urls[0].includes('/u2013'), urls[0]);
|
||||
assert.ok(urls[0].includes('%E2%80%93') || urls[0].includes('\u2013'), urls[0]);
|
||||
assert.ok(urls[0].includes('12.10.2026'));
|
||||
});
|
||||
|
||||
test('publishedAtFromPtDate parses DD/MM/YYYY', () => {
|
||||
const iso = publishedAtFromPtDate('17/06/2026', '2026-01-01T00:00:00.000Z');
|
||||
assert.equal(iso.slice(0, 10), '2026-06-17');
|
||||
@@ -98,6 +114,18 @@ test('pdfDateFromRevistaUrl parses filename date', () => {
|
||||
pdfDateFromRevistaUrl('https://portal.fpa.pt/wp-content/uploads/2026/06/Revista-de-Imprensa-18.06.2026.pdf'),
|
||||
'2026-06-18',
|
||||
);
|
||||
assert.equal(
|
||||
pdfDateFromRevistaUrl(
|
||||
'https://portal.fpa.pt/wp-content/uploads/2026/10/Revista-de-Imprensa-%E2%80%93-12.10.2026.pdf',
|
||||
),
|
||||
'2026-10-12',
|
||||
);
|
||||
assert.equal(
|
||||
pdfDateFromRevistaUrl(
|
||||
'https://portal.fpa.pt/wp-content/uploads/2026/10/Revista-de-Imprensa-12.10.2026-9a3f277b.pdf',
|
||||
),
|
||||
'2026-10-12',
|
||||
);
|
||||
});
|
||||
|
||||
test('isHandballRevistaLead detects andebol keywords', () => {
|
||||
|
||||
@@ -16,6 +16,15 @@ export function cycleErrorMessageLevel(message: string): 'warning' | 'error' {
|
||||
if (message.includes('truncating')) return 'warning';
|
||||
// Per-URL HTML probe failed but other pages in the same source may have succeeded.
|
||||
if (/^sitemap .+ page \(https?:\/\//.test(message)) return 'warning';
|
||||
// Whole-source fetch already retries (http-retry); remaining gateway blips are upstream
|
||||
// noise (BIT-30847 / ERRSIG a92b3521aec8). Keep HTTP 500 as error — that flagged the
|
||||
// broken /sitemap.xml URL fixed in BIT-30741.
|
||||
if (
|
||||
/^sitemap .+ \(https?:\/\//.test(message) &&
|
||||
/: HTTP (502|503|504)\b/.test(message)
|
||||
) {
|
||||
return 'warning';
|
||||
}
|
||||
return 'error';
|
||||
}
|
||||
|
||||
|
||||
@@ -100,13 +100,25 @@ export function isHandballRevistaLead(title: string, source: string): boolean {
|
||||
return /andebol|handball|\behf\b|liga dos campeões de andebol|fpa\b/.test(hay);
|
||||
}
|
||||
|
||||
/**
|
||||
* FPA media JSON sometimes embeds PDF filenames with a *literal* `\u2013`
|
||||
* (en-dash) escape. `new URL` treats `\` as a path separator and turns that
|
||||
* into `/u2013`, which 404s. Decode JSON-style `\uXXXX` before URL parsing
|
||||
* (BIT-31118 / ERRSIG 97ac27c4c5df).
|
||||
*/
|
||||
export function decodeJsonUnicodeEscapes(raw: string): string {
|
||||
return raw.replace(/\\u([0-9a-fA-F]{4})/g, (_, hex: string) =>
|
||||
String.fromCharCode(parseInt(hex, 16)),
|
||||
);
|
||||
}
|
||||
|
||||
export function extractRevistaPdfUrls(html: string, pageUrl: string): string[] {
|
||||
const seen = new Set<string>();
|
||||
const out: string[] = [];
|
||||
|
||||
const add = (raw: string) => {
|
||||
try {
|
||||
const href = new URL(raw, pageUrl).href;
|
||||
const href = new URL(decodeJsonUnicodeEscapes(raw), pageUrl).href;
|
||||
if (!seen.has(href)) {
|
||||
seen.add(href);
|
||||
out.push(href);
|
||||
@@ -134,7 +146,13 @@ export async function parseRevistaPdfBuffer(buffer: Buffer): Promise<RevistaEntr
|
||||
}
|
||||
|
||||
export function pdfDateFromRevistaUrl(pdfUrl: string): string | null {
|
||||
const m = pdfUrl.match(/Revista-de-Imprensa-(\d{2})\.(\d{2})\.(\d{4})\.pdf/i);
|
||||
// Accept hyphen or en-dash before the date, and optional WP hash suffix:
|
||||
// Revista-de-Imprensa-12.10.2026.pdf
|
||||
// Revista-de-Imprensa-–-12.10.2026.pdf
|
||||
// Revista-de-Imprensa-12.10.2026-9a3f277b.pdf
|
||||
const m = pdfUrl.match(
|
||||
/Revista-de-Imprensa-(?:(?:\u2013|%E2%80%93)-)?(\d{2})\.(\d{2})\.(\d{4})(?:-[a-f0-9]+)?\.pdf/i,
|
||||
);
|
||||
if (!m) return null;
|
||||
return `${m[3]}-${m[2]}-${m[1]}`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user