--- // ListadoPosts.astro const posts = await Astro.glob("../pages/posts/*.mdx"); // Función para ordenar posts const orderPosts = (posts, orderBy = "fecha", ascending = false) => { return [...posts].sort((a, b) => { if (orderBy === "fecha") { const comparison = new Date(b.frontmatter.fecha).getTime() - new Date(a.frontmatter.fecha).getTime(); return ascending ? -comparison : comparison; } else if (orderBy === "titulo") { const comparison = a.frontmatter.titulo.localeCompare(b.frontmatter.titulo); return ascending ? comparison : -comparison; } return 0; }); }; // Ordenar posts por defecto (más reciente primero) const initialPosts = orderPosts(posts, "fecha", false); ---

Blog Ecobjetivos

Explora nuestros artículos sobre sostenibilidad y desarrollo

{ initialPosts.map((post) => (
{post.frontmatter.imagen ? ( {post.frontmatter.titulo} ) : (
)}

{post.frontmatter.titulo}

{post.frontmatter.descripcion}

{post.frontmatter.autor} {new Date(post.frontmatter.fecha).toLocaleDateString('es-ES', { year: 'numeric', month: 'long', day: 'numeric' })}
Leer más
)) }