All files / src/generators seo-copy.ts

100% Statements 19/19
80.76% Branches 21/26
100% Functions 4/4
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450                                                                                8x                                                                         8x                                                                 8x                                                                                   8x                                                                                                                                                                                     8x                                                                                                                                                                 8x                                                                                                                                                                   151x 148x 148x                                   59x 41x                 89x 51x                 67x 59x    
// SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable sonarjs/no-duplicate-string -- translations naturally repeat
   common labels (e.g., "Hjem", "Nyheter") across closely related languages
   like Norwegian / Danish; deduplicating across locales would couple them. */
 
/**
 * @module Generators/SeoCopy
 * @description Localized SEO copy (keywords, breadcrumb labels, FAQ pairs,
 * og:image alt) shared by the news-index, sitemap and political-intelligence
 * landing pages. Each page type has its own record keyed by ISO 639-1 code;
 * unknown languages fall back to English.
 *
 * The visible FAQ text rendered into the page MUST be byte-equivalent to the
 * matching `acceptedAnswer.text` emitted in the FAQPage JSON-LD — this module
 * is the single source of truth for both surfaces.
 */
 
export interface FaqPair {
  readonly q: string;
  readonly a: string;
}
 
export interface PageSeoCopy {
  readonly keywords: string;
  readonly ogImageAlt: string;
  readonly breadcrumbHome: string;
  readonly breadcrumbCurrent: string;
  readonly breadcrumbAriaLabel: string;
  readonly faqHeading: string;
  readonly faqLanguage: string;
  readonly faqs: ReadonlyArray<FaqPair>;
}
 
// =============================================================================
// English — authoritative copy. All other locales fall back to these strings
// when a translation is not yet provided. Keep questions/answers concise so
// translation effort stays bounded and rich-result eligibility stays high.
// =============================================================================
 
const NEWS_INDEX_EN: PageSeoCopy = {
  keywords:
    'European Parliament, EU news, MEPs, plenary sessions, AI journalism, parliamentary intelligence, EU policy, Hack23',
  ogImageAlt: 'EU Parliament Monitor — AI-Disrupted Parliamentary Intelligence',
  breadcrumbHome: 'Home',
  breadcrumbCurrent: 'News',
  breadcrumbAriaLabel: 'Breadcrumb',
  faqHeading: 'Frequently asked questions',
  faqLanguage: 'en',
  faqs: [
    {
      q: 'What is EU Parliament Monitor?',
      a: 'EU Parliament Monitor is an independent transparency platform that publishes daily AI-generated articles tracking the work of the European Parliament. It is built and operated by Hack23 AB and is not affiliated with the European Parliament.',
    },
    {
      q: 'Is this an official European Parliament site?',
      a: 'No. EU Parliament Monitor is independent journalism produced by Hack23 AB. Source data is fetched from the European Parliament Open Data Portal, but editorial decisions, AI prompts and analysis are wholly the responsibility of Hack23 AB.',
    },
    {
      q: 'How are the articles generated?',
      a: 'Each article is generated by a deterministic pipeline of AI agents that read EP Open Data, run analysis tools, and write a draft. Drafts are validated for factuality and accessibility before being published as static HTML on GitHub Pages.',
    },
    {
      q: 'In how many languages is the site available?',
      a: 'Articles and the site shell are available in 14 languages: English, Swedish, Danish, Norwegian, Finnish, German, French, Spanish, Dutch, Arabic, Hebrew, Japanese, Korean and Chinese.',
    },
    {
      q: 'Where does the underlying data come from?',
      a: 'All parliamentary data is fetched from the European Parliament Open Data Portal (data.europarl.europa.eu) via the open-source European Parliament MCP server published at github.com/Hack23/european-parliament-mcp.',
    },
    {
      q: 'How can I subscribe to updates?',
      a: 'A standards-compliant RSS 2.0 feed is published at rss.xml. The site is also fully static, so it can be archived, mirrored, or read offline at any time.',
    },
  ],
};
 
const SITEMAP_EN: PageSeoCopy = {
  keywords:
    'sitemap, EU Parliament Monitor, archive, news index, parliamentary articles, transparency, RSS, Hack23',
  ogImageAlt: 'EU Parliament Monitor — Site map of every published article',
  breadcrumbHome: 'Home',
  breadcrumbCurrent: 'Sitemap',
  breadcrumbAriaLabel: 'Breadcrumb',
  faqHeading: 'About this sitemap',
  faqLanguage: 'en',
  faqs: [
    {
      q: 'What is on this page?',
      a: 'This page lists every news article published by EU Parliament Monitor, grouped by category and topic, so that readers and search engines can find any piece of coverage in a single click.',
    },
    {
      q: 'How often is the sitemap regenerated?',
      a: 'The sitemap is rebuilt automatically every time a new article is published, which currently happens at least once per parliamentary working day.',
    },
    {
      q: 'Is there a machine-readable version?',
      a: 'Yes. A standards-compliant XML sitemap is published at sitemap.xml and a Schema.org CollectionPage with an embedded ItemList is included in this page for structured-data consumers.',
    },
    {
      q: 'Why are some articles missing in my language?',
      a: 'Every article is generated in 14 languages, but for very recent items the pipeline publishes English first and other languages within a few minutes. Refresh the page if a translation appears to be missing.',
    },
    {
      q: 'Can I link to a specific category?',
      a: 'Yes. Each category heading on this page has a stable id you can deep-link to. The sitemap.xml file additionally exposes every article URL with a lastmod timestamp for crawlers.',
    },
  ],
};
 
const PI_EN: PageSeoCopy = {
  keywords:
    'political intelligence, EU Parliament, OSINT, MEP analysis, coalition dynamics, voting patterns, EP open data, Hack23',
  ogImageAlt: 'EU Parliament Monitor — Political intelligence run archive',
  breadcrumbHome: 'Home',
  breadcrumbCurrent: 'Political Intelligence',
  breadcrumbAriaLabel: 'Breadcrumb',
  faqHeading: 'About political intelligence runs',
  faqLanguage: 'en',
  faqs: [
    {
      q: 'What is a political intelligence run?',
      a: 'A political intelligence run is a daily analytical workflow that pulls fresh data from the European Parliament Open Data Portal, executes a fixed set of MCP analysis tools, and produces both a markdown brief and a public news article.',
    },
    {
      q: 'Are the analyses peer-reviewed?',
      a: 'No. Analyses are produced by AI agents using deterministic prompts and published openly so that anyone can reproduce, fork, or contest the methodology. Source code, prompts and raw data are linked from every run card.',
    },
    {
      q: 'How frequently are runs executed?',
      a: 'At least once per European Parliament working day. Specialised runs (coalition fracture, MEP influence, legislative bottlenecks) execute on their own GitHub Actions schedules.',
    },
    {
      q: 'Where can I see the source code?',
      a: 'All workflow definitions, agent prompts, and analysis tooling are published at github.com/Hack23/euparliamentmonitor under the Apache 2.0 license. The MCP server itself is at github.com/Hack23/european-parliament-mcp.',
    },
    {
      q: 'Who writes the analysis?',
      a: 'The analysis is written by AI agents orchestrated by Hack23 AB. Editorial guardrails, prompts and tool whitelists are version-controlled and reviewed by humans before each release.',
    },
  ],
};
 
// =============================================================================
// Localised overlays. Only the breadcrumb labels, FAQ headings and keyword
// strings are translated for now — the FAQ Q/A bodies remain in English to
// keep the visible-text/structured-data byte-equivalence guarantee trivial to
// audit. Full FAQ translation is tracked in a follow-up issue.
// =============================================================================
 
type Overlay = Partial<PageSeoCopy>;
 
