import raw from "@/data/posts.json";

export type Post = { slug: string; title: string; date: string; image: string | null; content: string };
export const posts = raw as Post[];
export const getPost = (slug: string) => posts.find((p) => p.slug === slug);
export const excerpt = (p: Post, n = 160) => {
  const t = p.content.replace(/<[^>]+>/g, " ").replace(/&nbsp;/g, " ").replace(/\s+/g, " ").trim();
  return t.length > n ? t.slice(0, n).trimEnd() + "…" : t;
};
