Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto substandard.blog
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293// The publication's standing in panoptiblog, the rankings the site publishes.//// The dataset is one static file on substandard.blog. It is somebody else's// read — nothing here writes — and the popup can live without it, so every// failure costs the row rather than the popup.
import { cached } from './cache'import { type RequestOptions, requestJson } from './http'
export const PANOPTIBLOG_URL = 'https://substandard.blog/panoptiblog/data.json'export const PANOPTIBLOG_PAGE = 'https://substandard.blog/panoptiblog'
/** Third-party and optional: fail fast rather than hold the card open. */const OPTIONS: RequestOptions = { timeoutMs: 8_000, retries: 1 }
export interface PanoptiblogPublication { uri: string did: string rank?: number name: string url?: string description?: string wordCount: number docCount: number readingMinutes?: number readingHours?: number subscribers: number recommends: number topics?: string[] score: number}
export interface PanoptiblogAccount { did: string handle?: string rank?: number wordsRank?: number publicationCount: number wordCount: number readingMinutes?: number readingHours?: number labels: string[] score: number}
export interface PanoptiblogData { generatedAt: string totals: Record<string, number> publications: PanoptiblogPublication[] accounts: PanoptiblogAccount[] method?: { weights?: Record<string, number> }}
/** * The dataset, or null when it cannot be read. Cached in `world` for the same * day as every other stranger's data: the ranking changes when the scheduled * job runs, not between two popup opens. */export async function fetchPanoptiblog(refresh = false): Promise<PanoptiblogData | null> { try { return await cached( { scope: 'world', subject: 'panoptiblog', name: 'data' }, async () => { const data = await requestJson<PanoptiblogData>(PANOPTIBLOG_URL, OPTIONS) if (!Array.isArray(data?.publications) || !Array.isArray(data?.accounts)) { throw new Error('panoptiblog dataset has the wrong shape') } return data }, { refresh }, ) } catch (err) { console.debug('[substandard] panoptiblog dataset unavailable', err) return null }}
/** The publication's own row, when it ranked. */export function publicationStanding( data: PanoptiblogData | null, uri: string,): PanoptiblogPublication | undefined { return data?.publications.find((publication) => publication.uri === uri)}
/** The account's row, which carries the labels even when its publication did not rank. */export function accountStanding( data: PanoptiblogData | null, did: string,): PanoptiblogAccount | undefined { return data?.accounts.find((account) => account.did === did)}