const NEWS_INDEX_OVERLAYS: Record<string, Overlay> = {
  sv: {
    keywords:
      'Europaparlamentet, EU-nyheter, ledamöter, plenarsessioner, AI-journalistik, parlamentarisk underrättelse, EU-politik, Hack23',
    breadcrumbHome: 'Hem',
    breadcrumbCurrent: 'Nyheter',
    breadcrumbAriaLabel: 'Brödsmulor',
    faqHeading: 'Vanliga frågor',
  },
  da: {
    breadcrumbHome: 'Hjem',
    breadcrumbCurrent: 'Nyheder',
    breadcrumbAriaLabel: 'Brødkrumme',
    faqHeading: 'Ofte stillede spørgsmål',
  },
  no: {
    breadcrumbHome: 'Hjem',
    breadcrumbCurrent: 'Nyheter',
    breadcrumbAriaLabel: 'Brødsmulesti',
    faqHeading: 'Ofte stilte spørsmål',
  },
  fi: {
    breadcrumbHome: 'Etusivu',
    breadcrumbCurrent: 'Uutiset',
    breadcrumbAriaLabel: 'Murupolku',
    faqHeading: 'Usein kysytyt kysymykset',
  },
  de: {
    keywords:
      'Europäisches Parlament, EU-Nachrichten, Abgeordnete, Plenarsitzungen, KI-Journalismus, parlamentarische Aufklärung, EU-Politik, Hack23',
    breadcrumbHome: 'Startseite',
    breadcrumbCurrent: 'Nachrichten',
    breadcrumbAriaLabel: 'Brotkrümelnavigation',
    faqHeading: 'Häufig gestellte Fragen',
  },
  fr: {
    keywords:
      'Parlement européen, actualités UE, députés européens, sessions plénières, journalisme IA, renseignement parlementaire, politique UE, Hack23',
    breadcrumbHome: 'Accueil',
    breadcrumbCurrent: 'Actualités',
    breadcrumbAriaLabel: "Fil d'Ariane",
    faqHeading: 'Questions fréquentes',
  },
  es: {
    keywords:
      'Parlamento Europeo, noticias UE, eurodiputados, sesiones plenarias, periodismo con IA, inteligencia parlamentaria, política UE, Hack23',
    breadcrumbHome: 'Inicio',
    breadcrumbCurrent: 'Noticias',
    breadcrumbAriaLabel: 'Ruta de navegación',
    faqHeading: 'Preguntas frecuentes',
  },
  nl: {
    keywords:
      'Europees Parlement, EU-nieuws, Europarlementariërs, plenaire vergaderingen, AI-journalistiek, parlementaire inlichtingen, EU-beleid, Hack23',
    breadcrumbHome: 'Startpagina',
    breadcrumbCurrent: 'Nieuws',
    breadcrumbAriaLabel: 'Kruimelpad',
    faqHeading: 'Veelgestelde vragen',
  },
  ar: {
    breadcrumbHome: 'الرئيسية',
    breadcrumbCurrent: 'الأخبار',
    breadcrumbAriaLabel: 'مسار التنقل',
    faqHeading: 'الأسئلة الشائعة',
  },
  he: {
    breadcrumbHome: 'דף הבית',
    breadcrumbCurrent: 'חדשות',
    breadcrumbAriaLabel: 'נתיב ניווט',
    faqHeading: 'שאלות נפוצות',
  },
  ja: {
    breadcrumbHome: 'ホーム',
    breadcrumbCurrent: 'ニュース',
    breadcrumbAriaLabel: 'パンくずリスト',
    faqHeading: 'よくある質問',
  },
  ko: {
    breadcrumbHome: '홈',
    breadcrumbCurrent: '뉴스',
    breadcrumbAriaLabel: '경로',
    faqHeading: '자주 묻는 질문',
  },
  zh: {
    breadcrumbHome: '首页',
    breadcrumbCurrent: '新闻',
    breadcrumbAriaLabel: '面包屑导航',
    faqHeading: '常见问题',
  },
};
 
