// HOW A PAGE RECORD IS SHOWN (release 37 S4): the facts every surface that // renders a page record — a report site's moment page and citation card, the // editor's Wayback pages panel, umtool's evidence rail, the corpus viewer's // post modal — prints about its capture, in the same words everywhere: // // the kind ("Tumblr post", "Web page", …), the capture's date, // "Original (may be gone)" + "Wayback Machine copy, " // (lib/wayback.ts waybackCitationLinks), // the version list — "4 captures of this page; text changed on …" — from // the records of the same original URL, // "This capture holds no content." for a shell, and the extractor-fallback // note when a site extractor failed and the generic one read the page. // // Client-safe and pure: types only from ./types (whose urlHash is // node:crypto), so the whole-page test is the id's shape, not a hash. import type { Post } from "../posts"; import type { PagePostInfo } from "./types"; import { waybackCaptureDate, waybackCitationLinks, type WaybackLink } from "../wayback"; import { PAGE_ORIGINAL_GONE_LABEL } from "./liveness"; import { pageArchiveLink } from "../archives/mementos"; export const PAGE_KIND_LABELS: Record = { generic: "Web page", "tumblr-post": "Tumblr post", "tumblr-index": "Tumblr page", tweet: "Tweet", "x-profile": "X/Twitter profile", "forum-post": "Forum post", gdoc: "Google Doc", "yt-about": "YouTube channel page", "ng-user": "Newgrounds user page", "ng-art": "Newgrounds art", "ng-movie": "Newgrounds movie", }; export function pageKindLabel(kind: string): string { return PAGE_KIND_LABELS[kind] ?? `Web page (${kind})`; } export const PAGE_NO_CONTENT_LINE = "This capture holds no content."; // A whole-page record's id is pageRecordId(captureTs, originalUrl): // `-<12 hex>`. An item's id is the source's own (`tumblr-…`, `tweet-…`). const WHOLE_PAGE_ID = /^\d{4,14}-[0-9a-f]{12}$/; export function isWholePageId(id: string): boolean { return WHOLE_PAGE_ID.test(id); } export type PageVersionsView = { // Captures of the page held (this one included). count: number; // The capture dates on which the text differs from the capture before. changedOn: string[]; // Each capture, oldest first. captures: { id: string; date: string; waybackUrl: string; current: boolean }[]; }; export type PageCaptureView = { kind: string; kindLabel: string; captureTs: string; captureDate: string; originalUrl: string; waybackUrl: string; links: { original: WaybackLink; copy: WaybackLink }; // The original is known gone: the Wayback copy is the only copy. originalGone?: boolean; // Release 37 lane F: the archive source when it is not the Wayback Machine // ("archive.today"); `waybackUrl` is then that copy's URL. source?: string; title?: string; noContent?: boolean; // The extractor-fallback sentence. fallbackNote?: string; // An item seen in more than one capture: the first one's date. firstSeenDate?: string; versions?: PageVersionsView; }; // THE ONE PLACE a page record's two links are named: "Original (may be gone)" // and " copy, " (lib/wayback.ts waybackCitationLinks). Every // surface — compose's record view, this module's view, the MCP — goes through // it, so a record from another archive is one change here. // `originalGone`: the original is known gone (release 37 S5's check recorded // it `deleted`) — the original is then named as such (PAGE_ORIGINAL_GONE_LABEL). // Release 37 lane F: a record from another archive source (`page.source`, // "archive.today") names that source and links its copy (`page.archiveUrl`): // "archive.today copy, ". export function pageCopyLinks( page: Pick & Partial>, o: { originalGone?: boolean } = {}, ): { original: WaybackLink; copy: WaybackLink; } { const base = waybackCitationLinks(page); const other = page.source && page.source !== "wayback" ? pageArchiveLink(page) : null; const links = other ? { ...base, copy: { label: `${other.label} copy, ${waybackCaptureDate(page.captureTs)}`, url: other.url } } : base; return o.originalGone ? { ...links, original: { ...links.original, label: PAGE_ORIGINAL_GONE_LABEL } } : links; } export function pageFallbackNote(page: Pick): string | undefined { const f = page.extractorFallback; if (!f) return undefined; return `The ${f.from} reader could not read this capture (${f.error}); the text is the generic reader's.`; } const tsKey = (ts: string) => ts.padEnd(14, "0"); // The versions of a whole-page record: the other whole-page records of the // same original URL (`siblings` may hold anything — the channel's records; // the ones that are not versions of this page are ignored). Undefined for an // item record, or a page held in one capture only. export function pageVersions(post: Pick, siblings: ReadonlyArray>): PageVersionsView | undefined { if (!post.page || !isWholePageId(post.id)) return undefined; const original = post.page.originalUrl; const all = new Map>(); for (const s of [post, ...siblings]) { if (s.page && s.page.originalUrl === original && isWholePageId(s.id)) all.set(s.id, s); } if (all.size < 2) return undefined; const list = [...all.values()].sort((a, b) => tsKey(a.page!.captureTs).localeCompare(tsKey(b.page!.captureTs))); const changedOn: string[] = []; for (let i = 1; i < list.length; i++) { if (list[i]!.text.trim() !== list[i - 1]!.text.trim()) changedOn.push(waybackCaptureDate(list[i]!.page!.captureTs)); } return { count: list.length, changedOn, captures: list.map((s) => ({ id: s.id, date: waybackCaptureDate(s.page!.captureTs), waybackUrl: s.page!.waybackUrl, current: s.id === post.id, })), }; } // "4 captures of this page; text changed on 2015-06-11 and 2016-01-02." / // "2 captures of this page; the text is the same in both." export function pageVersionsLine(v: Pick): string { const head = `${v.count} captures of this page`; if (v.changedOn.length === 0) return `${head}; the text is the same in ${v.count === 2 ? "both" : "all"}.`; const dates = v.changedOn.length === 1 ? v.changedOn[0] : `${v.changedOn.slice(0, -1).join(", ")} and ${v.changedOn[v.changedOn.length - 1]}`; return `${head}; text changed on ${dates}.`; } export function pageCaptureView( post: Pick & Partial>, siblings: ReadonlyArray> = [], // Whether the original is known gone; default: the record's own flag (the // index merges the availability sidecar onto a served record). o: { originalGone?: boolean } = {}, ): PageCaptureView | undefined { const page = post.page; if (!page) return undefined; const originalGone = o.originalGone ?? (post.isDeleted === true || post.availability === "deleted"); const versions = pageVersions(post, siblings); const fallbackNote = pageFallbackNote(page); const firstSeen = page.firstSeenTs && tsKey(page.firstSeenTs) !== tsKey(page.captureTs) ? waybackCaptureDate(page.firstSeenTs) : undefined; return { kind: page.kind, kindLabel: pageKindLabel(page.kind), captureTs: page.captureTs, captureDate: waybackCaptureDate(page.captureTs), originalUrl: page.originalUrl, waybackUrl: page.archiveUrl ?? page.waybackUrl, links: pageCopyLinks(page, { originalGone }), ...(page.source && page.source !== "wayback" ? { source: page.source } : {}), ...(originalGone ? { originalGone: true } : {}), ...(page.title ? { title: page.title } : {}), ...(page.noContent ? { noContent: true } : {}), ...(fallbackNote ? { fallbackNote } : {}), ...(firstSeen ? { firstSeenDate: firstSeen } : {}), ...(versions ? { versions } : {}), }; } // One line of what the capture is: "Tumblr post · captured 2012-06-01". export function pageCaptureLine(v: Pick): string { return `${v.kindLabel} · captured ${v.captureDate}${v.firstSeenDate ? ` (first seen ${v.firstSeenDate})` : ""}`; }