Files
arjmand-pharmacy/lib/blog.ts
T
Alireza HassaniandCursor 66e604c426 Connect the storefront to Meshkee catalog, blogs, and static image slots.
Wire homepage specials, product/blog pages, instant search, and the customer portal so the live pharmacy site can be managed from the dashboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-19 23:51:41 +03:30

47 lines
1.2 KiB
TypeScript

import { meshkeeGet, tenantPath } from "@/lib/meshkee";
export type BlogPost = {
id: string;
title: string;
slug: string;
abstract?: string | null;
mainTextHtml?: string | null;
titleImageUrl?: string | null;
publishedAt?: string | null;
createdAt?: string | null;
commentCount?: number;
author?: { name?: string } | string | null;
};
export type PagedBlogs = {
items: BlogPost[];
total: number;
page: number;
pageSize: number;
};
export async function fetchBlogs(params: { page?: number; pageSize?: number } = {}) {
const query = new URLSearchParams();
query.set("page", String(params.page ?? 1));
query.set("pageSize", String(params.pageSize ?? 12));
return meshkeeGet<PagedBlogs>(tenantPath(`/blogs?${query.toString()}`), {
items: [],
total: 0,
page: 1,
pageSize: params.pageSize ?? 12,
});
}
export async function fetchBlog(slug: string) {
const data = await meshkeeGet<{ blog?: BlogPost }>(tenantPath(`/blogs/${encodeURIComponent(slug)}`), {});
return data.blog ?? null;
}
export function blogImage(post: BlogPost) {
return post.titleImageUrl || "/placeholders/blog.svg";
}
export function blogHref(post: BlogPost) {
return `/blog/${encodeURIComponent(post.slug)}`;
}