feat: add the switch for enable or disable the comments.
This commit is contained in:
parent
2903026ab4
commit
cb95e90d97
27
README.md
27
README.md
@ -108,6 +108,18 @@ This weblog uses artalk as its backend comment service. But since artalk didn't
|
|||||||
We decide to query it directly from the Postgres database. So the comments and fav clicks are living in the same
|
We decide to query it directly from the Postgres database. So the comments and fav clicks are living in the same
|
||||||
database.
|
database.
|
||||||
|
|
||||||
|
If you don't want the astro integration, change the switch in `options.ts` to `false`.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
settings: {
|
||||||
|
comments: {
|
||||||
|
enable: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### S3 Compatible Storage Integration
|
### S3 Compatible Storage Integration
|
||||||
|
|
||||||
This blog will upload all the built resources at build stage. You can remove this feature by removing the
|
This blog will upload all the built resources at build stage. You can remove this feature by removing the
|
||||||
@ -135,8 +147,8 @@ date: 2013/7/13 20:46:25
|
|||||||
|
|
||||||
| Setting | Description | Required | Default |
|
| Setting | Description | Required | Default |
|
||||||
|-------------|--------------------------------------|----------|----------------------|
|
|-------------|--------------------------------------|----------|----------------------|
|
||||||
| `slug` | ID (unique), used as the permalink | true | Filename |
|
| `slug` | ID (unique), used as the permalink | true | |
|
||||||
| `title` | Title | true | Filename |
|
| `title` | Title | true | |
|
||||||
| `date` | Published date | true | |
|
| `date` | Published date | true | |
|
||||||
| `updated` | Updated date | false | Published date |
|
| `updated` | Updated date | false | Published date |
|
||||||
| `comments` | Enables comment feature for the post | false | `true` |
|
| `comments` | Enables comment feature for the post | false | `true` |
|
||||||
@ -151,14 +163,15 @@ date: 2013/7/13 20:46:25
|
|||||||
### Pages Front Matter Settings
|
### Pages Front Matter Settings
|
||||||
|
|
||||||
| Setting | Description | Required | Default |
|
| Setting | Description | Required | Default |
|
||||||
|-------------|--------------------------------------|----------|----------------|
|
|-------------|--------------------------------------|----------|----------------------|
|
||||||
| `slug` | ID (unique), used as the permalink | true | Filename |
|
| `slug` | ID (unique), used as the permalink | true | |
|
||||||
| `title` | Title | true | Filename |
|
| `title` | Title | true | |
|
||||||
| `date` | Published date | true | |
|
| `date` | Published date | true | |
|
||||||
| `updated` | Updated date | false | Published date |
|
| `updated` | Updated date | false | Published date |
|
||||||
| `comments` | Enables comment feature for the post | false | `true` |
|
| `comments` | Enables comment feature for the page | false | `true` |
|
||||||
|
| `summary` | Page summary in plain text | false | First 140 characters |
|
||||||
| `cover` | The cover image | false | `null` |
|
| `cover` | The cover image | false | `null` |
|
||||||
| `published` | Whether the post should be published | false | `true` |
|
| `published` | Whether the page should be published | false | `true` |
|
||||||
| `toc` | Display the Table of Contents | false | `false` |
|
| `toc` | Display the Table of Contents | false | `false` |
|
||||||
|
|
||||||
## Weblog Design
|
## Weblog Design
|
||||||
|
@ -67,6 +67,7 @@ const Options = z
|
|||||||
calendar: z.boolean().default(false),
|
calendar: z.boolean().default(false),
|
||||||
}),
|
}),
|
||||||
comments: z.object({
|
comments: z.object({
|
||||||
|
enable: z.boolean().optional().default(true),
|
||||||
size: z.number().default(10).readonly(),
|
size: z.number().default(10).readonly(),
|
||||||
avatar: z.object({
|
avatar: z.object({
|
||||||
mirror: z.string().url().readonly(),
|
mirror: z.string().url().readonly(),
|
||||||
@ -190,6 +191,7 @@ const options: z.input<typeof Options> = {
|
|||||||
calendar: true,
|
calendar: true,
|
||||||
},
|
},
|
||||||
comments: {
|
comments: {
|
||||||
|
enable: true,
|
||||||
size: 10,
|
size: 10,
|
||||||
avatar: {
|
avatar: {
|
||||||
mirror: 'https://weavatar.com/avatar',
|
mirror: 'https://weavatar.com/avatar',
|
||||||
|
@ -15,7 +15,7 @@ const CommentConnectError = new ActionError({
|
|||||||
message: "couldn't connect to comment server",
|
message: "couldn't connect to comment server",
|
||||||
});
|
});
|
||||||
|
|
||||||
export const server = {
|
const normalActions = {
|
||||||
like: defineAction({
|
like: defineAction({
|
||||||
accept: 'json',
|
accept: 'json',
|
||||||
input: z
|
input: z
|
||||||
@ -53,6 +53,9 @@ export const server = {
|
|||||||
return { avatar: urlJoin(import.meta.env.SITE, 'avatar', `${hash}.webp`) };
|
return { avatar: urlJoin(import.meta.env.SITE, 'avatar', `${hash}.webp`) };
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
const commentActions = {
|
||||||
comment: defineAction({
|
comment: defineAction({
|
||||||
accept: 'json',
|
accept: 'json',
|
||||||
input: z.object({
|
input: z.object({
|
||||||
@ -98,3 +101,5 @@ export const server = {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const server = options.settings.comments.enable ? { ...normalActions, ...commentActions } : { ...normalActions };
|
||||||
|
@ -11,17 +11,18 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { commentKey, title } = Astro.props;
|
const { commentKey, title } = Astro.props;
|
||||||
const comments = await loadComments(commentKey, title, 0);
|
const comments = options.settings.comments.enable ? await loadComments(commentKey, title, 0) : null;
|
||||||
|
|
||||||
// Increase the PV in production environment.
|
// Increase the PV in production environment.
|
||||||
if (options.isProd()) {
|
if (options.settings.comments.enable && options.isProd()) {
|
||||||
await increaseViews(commentKey, title);
|
await increaseViews(commentKey, title);
|
||||||
}
|
}
|
||||||
---
|
---
|
||||||
|
|
||||||
<div id="comments" class="comments pt-5">
|
{
|
||||||
{
|
options.settings.comments.enable && (
|
||||||
comments != null ? (
|
<div id="comments" class="comments pt-5">
|
||||||
|
{comments != null ? (
|
||||||
<>
|
<>
|
||||||
<div class="h5 mb-4 comment-total-count">
|
<div class="h5 mb-4 comment-total-count">
|
||||||
评论 <small class="font-theme text-sm">({comments.count})</small>
|
评论 <small class="font-theme text-sm">({comments.count})</small>
|
||||||
@ -57,7 +58,13 @@ if (options.isProd()) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-submit text-end">
|
<div class="form-submit text-end">
|
||||||
<input type="button" id="cancel-comment-reply-link" class="btn btn-light me-1" value="再想想" hidden />
|
<input
|
||||||
|
type="button"
|
||||||
|
id="cancel-comment-reply-link"
|
||||||
|
class="btn btn-light me-1"
|
||||||
|
value="再想想"
|
||||||
|
hidden
|
||||||
|
/>
|
||||||
<input name="submit" type="submit" id="submit" class="btn btn-primary" value="发表评论" />
|
<input name="submit" type="submit" id="submit" class="btn btn-primary" value="发表评论" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -73,6 +80,7 @@ if (options.isProd()) {
|
|||||||
data-key={commentKey}
|
data-key={commentKey}
|
||||||
data-size={options.settings.comments.size}
|
data-size={options.settings.comments.size}
|
||||||
data-offset={options.settings.comments.size}
|
data-offset={options.settings.comments.size}
|
||||||
|
type="button"
|
||||||
class="btn btn-light"
|
class="btn btn-light"
|
||||||
>
|
>
|
||||||
加载更多
|
加载更多
|
||||||
@ -82,6 +90,7 @@ if (options.isProd()) {
|
|||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
'评论加载失败 ❌'
|
'评论加载失败 ❌'
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</div>
|
|
||||||
|
@ -4,7 +4,7 @@ import options from '@/options';
|
|||||||
---
|
---
|
||||||
|
|
||||||
{
|
{
|
||||||
options.settings.sidebar.comment > 0 && (
|
options.settings.comments.enable && options.settings.sidebar.comment > 0 && (
|
||||||
<div id="recent-comments" class="widget widget-recent-comments">
|
<div id="recent-comments" class="widget widget-recent-comments">
|
||||||
<div class="widget-title">近期评论</div>
|
<div class="widget-title">近期评论</div>
|
||||||
<ul id="recent-comments">
|
<ul id="recent-comments">
|
||||||
|
Loading…
Reference in New Issue
Block a user