Новые изменения в компоненты

This commit is contained in:
Web-serfer 2026-04-26 23:47:23 +05:00
parent faf02848ed
commit 735289481c
7 changed files with 151 additions and 3 deletions

View file

@ -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;
}