Something went wrong. Try again.
a tool for shared writing and social publishing
Something went wrong. Try again.
TypeScript
at perf/paste
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import { PubLeafletContent, PubLeafletPagesCanvas, PubLeafletPagesLinearDocument, PubLeafletPublicationPage,} from "lexicons/api";
import type { Fact } from "src/replicache";import type { Attribute } from "src/replicache/attributes";import { processBlocksToPages, type ProcessBlocksToPagesHooks,} from "src/utils/factsToPagesRecord";
export async function leafletToPublicationPageRecord(opts: { facts: Fact<Attribute>[]; root_entity: string; // Set when the facts hold a whole draft leaflet rather than one page's. start_page?: string; publication_uri: string; path: string; title?: string; publishedAt?: string; hooks: ProcessBlocksToPagesHooks;}): Promise<PubLeafletPublicationPage.Record> { const { pages } = await processBlocksToPages({ facts: opts.facts, root_entity: opts.root_entity, start_page: opts.start_page, hooks: opts.hooks, });
const pagesArray: PubLeafletContent.Main["pages"] = pages.map((p) => { if (p.type === "canvas") { return { $type: "pub.leaflet.pages.canvas" as const, id: p.id, blocks: p.blocks as PubLeafletPagesCanvas.Block[], }; } return { $type: "pub.leaflet.pages.linearDocument" as const, id: p.id, blocks: p.blocks as PubLeafletPagesLinearDocument.Block[], }; });
return { $type: "pub.leaflet.publicationPage", publication: opts.publication_uri, path: opts.path, ...(opts.title !== undefined && { title: opts.title }), publishedAt: opts.publishedAt ?? new Date().toISOString(), content: { $type: "pub.leaflet.content", pages: pagesArray, }, };}