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>
47 lines
1.2 KiB
TypeScript
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)}`;
|
|
}
|