重构
This commit is contained in:
@@ -25,6 +25,62 @@ const outrightTeams = [...outrightSrc.matchAll(/code: '([^']+)', names: \{ 'zh-C
|
||||
en: m[3],
|
||||
}));
|
||||
|
||||
const CODE_TO_FLAG_ISO = {
|
||||
ALG: 'dz',
|
||||
ARG: 'ar',
|
||||
AUS: 'au',
|
||||
AUT: 'at',
|
||||
BEL: 'be',
|
||||
BIH: 'ba',
|
||||
BRA: 'br',
|
||||
CAN: 'ca',
|
||||
CIV: 'ci',
|
||||
COD: 'cd',
|
||||
COL: 'co',
|
||||
CPV: 'cv',
|
||||
CRO: 'hr',
|
||||
CUW: 'cw',
|
||||
CZE: 'cz',
|
||||
ECU: 'ec',
|
||||
EGY: 'eg',
|
||||
ENG: 'gb-eng',
|
||||
ESP: 'es',
|
||||
FRA: 'fr',
|
||||
GER: 'de',
|
||||
GHA: 'gh',
|
||||
HAI: 'ht',
|
||||
IRN: 'ir',
|
||||
IRQ: 'iq',
|
||||
JOR: 'jo',
|
||||
JPN: 'jp',
|
||||
KOR: 'kr',
|
||||
KSA: 'sa',
|
||||
MAR: 'ma',
|
||||
MEX: 'mx',
|
||||
NED: 'nl',
|
||||
NOR: 'no',
|
||||
NZL: 'nz',
|
||||
PAN: 'pa',
|
||||
PAR: 'py',
|
||||
POR: 'pt',
|
||||
QAT: 'qa',
|
||||
RSA: 'za',
|
||||
SCO: 'gb-sct',
|
||||
SEN: 'sn',
|
||||
SUI: 'ch',
|
||||
SWE: 'se',
|
||||
TUN: 'tn',
|
||||
TUR: 'tr',
|
||||
URU: 'uy',
|
||||
USA: 'us',
|
||||
UZB: 'uz',
|
||||
};
|
||||
|
||||
function flagUrlForCode(code) {
|
||||
const iso = CODE_TO_FLAG_ISO[code];
|
||||
return iso ? `https://flagcdn.com/${iso}.svg` : '';
|
||||
}
|
||||
|
||||
function pickNames(names) {
|
||||
return {
|
||||
zh: names?.zh ?? null,
|
||||
@@ -37,11 +93,12 @@ function pickNames(names) {
|
||||
}
|
||||
|
||||
function pickTeam(team) {
|
||||
const code = resolveCanonicalCode(team);
|
||||
return {
|
||||
id: team.id,
|
||||
name: team.name,
|
||||
names: pickNames(team.names),
|
||||
image: team.image ?? '',
|
||||
image: code ? flagUrlForCode(code) : '',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -65,7 +122,7 @@ function slimMatch(m) {
|
||||
},
|
||||
homeTeam: pickTeam(m.homeTeam),
|
||||
awayTeam: pickTeam(m.awayTeam),
|
||||
status: { state: m.status.state, isHot: m.status.isHot ?? 0 },
|
||||
status: { state: m.status.state, isHot: 0 },
|
||||
venue: {
|
||||
names: pickNames(m.venue?.names),
|
||||
city: pickNames(m.venue?.city),
|
||||
@@ -76,7 +133,6 @@ function slimMatch(m) {
|
||||
}
|
||||
|
||||
function resolveCanonicalCode(team) {
|
||||
if (team.id == null) return null;
|
||||
const en = (team.name || team.names?.en || '').toLowerCase();
|
||||
const zh = team.names?.zh || '';
|
||||
const hit = outrightTeams.find(
|
||||
@@ -104,13 +160,16 @@ for (const m of raw.matches || []) {
|
||||
}
|
||||
|
||||
const zhiboToCode = {};
|
||||
const logoByCode = {};
|
||||
const unmatched = [];
|
||||
const missingFlagCodes = new Set();
|
||||
for (const [id, team] of teamById) {
|
||||
const code = resolveCanonicalCode(team);
|
||||
if (code) {
|
||||
zhiboToCode[id] = code;
|
||||
if (team.image) logoByCode[code] = team.image;
|
||||
const flagUrl = flagUrlForCode(code);
|
||||
if (!flagUrl) {
|
||||
missingFlagCodes.add(code);
|
||||
}
|
||||
} else {
|
||||
unmatched.push({ id, name: team.name });
|
||||
}
|
||||
@@ -125,9 +184,9 @@ const mapLines = Object.entries(zhiboToCode)
|
||||
.map(([id, code]) => ` ${id}: '${code}',`)
|
||||
.join('\n');
|
||||
|
||||
const logoLines = Object.entries(logoByCode)
|
||||
const flagIsoLines = Object.entries(CODE_TO_FLAG_ISO)
|
||||
.sort(([a], [b]) => a.localeCompare(b))
|
||||
.map(([code, url]) => ` ${code}: '${url.replace(/'/g, "\\'")}',`)
|
||||
.map(([code, iso]) => ` ${code}: '${iso}',`)
|
||||
.join('\n');
|
||||
|
||||
const mapTs = `/** 由 build-wc2026-seed-json.mjs 生成 — zhibo externalId → WC2026 canonical code */
|
||||
@@ -135,10 +194,17 @@ export const WC2026_ZIBO_ID_TO_CODE: Record<number, string> = {
|
||||
${mapLines}
|
||||
};
|
||||
|
||||
/** zhibo 球队 logo(seed 时写入 teams.logo_url) */
|
||||
export const WC2026_TEAM_LOGO_BY_CODE: Record<string, string> = {
|
||||
${logoLines}
|
||||
/** WC2026 默认国家/地区国旗(FlagCDN,seed 时写入 teams.logo_url) */
|
||||
export const WC2026_FLAG_ISO_BY_CODE: Record<string, string> = {
|
||||
${flagIsoLines}
|
||||
};
|
||||
|
||||
export const WC2026_TEAM_LOGO_BY_CODE: Record<string, string> = Object.fromEntries(
|
||||
Object.entries(WC2026_FLAG_ISO_BY_CODE).map(([code, iso]) => [
|
||||
code,
|
||||
\`https://flagcdn.com/\${iso}.svg\`,
|
||||
]),
|
||||
);
|
||||
`;
|
||||
|
||||
const mapOut = path.join(seedDataDir, 'wc2026-zhibo-team-map.ts');
|
||||
@@ -150,3 +216,7 @@ if (unmatched.length) {
|
||||
console.warn('Unmatched teams:', unmatched);
|
||||
process.exit(1);
|
||||
}
|
||||
if (missingFlagCodes.size) {
|
||||
console.warn('Missing FlagCDN ISO mapping:', [...missingFlagCodes].sort());
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user