// Wayback pages (release 37, plans/release-37/wayback-pages.md): a non-video // Wayback Machine capture as a first-class record — a Post on platform // "webpage". This file is the CONTRACT the release's lanes code against: the // record's `page` facts, what an extractor is, and how a record's id is made. // Types and pure helpers only; no I/O. import { createHash } from "node:crypto"; import type { WaybackProvenance } from "../wayback"; import type { ForumPostInfo, PostMedia, PostRef } from "../posts"; // What an extractor recognised the capture as. "generic" is the fallback for // every page no site extractor claims (articles, personal sites). export const PAGE_KINDS = [ "generic", "tumblr-post", "tumblr-index", "tweet", "x-profile", "forum-post", "gdoc", "yt-about", // Release 38 lane C: Newgrounds (extractors/newgrounds.ts). "ng-user", "ng-art", "ng-movie", ] as const; export type PageKind = (typeof PAGE_KINDS)[number]; // The facts of one capture a record came from (Post.page). Provenance is never // lost: the original URL, the capture's timestamp, the replay URL and the raw // (`id_`) URL are always present. export type PagePostInfo = WaybackProvenance & { kind: PageKind; // From CDX when known. title?: string; mimetype?: string; digest?: string; status?: number; // The content's own date (ISO-8601) when the extractor can read it; the // record's createdAt is this, else the capture time. publishedAt?: string; // A split record (one item of a capture that holds many) seen in several // captures is ONE record: the latest capture's facts win, the first // capture's timestamp is kept here. firstSeenTs?: string; // The id of the first imported capture of the same originalUrl (a whole-page // record that is a later version of a page already held). versionOf?: string; // The capture held only a shell (a JS app's frame, a doc's edit page): the // record exists so the capture is accounted for, its text says so. noContent?: boolean; // Which extractor made the record, and its version, so a re-extract knows // what is stale. extractor: string; extractorVersion: number; // The site extractor that claimed the capture and threw: the record is the // generic extractor's, and says which one failed and why (release 37 S1). extractorFallback?: { from: string; fromVersion: number; error: string }; // Tags the page gives the item (Tumblr tags). tags?: string[]; // Release 37 lane F (lib/archives/): the archive source the capture is // from — "archive.today", … — absent for the Wayback Machine (every record // made before sources existed). For a source that is not the Wayback // Machine, `archiveUrl` is the copy's URL (archive.today's // `https://archive.ph/`), and `waybackUrl` / `rawUrl` hold that same // URL (they are required, and a reader that knows no source still links // the copy): cite by `pageArchiveLink(page)` (lib/archives/mementos.ts), // which names the source. source?: string; archiveUrl?: string; }; // What an extractor hands back per record, before it becomes a Post. The // importer fills id, slug, channelSlug, platform, uploadDate, threadId, url // and the provenance half of `page`. export type PageRecordDraft = { kind: PageKind; // A stable id for an ITEM inside a capture: "tumblr-", // "tweet-", "kf-". Absent = the record is the whole page, // and its id is pageRecordId(captureTs, originalUrl). itemId?: string; // The item's own permalink when it has one (a tweet's status URL, a Tumblr // post's URL); else the capture's original URL is the record's url. url?: string; title?: string; author?: string; authorName?: string; publishedAt?: string; text: string; links: string[]; media?: PostMedia[]; tags?: string[]; noContent?: boolean; replyTo?: PostRef; quoted?: PostRef; repostOf?: PostRef; isReply?: boolean; isRepost?: boolean; // forum-post records: the shape the live forum channel uses, so the same // thread's ids line up. forum?: ForumPostInfo; }; export type PageExtractInput = { html: string; // The capture: its provenance and what CDX said about it. capture: WaybackProvenance & { mimetype?: string; digest?: string; status?: number }; }; // One module per kind (S3), each pure: no network, no disk, no clock. A // capture goes to the FIRST registered extractor whose `matches` is true, else // to the generic extractor (S1). export type PageExtractor = { // A short stable name ("tumblr", "x", "xenforo", "gdoc", "yt-about"). name: string; // Bump when the output for the same input changes; a re-extract redoes // records made by an older version. version: number; matches(originalUrl: URL, html: string): boolean; extract(input: PageExtractInput): PageRecordDraft[]; }; // A short, stable hash of a URL (12 hex chars of sha256). export function urlHash(url: string): string { return createHash("sha256").update(url).digest("hex").slice(0, 12); } // The id of a whole-page record: one captured state of one page. export function pageRecordId(captureTs: string, originalUrl: string): string { return `${captureTs}-${urlHash(originalUrl)}`; } // The thread a page's versions group under (groupIntoThreads). export function pageThreadId(originalUrl: string): string { return `page-${urlHash(originalUrl)}`; }