fix: add title to acquire the comments.

This commit is contained in:
Yufan Sheng 2024-06-17 05:15:18 +08:00
parent de93b65386
commit 42dc768087
Signed by: syhily
GPG Key ID: DEB186763C308C31
3 changed files with 16 additions and 5 deletions

View File

@ -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;
---
<div id="comments" class="comments py-5">

View File

@ -30,14 +30,25 @@ export const getConfig = async (): Promise<CommentConfig | null> => {
return data != null ? (data as CommentConfig) : data;
};
export const loadComments = async (key: string, offset: number, config: CommentConfig): Promise<Comments | null> => {
const query = querystring.stringify({
export const loadComments = async (
key: string,
title: string | null,
offset: number,
config: CommentConfig,
): Promise<Comments | null> => {
let params: Record<string, string | number | boolean> = {
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) => {

View File

@ -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('');
}