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
67 lines
3.0 KiB
TypeScript
67 lines
3.0 KiB
TypeScript
import { query } from './db';
|
|
import { ensureAnalysisSchema } from './analysis-schema';
|
|
import type { ContentNode } from './content-tree';
|
|
|
|
export interface ListedPaper { id: number; conf: string; ext_id: string | null; title: string; conf_short: string; date: string; analysed: boolean }
|
|
export interface AnalysedArticle { paperId: number; paperTitle: string; updatedAt: string }
|
|
export interface PaperListContent {
|
|
total: number;
|
|
papers: ListedPaper[];
|
|
analysed: AnalysedArticle[];
|
|
byVenue: { conf_short: string; n: number }[];
|
|
benchmarks: { id: number; name: string; n: number }[];
|
|
}
|
|
|
|
const TEXT = `(p.title || ' ' || COALESCE(p.abstract, '') || ' ' || COALESCE(p.keywords, ''))`;
|
|
|
|
function where(node: ContentNode): { sql: string; params: string[] } {
|
|
const m = node.match;
|
|
if (!m) return { sql: 'FALSE', params: [] };
|
|
return m.require
|
|
? { sql: `${TEXT} ~ ? AND ${TEXT} ~* ?`, params: [m.pattern, m.require] }
|
|
: { sql: `${TEXT} ~ ?`, params: [m.pattern] };
|
|
}
|
|
|
|
/** Papers an analysis page of kind 'papers' is about, and the analysis articles written about them. */
|
|
export async function getPaperList(node: ContentNode): Promise<PaperListContent> {
|
|
const w = where(node);
|
|
const papers = await query<Omit<ListedPaper, 'analysed'>>(
|
|
`SELECT p.id, p.conf, p.ext_id, p.title, c.short AS conf_short, COALESCE(c.start_date, '2026-06-01') AS date
|
|
FROM papers p JOIN conferences c ON c.slug = p.conf
|
|
WHERE ${w.sql} ORDER BY date DESC, p.id`, w.params);
|
|
|
|
// a paper counts as analysed when its detail page has blocks (page = paper/<conf>/<ext_id>)
|
|
let pages: { page: string; updated_at: Date }[] = [];
|
|
try {
|
|
await ensureAnalysisSchema();
|
|
pages = await query(`SELECT page, MAX(updated_at) AS updated_at FROM analysis.page_block WHERE page LIKE 'paper/%' GROUP BY page ORDER BY MAX(updated_at) DESC`);
|
|
} catch { /* no analysis schema reachable: list the papers without analyses */ }
|
|
const byKey = new Map(papers.map((p) => [`${p.conf}/${p.ext_id}`, p]));
|
|
const analysed: AnalysedArticle[] = [];
|
|
const done = new Set<string>();
|
|
for (const pg of pages) {
|
|
const key = pg.page.slice('paper/'.length);
|
|
const p = byKey.get(key);
|
|
if (!p) continue;
|
|
done.add(key);
|
|
analysed.push({ paperId: p.id, paperTitle: p.title, updatedAt: new Date(pg.updated_at).toISOString().slice(0, 10) });
|
|
}
|
|
|
|
const ids = papers.map((p) => p.id);
|
|
const benchmarks = ids.length
|
|
? await query<{ id: number; name: string; n: number }>(
|
|
`SELECT b.id, b.name, COUNT(DISTINCT pb.paper_id) AS n FROM paper_benchmarks pb JOIN benchmarks b ON b.id = pb.bench_id
|
|
WHERE pb.paper_id = ANY(?) GROUP BY b.id, b.name ORDER BY n DESC, b.id LIMIT 12`, [ids])
|
|
: [];
|
|
const venues = new Map<string, number>();
|
|
for (const p of papers) venues.set(p.conf_short, (venues.get(p.conf_short) ?? 0) + 1);
|
|
|
|
return {
|
|
total: papers.length,
|
|
papers: papers.map((p) => ({ ...p, analysed: done.has(`${p.conf}/${p.ext_id}`) })),
|
|
analysed,
|
|
byVenue: [...venues].map(([conf_short, n]) => ({ conf_short, n })).sort((a, b) => b.n - a.n),
|
|
benchmarks,
|
|
};
|
|
}
|