Import a Word document as a blog post, and add table blocks

- Table content blocks (migration 044): a grid of text, a row per
  line, cells split by |, the first row the header; cells take the
  same formatting as a paragraph; wide tables scroll on a phone
- Blog posts -> Import from Word: the server reads the .docx (zip and
  XML read without a library, sizes capped) and creates an unpublished
  post through the CRUD engine: title, date, headings, paragraphs,
  lists, tables, bold, italic and links; the editor opens with a note
  of what came over and what didn't (images)
- docs/importing.md, and an nginx block for the upload

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-29 12:44:20 -05:00
parent adc88e5714
commit 7f12824c93
16 changed files with 656 additions and 6 deletions

View file

@ -66,6 +66,23 @@ export default function ContentBlocks({
)
}
/* A table block's text as rows of cells: one row per line, cells
split by "|" (a literal bar is "\|"), blank lines skipped. A
leading and trailing bar, as in Markdown, is allowed. */
export function tableRows(text: string): string[][] {
return text
.split('\n')
.map((line) => line.trim())
.filter(Boolean)
.map((line) =>
line
.replace(/^\|/, '')
.replace(/(?<!\\)\|$/, '')
.split(/(?<!\\)\|/)
.map((cell) => cell.replace(/\\\|/g, '|').trim()),
)
}
function Caption({ text }: { text?: string | null }) {
if (!text) return null
return (
@ -165,6 +182,47 @@ function Block({ block, accent, anchor }: { block: ContentBlock; accent: string;
</figure>
)
case 'table': {
const rows = tableRows(text)
if (rows.length === 0) return null
const [head, ...body] = rows
const width = Math.max(...rows.map((row) => row.length))
return (
// Wide tables scroll sideways inside their box on a phone
// rather than squeezing every column to a word.
<div className="overflow-x-auto rounded-2xl border border-brand/15">
<table className="min-w-full text-left text-sm leading-snug">
<thead className="bg-tint">
<tr>
{Array.from({ length: width }, (_, i) => (
<th key={i} scope="col" className="min-w-[8rem] px-4 py-3 font-semibold text-ink">
<Inline text={head[i] ?? ''} accent={accent} />
</th>
))}
</tr>
</thead>
<tbody>
{body.map((row, r) => (
<tr key={r} className={r % 2 ? 'bg-tint-soft' : ''}>
{Array.from({ length: width }, (_, i) =>
i === 0 ? (
<th key={i} scope="row" className="min-w-[8rem] px-4 py-3 align-top font-semibold text-ink">
<Inline text={row[i] ?? ''} accent={accent} />
</th>
) : (
<td key={i} className="min-w-[8rem] px-4 py-3 align-top" style={{ color: BODY }}>
<Inline text={row[i] ?? ''} accent={accent} />
</td>
),
)}
</tr>
))}
</tbody>
</table>
</div>
)
}
case 'callout':
if (!text) return null
return (