fix: add title to acquire the comments.
This commit is contained in:
parent
3edf70a36b
commit
66f7e0fb21
@ -10,7 +10,7 @@ interface Props {
|
|||||||
|
|
||||||
const { commentKey, title } = Astro.props;
|
const { commentKey, title } = Astro.props;
|
||||||
const config = await getConfig();
|
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">
|
<div id="comments" class="comments py-5">
|
||||||
|
@ -30,14 +30,25 @@ export const getConfig = async (): Promise<CommentConfig | null> => {
|
|||||||
return data != null ? (data as CommentConfig) : data;
|
return data != null ? (data as CommentConfig) : data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loadComments = async (key: string, offset: number, config: CommentConfig): Promise<Comments | null> => {
|
export const loadComments = async (
|
||||||
const query = querystring.stringify({
|
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,
|
limit: config.frontend_conf.pagination.pageSize,
|
||||||
offset: offset,
|
offset: offset,
|
||||||
flat_mode: false,
|
flat_mode: false,
|
||||||
page_key: key,
|
page_key: key,
|
||||||
site_name: options.title,
|
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}`))
|
const data = await fetch(urlJoin(server, `/api/v2/comments?${query}`))
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
|
@ -19,7 +19,7 @@ export const GET: APIRoute = async ({ url }) => {
|
|||||||
return new Response('');
|
return new Response('');
|
||||||
}
|
}
|
||||||
|
|
||||||
const comments = await loadComments(key, Number(offset), config);
|
const comments = await loadComments(key, null, Number(offset), config);
|
||||||
if (comments === null) {
|
if (comments === null) {
|
||||||
return new Response('');
|
return new Response('');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user