import directus from "./directus";
import { readItems } from "@directus/sdk";

export const posts = await directus.request(
    readItems("codyops_posts", {
        fields: ['*']
        }
    )
);

export function getAllPosts() {
    return posts;
};

export function getUniqueTags(posts: any ) {
    const allTags = posts.flatMap((post: any) => post.tags);
    const uniqueTags = [...new Set(allTags)];
    return uniqueTags;
};
  
export function filterPostsByTag(posts: any, tag: any) {
    return posts.filter((post: any) => post.tags.includes(tag));
};
  