5407bf4dff
Deploy / deploy (push) Successful in 8m0s
A page is now an ordered list of independent blocks (analysis.page_block), no sections and no headings; every block has an id shown on the page so it can be pointed at. Paper detail pages use page "paper/<conf>/<ext_id>", analysis pages on /contents use "content/<node id>". - /api/blocks (list, replace a page, add) and /api/blocks/:id (get, patch, move, delete) - dynamic block types (stats, tool-table, paper-table, benchmark-table) are filled from the database at render time; the two content pages are rendered from their blocks (seeded with defaults on first view) - one-time migration copies the legacy articles into blocks (section titles dropped, links become a links block); legacy tables are kept untouched - old /api/articles, ArticleView and PaperGroup removed Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FbMbJPadPzVwvt9rU9GBNo
65 lines
3.2 KiB
TypeScript
65 lines
3.2 KiB
TypeScript
import { getContent } from './content';
|
|
import { getPaperList } from './content-papers';
|
|
import { findNode } from './content-tree';
|
|
import { getToolTable } from './tool-taxonomy';
|
|
import type { PageBlock, Resolved, StatItem } from './blocks';
|
|
|
|
type Content = Awaited<ReturnType<typeof getContent>>;
|
|
type List = Awaited<ReturnType<typeof getPaperList>>;
|
|
|
|
/** Fill the dynamic blocks of a page (stats, tables) with live numbers. Static blocks pass through unchanged. */
|
|
export async function resolveBlocks(blocks: PageBlock[]): Promise<PageBlock[]> {
|
|
const contents = new Map<string, Promise<Content | null>>();
|
|
const lists = new Map<string, Promise<List | null>>();
|
|
const content = (id: string) => {
|
|
const n = findNode(id);
|
|
return contents.get(id) ?? contents.set(id, n?.kind === 'tools' ? getContent(n) : Promise.resolve(null)).get(id)!;
|
|
};
|
|
const list = (id: string) => {
|
|
const n = findNode(id);
|
|
return lists.get(id) ?? lists.set(id, n?.kind === 'papers' ? getPaperList(n) : Promise.resolve(null)).get(id)!;
|
|
};
|
|
let tools: ReturnType<typeof getToolTable> | null = null;
|
|
|
|
return Promise.all(blocks.map(async (pb): Promise<PageBlock> => {
|
|
const b = pb.block;
|
|
let resolved: Resolved | undefined;
|
|
switch (b.type) {
|
|
case 'stats': {
|
|
const [c, l] = await Promise.all([content(b.data.node), list(b.data.node)]);
|
|
const items: StatItem[] = [];
|
|
for (const it of b.data.items) {
|
|
const fill = (name: string) => it.label.replace('{name}', name);
|
|
switch (it.metric) {
|
|
case 'area-papers': if (c) items.push({ value: c.total, label: fill('') }); break;
|
|
case 'benchmark-count': if (c) items.push({ value: c.benchmarks.length, label: fill('') }); break;
|
|
case 'taxonomy-papers': {
|
|
const t = c?.taxonomy.find((x) => x.id === it.arg);
|
|
if (t) items.push({ value: t.n, label: fill(t.label), href: it.href ?? `/papers?node=${t.id}` });
|
|
break;
|
|
}
|
|
case 'group-papers': if (l) items.push({ value: l.total, label: fill('') }); break;
|
|
case 'group-analysed': if (l) items.push({ value: l.analysed.length, label: fill('') }); break;
|
|
case 'group-venues': if (l) for (const v of l.byVenue.slice(0, Number(it.arg) || 4)) items.push({ value: v.n, label: fill(v.conf_short) }); break;
|
|
default: if (it.value !== undefined) items.push({ value: it.value, label: fill(''), href: it.href });
|
|
}
|
|
}
|
|
resolved = { type: 'stats', items };
|
|
break;
|
|
}
|
|
case 'tool-table': resolved = { type: 'tool-table', table: await (tools ??= getToolTable()) }; break;
|
|
case 'paper-table': {
|
|
const l = await list(b.data.node);
|
|
resolved = { type: 'paper-table', papers: l?.papers ?? [] };
|
|
break;
|
|
}
|
|
case 'benchmark-table': {
|
|
if (b.data.scope === 'areas') resolved = { type: 'benchmark-table', rows: (await content(b.data.node))?.benchmarks ?? [], showNew: true };
|
|
else resolved = { type: 'benchmark-table', rows: (await list(b.data.node))?.benchmarks ?? [], showNew: false };
|
|
break;
|
|
}
|
|
}
|
|
return resolved ? { ...pb, resolved } : pb;
|
|
}));
|
|
}
|