import { PagePropsType } from "@/src/types";
import { DSQL_TBEN_ME_BLOG_POSTS } from "@/src/types/dsql";
import { BunextPageServerFn } from "@moduletrace/bunext/types";
import sql from "@/src/utils/db";

export const server: BunextPageServerFn<PagePropsType> = async (ctx) => {
    const blog_posts_res = await sql`
        SELECT * FROM blog_posts
        WHERE published=1
        ORDER BY id DESC
    `;

    const blog_posts: DSQL_TBEN_ME_BLOG_POSTS[] = [...blog_posts_res];

    return {
        props: {
            blogPosts: blog_posts,
        },
    };
};
