/* global React, ReactDOM */ /* lp-blog.jsx — dual mode: listing (no slug) / article (slug present) */ const { useEffect: useEff_bl, useState: useSt_bl } = React; const SANITY_PROJECT = 'gyrzd1m5'; const SANITY_DATASET = 'production'; const SANITY_API = `https://${SANITY_PROJECT}.api.sanity.io/v2024-01-01/data/query/${SANITY_DATASET}`; const SANITY_IMG = `https://cdn.sanity.io/images/gyrzd1m5/${SANITY_DATASET}/`; const slugify = (text) => text.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]/g, ''); const formatDate = (iso) => { if (!iso) return ''; return new Date(iso).toLocaleDateString('es-MX', { year: 'numeric', month: 'long', day: 'numeric' }); }; /* ══════════════════════════════════════════ BLOG LISTING ═══════════════════════════════════════════ */ function BlogCard({ post, featured }) { const href = `/blog?slug=${post.slug || ''}`; if (featured) { return (
{post.category}{post.readTime ? ` · ${post.readTime} min` : ''}

{post.title}

{post.excerpt &&

{post.excerpt}

} {formatDate(post.publishedAt)} Leer artículo
); } return ( {post.imageUrl &&
}
{post.category}{post.readTime ? ` · ${post.readTime} min` : ''}

{post.title}

{post.excerpt &&

{post.excerpt}

} {formatDate(post.publishedAt)}
); } function BlogListing() { const [posts, setPosts] = useSt_bl([]); const [loading, setLoading] = useSt_bl(true); useEff_bl(() => { const q = encodeURIComponent( `*[_type=="post"] | order(publishedAt desc) { title, "slug": slug.current, category, readTime, publishedAt, excerpt, "imageUrl": mainImage.asset->url }` ); fetch(`${SANITY_API}?query=${q}`) .then(r => r.json()) .then(d => { setPosts(d.result || []); setLoading(false); }) .catch(() => setLoading(false)); }, []); return ( <>