Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto substandard.blog
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122// The publication's standing in panoptiblog: its rank, words, posts, and the// signals on the account that writes it.//// The dataset is one static file the site publishes. It is off the render path// and advisory, so a fetch that fails hides the row. A publication outside the// published top N still gets its account's labels, when the account is there.
import { PANOPTIBLOG_PAGE, accountStanding, fetchPanoptiblog, publicationStanding, type PanoptiblogData,} from '../../lib/panoptiblog'import { $ } from '../dom'import type { Card, CardHost } from './card'
const LABELS: Record<string, string> = { 'multiple-blogs': 'multiple blogs', 'blogged-recently': 'blogged recently', 'stopped-blogging': 'stopped blogging', 'new-blogger': 'new blogger', prolific: 'prolific', 'no-posts': 'no posts', 'top-one-percent-publication': 'top 1% publication', 'top-five-percent-publication': 'top 5% publication', 'top-one-percent-publisher': 'top 1% publisher', 'top-five-percent-publisher': 'top 5% publisher', 'top-one-percent-real-blogger': 'top 1% real blogger', 'top-five-percent-real-blogger': 'top 5% real blogger', 'early-adopter': 'early adopter',}
/** Vanity badges first; a 400px row has room for three. */const LABEL_PRIORITY = [ 'top-one-percent-publication', 'top-one-percent-publisher', 'top-one-percent-real-blogger', 'top-five-percent-publication', 'top-five-percent-publisher', 'top-five-percent-real-blogger', 'early-adopter',]
const compact = new Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 1,})
function readingTime(minutes: number | undefined): string | undefined { if (!Number.isFinite(minutes) || (minutes ?? 0) <= 0) return undefined const value = minutes as number if (value < 60) return `${Math.round(value)} min` const hours = Math.floor(value / 60) const remainder = Math.round(value % 60) return remainder > 0 ? `${hours}h ${remainder}m` : `${hours}h`}
/** The last answer, shared by every publication the popup shows in one open. */let data: PanoptiblogData | null | undefined/** Whether this popup open has already asked. */let loaded = false
function labelPill(value: string): HTMLElement { const span = document.createElement('span') span.className = 'panoptiblog-label' span.textContent = LABELS[value] ?? value return span}
export const panoptiblogCard: Card = { id: 'panoptiblog',
async load(host, refresh) { if (!host.state()?.pub) return if (!refresh && loaded) return loaded = true data = await fetchPanoptiblog(refresh) host.rerender() },
render(host) { const pub = host.state()?.pub const row = $<HTMLAnchorElement>('panoptiblog') const standing = pub ? publicationStanding(data ?? null, pub.uri) : undefined const account = pub ? accountStanding(data ?? null, pub.did) : undefined if (!pub || (!standing && !account)) { row.hidden = true return } row.hidden = false row.href = PANOPTIBLOG_PAGE
const rank = $('panoptiblog-rank') if (standing?.rank) rank.textContent = `#${standing.rank} publication` else if (account?.rank) rank.textContent = `#${account.rank} account` else rank.textContent = 'unranked'
const meta = $('panoptiblog-meta') const read = readingTime(standing?.readingMinutes ?? account?.readingMinutes) meta.textContent = standing ? `${read ? `${read} read · ` : `${compact.format(standing.wordCount)} words · `}${compact.format(standing.docCount)} posts` : account ? `${read ? `${read} read · ` : `${compact.format(account.wordCount)} words · `}${account.publicationCount} blogs` : ''
const labels = [...(account?.labels ?? [])].sort((a, b) => { const left = LABEL_PRIORITY.indexOf(a) const right = LABEL_PRIORITY.indexOf(b) return (left === -1 ? 99 : left) - (right === -1 ? 99 : right) }) $('panoptiblog-labels').replaceChildren(...labels.slice(0, 3).map(labelPill)) },
reset() { // Nothing here belongs to the signed-in account, but a fresh popup is a // fresh question and the dataset is cheap to read from cache. data = undefined loaded = false },}