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
46 lines
3.1 KiB
TypeScript
46 lines
3.1 KiB
TypeScript
import { tx } from './db';
|
|
|
|
// One-time copy of the legacy articles (analysis.article / section / block / link) into analysis.page_block.
|
|
// Each legacy block becomes its own page block; section titles disappear (a block is a story, not a section);
|
|
// list blocks get a short lead-in sentence so they still read on their own; the links become one `links` block at the end.
|
|
const LEAD: Record<string, string> = {
|
|
'key-contribution': 'What the paper puts on the table:',
|
|
evaluation: 'How the evaluation is set up:',
|
|
limitations: 'Where the work falls short:',
|
|
notes: 'Worth keeping in mind:',
|
|
};
|
|
|
|
const stripHeadings = (t: string) => t.split('\n').filter((l) => !/^\s*#{1,6}\s/.test(l)).join('\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
|
|
export async function migrateLegacyArticles(): Promise<void> {
|
|
await tx(async (q) => {
|
|
await q('SELECT pg_advisory_xact_lock(7001)');
|
|
if ((await q("SELECT 1 FROM analysis.migration WHERE name = 'articles-to-page-blocks'")).length) return;
|
|
const arts = await q<{ id: number; subject_conf: string; subject_ext_id: string }>('SELECT id, subject_conf, subject_ext_id FROM analysis.article ORDER BY id');
|
|
for (const a of arts) {
|
|
const page = `paper/${a.subject_conf}/${a.subject_ext_id}`;
|
|
const [{ n }] = await q<{ n: number }>('SELECT COALESCE(MAX(position) + 1, 0) AS n FROM analysis.page_block WHERE page = ?', [page]);
|
|
let pos = n;
|
|
const out: { type: string; data: any }[] = [];
|
|
// depth-first over sections: parents before children, siblings by position
|
|
const secs = await q<{ id: number; parent_id: number | null; key: string; title: string }>('SELECT id, parent_id, key, title FROM analysis.section WHERE article_id = ? ORDER BY position, id', [a.id]);
|
|
const order: typeof secs = [];
|
|
const walk = (parent: number | null) => { for (const s of secs.filter((x) => (x.parent_id ?? null) === parent)) { order.push(s); walk(s.id); } };
|
|
walk(null);
|
|
for (const s of order) {
|
|
const blocks = await q<{ type: string; data: any }>('SELECT type, data FROM analysis.block WHERE section_id = ? ORDER BY position', [s.id]);
|
|
for (const b of blocks) {
|
|
let data = b.data;
|
|
if (b.type === 'markdown') { const text = stripHeadings(String(data.text ?? '')); if (!text) continue; data = { ...data, text }; }
|
|
if (b.type === 'list' && !data.lead) data = { ...data, lead: LEAD[s.key] ?? `${s.title}:` };
|
|
out.push({ type: b.type, data });
|
|
}
|
|
}
|
|
const links = await q<{ kind: string; title: string; url: string; note: string | null }>('SELECT kind, title, url, note FROM analysis.link WHERE article_id = ? ORDER BY position, id', [a.id]);
|
|
if (links.length) out.push({ type: 'links', data: { items: links.map((l) => ({ kind: l.kind, title: l.title, url: l.url, ...(l.note ? { note: l.note } : {}) })) } });
|
|
for (const b of out) await q('INSERT INTO analysis.page_block(page, position, type, data) VALUES (?,?,?,?::jsonb)', [page, pos++, b.type, JSON.stringify(b.data)]);
|
|
}
|
|
await q("INSERT INTO analysis.migration(name) VALUES ('articles-to-page-blocks')");
|
|
});
|
|
}
|