function getHeadlinesForSource(data, source, count = 1, with_dates = false) {
let filteredData = data
.orderby("rank", aq.desc("scraped_at_date"))
.filter(
aq.escape((o) => o.source === source && o.topic_prob > topic_threshold)
);
if (filteredData.size == 0) {
return [];
}
if (count === 1) {
return filteredData.slice(0, 1).objects()[0].headline_with_source;
}
if (with_dates) {
return filteredData
.derive({
headline_with_date: (o) => "(" + o.scraped_at_date + ") " + o.headline
})
.array("headline_with_date")
.slice(0, count);
}
return filteredData
.array("headline_with_source")
.slice(0, count)
.map((o) => get_headline_link(o, true));
}