File size: 1,729 Bytes
9d2d895 | 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 | import {
describePropagandaBadge,
getSourcePropagandaRisk,
getSourceTier,
getSourceTierBadgeTitle,
getSourceType,
} from '@/config/feeds';
import { escapeHtml } from '@/utils/sanitize';
export interface PrimarySourceProvenanceHtml {
riskBadge: string;
tierBadge: string;
}
/**
* Render the exact provenance badges used beside a cluster's primary source.
* Kept as a pure helper so fail-closed output can be regression-tested without
* constructing the full virtualized NewsPanel component.
*/
export function renderPrimarySourceProvenance(sourceName: string): PrimarySourceProvenanceHtml {
const sourceType = getSourceType(sourceName);
const riskDescription = describePropagandaBadge(getSourcePropagandaRisk(sourceName), sourceType);
const riskBadge = riskDescription
? `<span class="propaganda-badge ${riskDescription.risk}" title="${escapeHtml(riskDescription.title)}">${riskDescription.label}</span>`
: '';
const tier = getSourceTier(sourceName);
const tierLabel = tier === 1 && sourceType === 'wire' ? ' Wire' : '';
const tierBadge = tier <= 2
? `<span class="tier-badge tier-${tier}" title="${escapeHtml(getSourceTierBadgeTitle(sourceType))}">${tier === 1 ? '★' : '●'}${tierLabel}</span>`
: '';
return { riskBadge, tierBadge };
}
/** Render the compact risk marker shown for corroborating sources. */
export function renderCorroboratingSourceRisk(sourceName: string): string {
const description = describePropagandaBadge(
getSourcePropagandaRisk(sourceName),
getSourceType(sourceName),
);
return description
? `<span class="propaganda-badge ${description.risk}" title="${escapeHtml(description.title)}">${description.shortLabel}</span>`
: '';
}
|