2024-12-02 17:29:45 -06:00
|
|
|
import { PostCarousel } from "../../components/PostCarousel.tsx";
|
2024-11-26 23:35:32 -06:00
|
|
|
|
|
|
|
import { Handlers, PageProps } from "$fresh/server.ts";
|
2024-12-02 17:29:45 -06:00
|
|
|
import { Post } from "../../components/PostCard.tsx";
|
2024-11-26 23:35:32 -06:00
|
|
|
|
|
|
|
interface PageData {
|
|
|
|
featuredPosts: Post[];
|
2024-12-02 17:29:45 -06:00
|
|
|
recentPosts: Post[];
|
2024-11-26 23:35:32 -06:00
|
|
|
hotPosts: Post[];
|
|
|
|
popularPosts: Post[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export const handler: Handlers<PageData> = {
|
|
|
|
async GET(_: any, ctx: any) {
|
2024-12-02 17:29:45 -06:00
|
|
|
const [featuredResult, recentResult, hotResult, popularResult] =
|
|
|
|
await Promise.all([
|
|
|
|
fetch(`${Deno.env.get("BASE_URI_API")}/posts/featured`),
|
|
|
|
fetch(`${Deno.env.get("BASE_URI_API")}/posts/recent`),
|
|
|
|
fetch(`${Deno.env.get("BASE_URI_API")}/posts/hot`),
|
|
|
|
fetch(`${Deno.env.get("BASE_URI_API")}/posts/popular`),
|
|
|
|
]);
|
2024-11-26 23:35:32 -06:00
|
|
|
|
2024-12-02 17:29:45 -06:00
|
|
|
// parse all JSON responses concurrently
|
|
|
|
const [featuredPosts, recentPosts, hotPosts, popularPosts] = await Promise
|
|
|
|
.all([
|
|
|
|
featuredResult.json(),
|
|
|
|
recentResult.json(),
|
|
|
|
hotResult.json(),
|
|
|
|
popularResult.json(),
|
|
|
|
]);
|
2024-11-26 23:35:32 -06:00
|
|
|
|
|
|
|
return ctx.render({
|
|
|
|
featuredPosts,
|
2024-12-02 17:29:45 -06:00
|
|
|
recentPosts,
|
2024-11-26 23:35:32 -06:00
|
|
|
hotPosts,
|
|
|
|
popularPosts,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function PostPage({ data }: PageProps<PageData>) {
|
2024-12-02 17:29:45 -06:00
|
|
|
const { featuredPosts, recentPosts, hotPosts, popularPosts } = data;
|
2024-11-26 23:35:32 -06:00
|
|
|
|
2024-10-10 15:16:55 -05:00
|
|
|
return (
|
2024-12-02 17:29:45 -06:00
|
|
|
<div class="space-y-12 px-10 py-8 bg-[#313244]">
|
|
|
|
<h1 class="text-3xl text-white font-bold uppercase text-center">Blog</h1>
|
2024-11-26 23:35:32 -06:00
|
|
|
<section>
|
2024-12-02 17:29:45 -06:00
|
|
|
<h2 class="text-2xl font-bold mb-2 text-white text-center lg:text-left">
|
|
|
|
Featured Posts
|
|
|
|
</h2>
|
|
|
|
<div className="text-lg font-thin italic mb-4 text-white text-center lg:text-left">
|
|
|
|
Ignite the impossible
|
|
|
|
</div>
|
2024-11-26 23:35:32 -06:00
|
|
|
<PostCarousel posts={featuredPosts} />
|
|
|
|
</section>
|
|
|
|
<section>
|
2024-12-02 17:29:45 -06:00
|
|
|
<h2 class="text-2xl font-bold mb-2 text-white text-center lg:text-left">
|
|
|
|
Recent Posts
|
|
|
|
</h2>
|
|
|
|
<div className="text-lg font-thin italic mb-4 text-white text-center lg:text-left">
|
|
|
|
Now with 100% fresh perspective
|
|
|
|
</div>
|
|
|
|
<PostCarousel posts={recentPosts} />
|
|
|
|
</section>
|
|
|
|
<section>
|
|
|
|
<h2 class="text-2xl font-bold mb-2 text-white text-center lg:text-left">
|
|
|
|
Hot Posts
|
|
|
|
</h2>
|
|
|
|
<div className="text-lg font-thin italic mb-4 text-white text-center lg:text-left">
|
|
|
|
Making chaos look cool since forever
|
|
|
|
</div>
|
2024-11-26 23:35:32 -06:00
|
|
|
<PostCarousel posts={hotPosts} />
|
|
|
|
</section>
|
|
|
|
<section>
|
2024-12-02 17:29:45 -06:00
|
|
|
<h2 class="text-2xl font-bold mb-2 text-white text-center lg:text-left">
|
|
|
|
Popular Posts
|
|
|
|
</h2>
|
|
|
|
<div className="text-lg font-thin italic mb-4 text-white text-center lg:text-left">
|
|
|
|
Content may cause uncontrollable reading
|
|
|
|
</div>
|
2024-11-26 23:35:32 -06:00
|
|
|
<PostCarousel posts={popularPosts} />
|
|
|
|
</section>
|
2024-10-10 15:16:55 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|