Enable and manage comments for your content very easily!
You should have installed an instance of Strapi v4.x.x
Run the following command in your project root:
npm install strapi-plugin-comment-manager
For your frontend to have access to the API, enable the following permissions for Comment Manager from Users & Permissions Plugin on your project settings:
For public, enable: count, find and getPageSize.
For authenticated, enable create on both Comment and Subcomment.
Comments can be displayed in the frontend in two ways:
- Using the React components library strapi-comments-client (recommended)
- Build your custom frontend using the API
There are some Typescript interfaces that will help to get an idea of the data structures.
interface IComment {
id: string;
from_admin: boolean;
createdAt: string;
content: string;
author: IAuthor | null;
subcomments?: ISubcomment[];
}
interface ISubcomment {
id: string;
from_admin: boolean;
createdAt: string;
content: string;
author: IAuthor | null;
}
interface IAuthor {
username: string;
email: string;
id: string;
}
The following endpoints are exposed to fetch and post comments and subcomments:
Method: GET
Path: /api/comment-manager/comments/:slug
Optional query parameters: start, ignoreCount
Returns:
{
commentsCount?: Number;
comments: IComment[];
}
The parameter start
indicates how many comments to skip. This is for pagination purposes.
The parameter ignoreCount
indicates whether or not to return the total number of comments associated with the given slug.
Method: GET
Path: /api/comment-manager/comments/:slug/count
Returns:
{
count: Number;
}
Method: POST
Path: /api/comment-manager/comments/:slug
Authentication: Bearer token
Payload:
{
content: string;
}
Returns:
{
id: Number;
}
Method: POST
Path: /api/comment-manager/subcomments/:parent-id
Authentication: Bearer token
Payload:
{
content: string;
}
Returns:
{
id: Number;
}
Method: GET
Path: /api/comment-manager/page-size
Returns:
{
pageSize: Number;
}
The plugin allows to set how many comments are returned per page by going to the Pagination section under Comment Manager Plugin on the Settings section.
The default page size is 10.
Admin users are able to delete comments and subcomments as well as leave replies as admins from within the plugin page of the Strapi admin dashboard.
The plugin interface has two tabs: one for the latest comments and one for comments by content ID.
Issues are submitted to https://github.com/luisguve/strapi-plugin-comment-manager/issues. Please provide as much information as possible about the bug or feature request.
For more detailed instructions on how to install, configure & use this plugin, check out this post.