Новые изменения в компоненты
This commit is contained in:
parent
faf02848ed
commit
735289481c
7 changed files with 151 additions and 3 deletions
|
|
@ -169,4 +169,20 @@ export function getPostImageUrl(post: { image?: string }): string {
|
|||
return fileUrl;
|
||||
}
|
||||
return '/images/blog/default.avif';
|
||||
}
|
||||
|
||||
export async function getPostViews(postId: string): Promise<number> {
|
||||
try {
|
||||
const post = await pb.collection('posts').getOne(postId);
|
||||
return post.views || 0;
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
export async function incrementPostViews(postId: string): Promise<number> {
|
||||
const post = await pb.collection('posts').getOne(postId);
|
||||
const newViews = (post.views || 0) + 1;
|
||||
await pb.collection('posts').update(postId, { views: newViews });
|
||||
return newViews;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue