diff --git a/src/actions/index.ts b/src/actions/index.ts index ae6e7c9..0fef424 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -5,6 +5,7 @@ import { partialRender } from '@/helpers/container'; import { decreaseLikes, increaseLikes, queryLikes, queryUserId } from '@/helpers/db/query'; import { pages, posts } from '@/helpers/schema'; import { encodedEmail, urlJoin } from '@/helpers/tools'; +import options from '@/options'; import { ActionError, defineAction } from 'astro:actions'; import { z } from 'astro:schema'; @@ -91,8 +92,9 @@ export const server = { } const content = await partialRender(Comment, { props: { comments: comments } }); + const next = options.settings.comments.size + offset < comments.roots_count; - return { content }; + return { content, next }; }, }), }; diff --git a/src/assets/scripts/yufan.me.js b/src/assets/scripts/yufan.me.js index 0259f71..0d7a917 100644 --- a/src/assets/scripts/yufan.me.js +++ b/src/assets/scripts/yufan.me.js @@ -172,12 +172,15 @@ if (typeof comments !== 'undefined' && comments !== null) { return handleActionError(error); } - const { content } = data; - if (content === '') { - // Remove the load more button. + const { content, next } = data; + + // Remove the load more button. + if (!next || content === '') { event.target.remove(); - } else { - // Append the comments into the list. + } + + // Append the comments into the list. + if (content !== '') { event.target.dataset.offset = Number(offset) + Number(size); comments.querySelector('.comment-list').insertAdjacentHTML('beforeend', content); } diff --git a/src/components/comment/Comments.astro b/src/components/comment/Comments.astro index bde653d..4eb67b4 100644 --- a/src/components/comment/Comments.astro +++ b/src/components/comment/Comments.astro @@ -17,7 +17,7 @@ const comments = await loadComments(commentKey, title, 0); await increaseViews(commentKey, title); --- -