const SITEMAP_OVERLAYS: Record<string, Overlay> = {
  sv: {
    breadcrumbHome: 'Hem',
    breadcrumbCurrent: 'Webbplatskarta',
    breadcrumbAriaLabel: 'Brödsmulor',
    faqHeading: 'Om webbplatskartan',
  },
  da: {
    breadcrumbHome: 'Hjem',
    breadcrumbCurrent: 'Sitemap',
    breadcrumbAriaLabel: 'Brødkrumme',
    faqHeading: 'Om dette sitemap',
  },
  no: {
    breadcrumbHome: 'Hjem',
    breadcrumbCurrent: 'Nettstedskart',
    breadcrumbAriaLabel: 'Brødsmulesti',
    faqHeading: 'Om nettstedskartet',
  },
  fi: {
    breadcrumbHome: 'Etusivu',
    breadcrumbCurrent: 'Sivukartta',
    breadcrumbAriaLabel: 'Murupolku',
    faqHeading: 'Tietoa sivukartasta',
  },
  de: {
    breadcrumbHome: 'Startseite',
    breadcrumbCurrent: 'Seitenübersicht',
    breadcrumbAriaLabel: 'Brotkrümelnavigation',
    faqHeading: 'Über diese Seitenübersicht',
  },
  fr: {
    breadcrumbHome: 'Accueil',
    breadcrumbCurrent: 'Plan du site',
    breadcrumbAriaLabel: "Fil d'Ariane",
    faqHeading: 'À propos du plan du site',
  },
  es: {
    breadcrumbHome: 'Inicio',
    breadcrumbCurrent: 'Mapa del sitio',
    breadcrumbAriaLabel: 'Ruta de navegación',
    faqHeading: 'Acerca de este mapa del sitio',
  },
  nl: {
    breadcrumbHome: 'Startpagina',
    breadcrumbCurrent: 'Sitemap',
    breadcrumbAriaLabel: 'Kruimelpad',
    faqHeading: 'Over deze sitemap',
  },
  ar: {
    breadcrumbHome: 'الرئيسية',
    breadcrumbCurrent: 'خريطة الموقع',
    breadcrumbAriaLabel: 'مسار التنقل',
    faqHeading: 'حول خريطة الموقع',
  },
  he: {
    breadcrumbHome: 'דף הבית',
    breadcrumbCurrent: 'מפת אתר',
    breadcrumbAriaLabel: 'נתיב ניווט',
    faqHeading: 'אודות מפת האתר',
  },
  ja: {
    breadcrumbHome: 'ホーム',
    breadcrumbCurrent: 'サイトマップ',
    breadcrumbAriaLabel: 'パンくずリスト',
    faqHeading: 'サイトマップについて',
  },
  ko: {
    breadcrumbHome: '홈',
    breadcrumbCurrent: '사이트맵',
    breadcrumbAriaLabel: '경로',
    faqHeading: '사이트맵 안내',
  },
  zh: {
    breadcrumbHome: '首页',
    breadcrumbCurrent: '网站地图',
    breadcrumbAriaLabel: '面包屑导航',
    faqHeading: '关于本网站地图',
  },
};
 
