2026-06-08FRONTEND

Article-generator

/article/add Page Summary

Access Control

  • Server component (page.tsx) checks session on every request
  • Non-admin users are immediately redirected to /

Form Fields

(add-article-form.tsx)

FieldTypeBehavior
TitleText inputRequired. Auto-generates slug as you type
SlugText inputPre-filled from title (kebab-case). Becomes independent once manually edited
DateDate pickerDefaults to today's date
TagsText inputComma-separated string, split into string[] on submit
BodyThree-mode editorSee Body Modes below

Body Modes

A toggle in the top-right corner of the body field switches between three modes. body state is always a markdown string and stays in sync across all modes.

ModeDescription
Rich TextLexical WYSIWYG editor with full toolbar. Serializes to markdown via $convertToMarkdownString on every change. Remounts with $convertFromMarkdownString when switching back from Markdown mode.
MarkdownPlain monospace <textarea> that reads/writes body directly as raw markdown.
PreviewRendered output via ArticlePreview, which supports headings, blockquotes, code blocks, tables, HR, and links.

Lexical Toolbar

(lexical-editor.tsx)

GroupButtons
HistoryUndo, Redo (disabled when unavailable)
Text formatBold, Italic, Underline, Strikethrough, Inline Code, Superscript, Subscript
Block typeParagraph, H1, H2, H3, Blockquote, Code Block
ListsBullet list, Numbered list
AlignmentLeft, Center, Right, Justify
InsertLink (inline URL input), Horizontal Rule

Submit Flow

  1. Submit button is disabled until title, slug, and body are all non-empty
  2. Calls createArticle server action (article-actions.ts)
  • Re-validates admin role server-side
  • Inserts into the articles table via Drizzle
  • Revalidates /article cache
  1. Success → shows "Article published successfully!" with a "Write another" button that resets the form
  2. Error → displays error message inline above the submit button

Key Files