feat(v2.0c): comments — third slice of v2.0 engagement#45
Merged
Conversation
Per-article visitor comments with editor moderation. Dual-toggle policy so a fresh deploy never accidentally exposes a comment form. Schema (Drizzle migration 0009) ------------------------------- - comments: id, articleId FK CASCADE, parentId (forward-compat for threading; UI is flat), authorName, authorEmail (collected, never displayed publicly), body (plain text — never markdown to keep XSS surface minimal), status enum (pending/approved/spam/ archived), ipHash (16-char SHA-256 truncate; never raw IP), submittedAt, moderatedBy + moderatedAt. - articles.commentsMode: new column. enum (inherit/on/off), default 'inherit'. Dual toggle ----------- - Site-wide: settings.commentsEnabled defaults to false. New Comments card in /cms/settings. - Per-article: radio (Inherit / On / Off) on the article form. - $lib/server/comments.commentsAllowedForArticle() is the one-line truth table both the public render and the POST endpoint use. Public surface -------------- - POST /api/comments. Reuses v2.0a hashIp + rate-limit (3/min per ipHash per article). Honeypot _hp via $lib/forms/constants (extracted to a non-server module so client + server share the field name). 410 when commentsAllowed=false; 429 on rate limit. - (www)/[locale]/blog/[slug] page-server load now also fetches approved comments + computes commentsOpen. - New CommentSection.svelte renders approved comments + a fetch()-posted submission form. Fields: name (required, ≤80), email (required, ≤254, server-side regex), body (required, ≤4000). Plain-text rendering with whitespace-pre-wrap. - Page svelte mounts CommentSection when there are approved comments OR when commentsOpen=true. CMS surface ----------- - /cms/comments moderation queue. Status tabs (pending/approved/ spam/archived). Each row: status badge, timestamp, author + masked email (a***@e***.com via $lib/comments/mask), linked article title (batch-resolved per page), body, mark-as buttons (approved/ spam/archived), reply-via-email mailto, delete. Pagination 50/page. Pending count exposed for future sidebar badge. - Sidebar entry under taxonomy group, gated to editor+. Audit ----- - New comment.{create,approve,spam,archive,delete} AuditAction members. - Public submission writes comment.create with userId=null. - Moderation actions write the matching status-change action with the editor's userId. Constants --------- - HONEYPOT_FIELD + RATE_LIMIT_WINDOW_SECONDS + RATE_LIMIT_MAX_PER_ WINDOW moved from $lib/server/forms (server-only) to $lib/forms/ constants so client components can import them. Server module re-exports for backwards compat. i18n: 26 new comment_* / comments_* / cms_settings_comments_* keys (EN + TH). Migration 0009 already applied to live D1. Out of scope (deliberate non-goals for this slice): - Threaded replies — parentId is forward-compat only; UI is flat. - Comments on Pages — Pages are typically static. - Akismet/ML spam filtering — honeypot+rate-limit is the v2.0 floor. - Email notifications when comment approved. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
thunpisit
added a commit
to codustry/khaopad-example
that referenced
this pull request
May 2, 2026
Cherry-picks upstream PR codustry#45. Migration 0009 already applied to live D1 from upstream. Field-merged: blog/[slug]/+page.svelte (paypers shell preserved, CommentSection mounted) + 26 new comment_* / comments_* / cms_settings_comments_* keys in messages/en.json + th.json. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Third of four v2.0 PRs. Per-article visitor comments with editor moderation. Dual-toggle policy so a fresh deploy never accidentally exposes a comment form.
Schema (migration 0009)
Dual toggle (Option C)
Public
CMS
Audit
Constants module
i18n
26 new keys (EN + TH).
Migration
0009 already applied to live D1.
Deliberately out of scope
Test plan
🤖 Generated with Claude Code