From 42dc768087342fb24931730c7263c95919ab4c77 Mon Sep 17 00:00:00 2001 From: Yufan Sheng Date: Mon, 17 Jun 2024 05:15:18 +0800 Subject: [PATCH] fix: add title to acquire the comments. --- src/components/comment/Comments.astro | 2 +- src/components/comment/artalk.ts | 17 ++++++++++++++--- src/pages/comments/list.ts | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/components/comment/Comments.astro b/src/components/comment/Comments.astro index df8fbad..b5cec85 100644 --- a/src/components/comment/Comments.astro +++ b/src/components/comment/Comments.astro @@ -10,7 +10,7 @@ interface Props { const { commentKey, title } = Astro.props; const config = await getConfig(); -const comments = config != null ? await loadComments(commentKey, 0, config) : null; +const comments = config != null ? await loadComments(commentKey, title, 0, config) : null; ---
diff --git a/src/components/comment/artalk.ts b/src/components/comment/artalk.ts index 0cf21a2..0e5e270 100644 --- a/src/components/comment/artalk.ts +++ b/src/components/comment/artalk.ts @@ -30,14 +30,25 @@ export const getConfig = async (): Promise => { return data != null ? (data as CommentConfig) : data; }; -export const loadComments = async (key: string, offset: number, config: CommentConfig): Promise => { - const query = querystring.stringify({ +export const loadComments = async ( + key: string, + title: string | null, + offset: number, + config: CommentConfig, +): Promise => { + let params: Record = { limit: config.frontend_conf.pagination.pageSize, offset: offset, flat_mode: false, page_key: key, site_name: options.title, - }); + }; + if (title !== null) { + params = { ...params, title: title }; + } + const query = querystring.stringify(params); + + console.log(query); const data = await fetch(urlJoin(server, `/api/v2/comments?${query}`)) .then((response) => response.json()) .catch((e) => { diff --git a/src/pages/comments/list.ts b/src/pages/comments/list.ts index 46e6b71..a7b3dba 100644 --- a/src/pages/comments/list.ts +++ b/src/pages/comments/list.ts @@ -19,7 +19,7 @@ export const GET: APIRoute = async ({ url }) => { return new Response(''); } - const comments = await loadComments(key, Number(offset), config); + const comments = await loadComments(key, null, Number(offset), config); if (comments === null) { return new Response(''); }