const PI_OVERLAYS: Record<string, Overlay> = {
  sv: {
    breadcrumbHome: 'Hem',
    breadcrumbCurrent: 'Politisk underrättelse',
    breadcrumbAriaLabel: 'Brödsmulor',
    faqHeading: 'Om körningarna',
  },
  da: {
    breadcrumbHome: 'Hjem',
    breadcrumbCurrent: 'Politisk efterretning',
    breadcrumbAriaLabel: 'Brødkrumme',
    faqHeading: 'Om kørslerne',
  },
  no: {
    breadcrumbHome: 'Hjem',
    breadcrumbCurrent: 'Politisk etterretning',
    breadcrumbAriaLabel: 'Brødsmulesti',
    faqHeading: 'Om kjøringene',
  },
  fi: {
    breadcrumbHome: 'Etusivu',
    breadcrumbCurrent: 'Poliittinen tiedustelu',
    breadcrumbAriaLabel: 'Murupolku',
    faqHeading: 'Tietoa ajoista',
  },
  de: {
    breadcrumbHome: 'Startseite',
    breadcrumbCurrent: 'Politische Aufklärung',
    breadcrumbAriaLabel: 'Brotkrümelnavigation',
    faqHeading: 'Über die Analyseläufe',
  },
  fr: {
    breadcrumbHome: 'Accueil',
    breadcrumbCurrent: 'Renseignement politique',
    breadcrumbAriaLabel: "Fil d'Ariane",
    faqHeading: "À propos des exécutions d'analyse",
  },
  es: {
    breadcrumbHome: 'Inicio',
    breadcrumbCurrent: 'Inteligencia política',
    breadcrumbAriaLabel: 'Ruta de navegación',
    faqHeading: 'Acerca de las ejecuciones',
  },
  nl: {
    breadcrumbHome: 'Startpagina',
    breadcrumbCurrent: 'Politieke inlichtingen',
    breadcrumbAriaLabel: 'Kruimelpad',
    faqHeading: 'Over de analyseruns',
  },
  ar: {
    breadcrumbHome: 'الرئيسية',
    breadcrumbCurrent: 'الاستخبارات السياسية',
    breadcrumbAriaLabel: 'مسار التنقل',
    faqHeading: 'حول عمليات التحليل',
  },
  he: {
    breadcrumbHome: 'דף הבית',
    breadcrumbCurrent: 'מודיעין פוליטי',
    breadcrumbAriaLabel: 'נתיב ניווט',
    faqHeading: 'אודות הרצות הניתוח',
  },
  ja: {
    breadcrumbHome: 'ホーム',
    breadcrumbCurrent: '政治インテリジェンス',
    breadcrumbAriaLabel: 'パンくずリスト',
    faqHeading: '解析実行について',
  },
  ko: {
    breadcrumbHome: '홈',
    breadcrumbCurrent: '정치 인텔리전스',
    breadcrumbAriaLabel: '경로',
    faqHeading: '분석 실행 안내',
  },
  zh: {
    breadcrumbHome: '首页',
    breadcrumbCurrent: '政治情报',
    breadcrumbAriaLabel: '面包屑导航',
    faqHeading: '关于分析运行',
  },
};
 
function applyOverlay(base: PageSeoCopy, overlay: Overlay | undefined, lang: string): PageSeoCopy {
  if (!overlay) return base;
  const hasLocalizedFaqs = overlay.faqs !== undefined;
  return {
    keywords: overlay.keywords ?? base.keywords,
    ogImageAlt: overlay.ogImageAlt ?? base.ogImageAlt,
    breadcrumbHome: overlay.breadcrumbHome ?? base.breadcrumbHome,
    breadcrumbCurrent: overlay.breadcrumbCurrent ?? base.breadcrumbCurrent,
    breadcrumbAriaLabel: overlay.breadcrumbAriaLabel ?? base.breadcrumbAriaLabel,
    faqHeading: overlay.faqHeading ?? base.faqHeading,
    faqLanguage: overlay.faqLanguage ?? (hasLocalizedFaqs ? lang : base.faqLanguage),
    faqs: overlay.faqs ?? base.faqs,
  };
}
 
/**
 * Returns SEO copy for the news index page. Falls back to English.
 * @param lang - ISO 639-1 language code (e.g., `"en"`, `"de"`).
 * @returns A fully-populated {@link PageSeoCopy} record.
 */
export function getNewsIndexSeo(lang: string): PageSeoCopy {
  if (lang === 'en') return NEWS_INDEX_EN;
  return applyOverlay(NEWS_INDEX_EN, NEWS_INDEX_OVERLAYS[lang], lang);
}
 
/**
 * Returns SEO copy for the sitemap page. Falls back to English.
 * @param lang - ISO 639-1 language code (e.g., `"en"`, `"de"`).
 * @returns A fully-populated {@link PageSeoCopy} record.
 */
export function getSitemapSeo(lang: string): PageSeoCopy {
  if (lang === 'en') return SITEMAP_EN;
  return applyOverlay(SITEMAP_EN, SITEMAP_OVERLAYS[lang], lang);
}
 
/**
 * Returns SEO copy for the political-intelligence page. Falls back to English.
 * @param lang - ISO 639-1 language code (e.g., `"en"`, `"de"`).
 * @returns A fully-populated {@link PageSeoCopy} record.
 */
export function getPoliticalIntelligenceSeo(lang: string): PageSeoCopy {
  if (lang === 'en') return PI_EN;
  return applyOverlay(PI_EN, PI_OVERLAYS[lang], lang);
}