feat: add media bias fact check support

This commit is contained in:
Xylight committed 2024-07-16 12:53:05 -07:00
1 parent b97ebffc08
commit d2748faacf
9 files changed
+249 -14

No files matched your search

+134
View File
@@ -0,0 +1,134 @@
<script lang="ts" context="module">
// Courtesy of https://github.com/asimons04
export interface MBFCReport {
bias: string
credibility: string
domain: string
facebook?: string
twitter?: string
name: string
popularity?: number
questionable: string[]
reporting: string
url: string
// biases?: MBFCBiases
score?: number
}
export const findSource = async (
target: string,
dataset: any,
): Promise<MBFCReport | undefined> => {
if (!target) return undefined
let left = 0
let right = dataset.length
while (left <= right) {
const middle = Math.floor((left + right) / 2)
const foundDomain = dataset[middle].domain
if (foundDomain == target) return dataset[middle]
else if (foundDomain < target) left = middle + 1
else if (foundDomain > target) right = middle - 1
}
return undefined
}
</script>
<script lang="ts">
import { t } from '$lib/translations'
import { Badge, Modal, Spinner } from 'mono-svelte'
import Placeholder from '../ui/Placeholder.svelte'
import { Icon, QuestionMarkCircle, Link as Chain } from 'svelte-hero-icons'
import Link from '../input/Link.svelte'
import Expandable from '../ui/Expandable.svelte'
import Visualization from './Visualization.svelte'
export let open: boolean = false
export let domain: string = ''
let ratings = ['left', 'left-center', 'center', 'right-center', 'right']
let altRatings = [
'conspiracy-pseudoscience',
'pro-science',
'satire',
'fake-news',
]
let reporting = [
'very-low',
'low',
'mixed',
'mostly-factual',
'high',
'Very-high',
]
</script>
<Modal title={$t('post.actions.more.mediaBias')} {...$$restProps} bind:open>
{#await import('./data.json')}
<div class="w-full h-64 flex justify-center items-center">
<Spinner width={32} />
<span>{$t('post.actions.mediaBias.downloading')}</span>
</div>
{:then json}
{#await findSource(domain, json.sources)}
<span>{$t('post.actions.mediaBias.loading')}</span>
{:then data}
{#if data}
<h2 class="font-semibold text-xl">{data.name}</h2>
<Visualization
data={ratings.includes(data.bias) ? ratings : altRatings}
alt={!ratings.includes(data.bias)}
selected={data.bias}
name={json.biases.find((b) => b.bias == data.bias)?.name ?? data.bias}
/>
<Expandable open>
<span slot="title">{$t('post.actions.mediaBias.description')}</span>
<p class="text-sm">
{json.biases.find((b) => b.bias == data.bias)?.description}
</p>
</Expandable>
{#if data.questionable?.length > 0}
<div class="flex items-center flex-wrap gap-2">
{#each data.questionable as questionable}
<Badge color="red-subtle">
<span>
{json.questionable.find((q) => q.questionable == questionable)
?.name}
</span>
</Badge>
{/each}
</div>
{/if}
<h3 class="font-semibold text-lg">
{$t('post.actions.mediaBias.reporting')}
</h3>
<Visualization
data={reporting}
alt
width={24}
selected={data.reporting}
name={json.reporting.find((b) => b.reporting == data.reporting)
?.name ?? data.reporting}
/>
{:else}
<Placeholder
icon={QuestionMarkCircle}
title={$t('post.actions.mediaBias.noData.title')}
description={$t('post.actions.mediaBias.noData.description')}
/>
{/if}
<Link
href="https://mediabiasfactcheck.com/"
class="text-sm text-slate-700 dark:text-zinc-300"
>
<Icon src={Chain} micro size="14" />
mediabiasfactcheck.com
</Link>
{/await}
{/await}
</Modal>
@@ -0,0 +1,55 @@
<script lang="ts">
type T = $$Generic
export let data: T[]
export let selected: T
export let name: string
export let alt: boolean = false
export let width: number = 48
</script>
<div class="flex items-start gap-4 mx-auto mb-6">
{#each data as rating, index}
<div
class="flex flex-col gap-2 items-center relative"
style=" width: {width}px; height: {width}px;"
>
<div
class="w-12 h-12 {alt
? 'bg-red-500'
: 'bg-blue-500 border-blue-700'} opacity-50 transition-all cursor-pointer duration-100 {rating ==
selected
? 'current-bias'
: 'hover:opacity-100 rounded-full'}"
style="filter: hue-rotate({index *
30}deg); width: {width}px; height: {width}px;"
></div>
{#if rating == selected}
<span
class="capitalize font-medium whitespace-nowrap max-w-max absolute -bottom-8 left-1/2 -translate-x-1/2"
>
{name}
</span>
{/if}
</div>
{/each}
</div>
<style>
@keyframes spin {
0% {
transform: rotate(-180deg);
opacity: 0.5;
border-radius: 64px;
}
100% {
transform: rotate(45deg);
opacity: 1;
border-radius: 12px;
}
}
.current-bias {
animation: spin 1s forwards cubic-bezier(0.075, 0.82, 0.165, 1);
}
</style>
+1
View File
@@ -0,0 +1 @@
{"aliases":{"politi.co":"politico.com","bbc.co.uk":"bbc.com","cbs.com":"cbsnews.com","moveon.org":"front.moveon.org"},"biases":[{"bias":"left","code":"L","description":"These media sources are moderately to strongly biased toward liberal causes through story selection and/or political affiliation.  They may utilize strong loaded words (wording that attempts to influence an audience by using appeal to emotion or stereotypes), publish misleading reports and omit reporting of information that may damage liberal causes. Some sources in this category may be untrustworthy.","name":"Left Bias","pretty":"Left","url":"https://mediabiasfactcheck.com/left/"},{"bias":"left-center","code":"LC","description":"These media sources have a slight to moderate liberal bias.  They often publish factual information that utilizes loaded words (wording that attempts to influence an audience by using appeal to emotion or stereotypes) to favor liberal causes.  These sources are generally trustworthy for information, but may require further investigation.  ","name":"Left-Center Bias","pretty":"Left-Center","url":"https://mediabiasfactcheck.com/leftcenter/"},{"bias":"center","code":"C","description":"These sources have minimal bias and use very few loaded words (wording that attempts to influence an audience by using appeal to emotion or stereotypes).  The reporting is factual and usually sourced.  These are the most credible media sources.  ","name":"Least Biased","pretty":"Center","url":"https://mediabiasfactcheck.com/center/"},{"bias":"right-center","code":"RC","description":"These media sources are slightly to moderately conservative in bias. They often publish factual information that utilizes loaded words (wording that attempts to influence an audience by using appeal to emotion or stereotypes) to favor conservative causes. These sources are generally trustworthy for information, but may require further investigation.  ","name":"Right-Center Bias","pretty":"Right-Center","url":"https://mediabiasfactcheck.com/right-center/"},{"bias":"right","code":"R","description":"These media sources are moderately to strongly biased toward conservative causes through story selection and/or political affiliation. They may utilize strong loaded words (wording that attempts to influence an audience by using appeal to emotion or stereotypes), publish misleading reports and omit reporting of information that may damage conservative causes. Some sources in this category may be untrustworthy.","name":"Right Bias","pretty":"Right","url":"https://mediabiasfactcheck.com/right/"},{"bias":"pro-science","code":"PS","description":"These sources consist of legitimate science or are evidence based through the use of credible scientific sourcing.  Legitimate science follows the scientific method, is unbiased and does not use emotional words.  These sources also respect the consensus of experts in the given scientific field and strive to publish peer reviewed science. Some sources in this category may have a slight political bias, but adhere to scientific principles.","name":"Pro-Science","pretty":"Pro-Science","url":"https://mediabiasfactcheck.com/pro-science/"},{"bias":"conspiracy-pseudoscience","code":"CP","description":"Sources in the Conspiracy-Pseudoscience category may publish unverifiable information that is not always supported by evidence. These sources may be untrustworthy for credible/verifiable information, therefore fact checking and further investigation is recommended on a per article basis when obtaining information from these sources. ","name":"Conspiracy-Pseudoscience","pretty":"Conspiracy-Pseudoscience","url":"https://mediabiasfactcheck.com/conspiracy/"},{"bias":"satire","code":"S","description":"These sources exclusively use humor, irony, exaggeration, or ridicule to expose and criticize people’s stupidity or vices, particularly in the context of contemporary politics and other topical issues. Primarily these sources are clear that they are satire and do not attempt to deceive.","name":"Satire","pretty":"Satire","url":"https://mediabiasfactcheck.com/satire/"},{"bias":"fake-news","code":"FN","description":"A questionable source exhibits one or more of the following: extreme bias, overt propaganda, poor or no sourcing to credible information and/or is fake news. Fake News is the deliberate attempt to publish hoaxes and/or disinformation for the purpose of profit or influence (Learn More). Sources listed in the Questionable Category may be very untrustworthy and should be fact checked on a per article basis. Please note sources on this list are not considered fake news unless specifically written in the notes section for that source.","name":"Questionable Sources","pretty":"Fake-News","url":"https://mediabiasfactcheck.com/fake-news/"}],"credibility":[{"code":"H","credibility":"high-credibility","name":"High Credibility","pretty":"High Credibility"},{"code":"M","credibility":"medium-credibility","name":"Medium CredibLine truncated