feat(bloomberg): enrich article content for summaries (#36)

This commit is contained in:
2026-11-24 13:44:52 +01:00
parent 686f66a437
commit a53aec7947
22 changed files with 1148 additions and 127 deletions

View File

@ -16,7 +16,7 @@ function reliableISO(value) {
return Number.isFinite(timestamp) ? new Date(timestamp).toISOString() : null
}
function extractPublicationDate(html) {
function extractPublicationDate(html, expectedURL) {
const $ = cheerio.load(html)
for (const selector of ['meta[name="iso-8601-publish-date"]', 'time[datetime]']) {
for (const element of $(selector).toArray()) {
@ -30,7 +30,19 @@ function extractPublicationDate(html) {
if (!Array.isArray(node)) {
const types = Array.isArray(node['@type']) ? node['@type'] : [node['@type']]
if (types.some(type => ['Article', 'NewsArticle', 'ReportageNewsArticle'].includes(type))) {
const date = reliableISO(node.datePublished)
let associated = !expectedURL
if (expectedURL) {
const identity = node.url || node.mainEntityOfPage || node['@id']
const value = typeof identity === 'string' ? identity : identity?.['@id']
try {
if (typeof value === 'string') {
const actual = new URL(value, expectedURL); actual.search = ''; actual.hash = ''
const expected = new URL(expectedURL); expected.search = ''; expected.hash = ''
associated = isArticleURL(actual.href) && actual.href === expected.href
}
} catch { /* No trustworthy article identity. */ }
}
const date = associated ? reliableISO(node.datePublished) : null
if (date) return date
}
}
@ -75,7 +87,7 @@ function withDatesFromLoadedHtml(articles, html, loadedURL, parsed) {
const wanted = new Set(articles.map(article => key(article.url)).filter(Boolean))
const pageKey = key(loadedURL)
if (pageKey && wanted.has(pageKey)) {
const date = extractPublicationDate(html)
const date = extractPublicationDate(html, pageKey)
if (date) dates.set(pageKey, date)
}
for (const anchor of $('a[data-component="story-link"]').toArray()) {