@plumix/plugin-comments
v0.3.0
Published
Comments plugin for Plumix — threaded, moderated discussion on entries with a tested playground.
Maintainers
Readme
@plumix/plugin-comments
This Plumix plugin adds threaded, moderated comments to your entries — with a moderation queue, nesting, rate limiting, and email notifications.
Install
pnpm add @plumix/plugin-commentsThen add it to your plumix.config.ts and pick which entry types accept comments:
import { plumix } from "plumix";
import { comments } from "@plumix/plugin-comments";
export default plumix({
// …your runtime, database, and auth
plugins: [comments({ entryTypes: ["post"] })],
});The plugin ships a database table. Regenerate migrations after adding it:
plumix migrate generateWhat you get
- A
/commentsmoderation page (under Content) — approve, mark spam, or trash, gated behind acomment:moderatecapability. - Public endpoints —
POST /_plumix/comments/submitandGET /_plumix/comments/list, plus a{type}/{id}/commentsREST resource. - A
commentstemplate dependency your theme renders for the current entry. - A comment form that posts as a plain
<form method="post">, so it works with JavaScript switched off, and is upgraded in place where there is some. - Moderation hooks —
comment:moderate(trust policy) andcomment:created(notify).
Configuration
comments({
entryTypes: ["post"], // types that accept comments
mode: "first_time", // "all" | "first_time" | "none" — when to hold for review
maxDepth: 3, // reply nesting depth
rootsPerPage: 20, // roots per page
requireEmail: true, // require an author email
closeAfterDays: null, // auto-close threads after N days
notifyEmail: "[email protected]", // moderator address for pending comments
rateLimit: { max: 5, windowMin: 10 }, // per-author submission limit
});Notifications use the top-level mailer from your Plumix config.
Rendering in a theme
Load a thread without pulling in admin code via the /server entry:
import { loadThread } from "@plumix/plugin-comments/server";
const thread = await loadThread(ctx, { type: "post", id });Drop the form into a template with the component from the /theme entry. It
posts as a plain <form method="post">, so it works before any JavaScript
loads:
import { defineTemplate } from "plumix/theme";
import { PlumixCommentForm } from "@plumix/plugin-comments/theme";
export const post = defineTemplate({
single: {
comments: ["current"],
render: ({ data, comments }) => (
<article>
<Thread data={comments?.current} />
<PlumixCommentForm entryId={data.entry.id} />
</article>
),
},
});A theme writing its own controls calls usePlumixCommentForm from
@plumix/plugin-comments/hooks instead, and posts to the same endpoint.
Support
Have a question? Start a discussion. Found a bug? Open an issue.
Contributing
PRs and ideas welcome. The Contributing guide gets you set up — new contributors especially welcome.
License
MIT © Plumix Contributors
