Arreglo posts horizontales

This commit is contained in:
2025-03-25 09:47:24 +01:00
parent c16fd89953
commit e1c6cf61cb

View File

@@ -1,61 +1,57 @@
--- ---
import { getCollection } from "astro:content"; import { getCollection } from "astro:content";
const posts = await getCollection("posts"); const posts = await getCollection("posts");
// Selecciona 3 posts aleatorios // Selecciona 3 posts aleatorios
const selectedPosts = posts.sort(() => Math.random() - 0.5).slice(0, 3); const selectedPosts = posts.sort(() => Math.random() - 0.5).slice(0, 3);
--- ---
<div class="flex flex-wrap justify-center -mx-2"> <div class="flex flex-wrap justify-center -mx-2">
{ {
selectedPosts.map((post) => ( selectedPosts.map((post) => (
<div class="w-full md:w-1/3 p-2 mb-4 animate-on-scroll"> <div class="w-full md:w-1/3 p-2 mb-4 animate-on-scroll">
<div class="card bg-base-100 shadow-lg h-full"> <div class="card relative overflow-hidden bg-gradient-to-b from-neutral/80 to-neutral/90 dark:from-base-100/80 dark:to-base-100/90 shadow-lg h-full">
<div class="flex flex-wrap"> <div class="absolute inset-0 z-0">
<div class="w-full md:w-1/2"> <div class="aspect-[16/9] overflow-hidden">
<div class="aspect-square overflow-hidden rounded-l"> <img
<img src={post.data.imagen} class="object-cover w-full h-full" alt={post.data.titulo} /> src={post.data.imagen}
class="w-full h-full object-cover opacity-40 dark:opacity-50"
alt={post.data.titulo}
/>
</div> </div>
<div class="absolute inset-0 bg-black/40 dark:bg-black/30"></div>
</div> </div>
<div class="w-full md:w-1/2"> <div class="relative z-10 flex flex-col p-6 h-full">
<div class="card-body flex flex-col h-full p-4"> <h5 class="text-xl font-bold mb-3 text-white dark:text-base-content">
<h5 class="text-xl font-semibold mb-2">
{post.data.titulo} {post.data.titulo}
</h5> </h5>
<p class="text-base flex-grow post-content"> <p class="text-base mb-4 text-white/90 dark:text-base-content/80 line-clamp-3">
{post.data.descripcion} {post.data.descripcion}
</p> </p>
<a href={"/posts/" + post.id} class="btn btn-primary mt-auto"> <a
Ver detalles href={"/posts/" + post.id}
class="btn btn-primary w-full mt-auto"
>
Leer post
</a> </a>
</div> </div>
</div> </div>
</div> </div>
</div>
</div>
)) ))
} }
</div> </div>
<style> <style>
.post-content {
display: -webkit-box;
-webkit-box-orient: vertical;
flex-grow: 1;
overflow: hidden;
-webkit-line-clamp: 3;
}
.card { .card {
transition: transform 0.3s ease, box-shadow 0.3s ease; transition:
display: flex; transform 0.3s ease,
flex-direction: column; box-shadow 0.3s ease;
height: 100%;
} }
.card:hover { .card:hover {
transform: translateY(-5px); transform: translateY(-5px);
box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.15) !important; box-shadow: 0 0 1rem rgba(0, 0, 0, 0.15) !important;
} }
.btn-primary { .line-clamp-3 {
transition: transform 0.3s ease; display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
} }
</style> </style>