Zoeken...  ⌘K GitHub

BlogGrid Sections

Blog overzicht met featured grote post + 3-koloms kaartgrid. Categorie badges, auteur info.

/blog-grid
src/components/sections/BlogGrid.astro
---
/**
 * BlogGrid
 * Blog overzicht — 3-koloms kaartgrid met featured eerste post.
 */
interface BlogPost {
  title: string;
  excerpt: string;
  category?: string;
  date?: string;
  readTime?: string;
  image?: string;
  href?: string;
  author?: string;
  authorAvatar?: string;
  featured?: boolean;
}

interface Props {
  eyebrow?: string;
  headline?: string;
  posts: BlogPost[];
  ctaLabel?: string;
  ctaHref?: string;
}

const {
  eyebrow,
  headline,
  posts = [],
  ctaLabel,
  ctaHref,
} = Astro.props;

const featured = posts.find(p => p.featured) ?? posts[0];
const regular = posts.filter(p => !p.featured && p !== posts[0]).slice(0, 6);
---

<section class="bg" data-component="blog-grid">
  <div class="bg__inner">
    {(eyebrow || headline) && (
      <div class="bg__header">
        {eyebrow && <p class="bg__eyebrow">{eyebrow}</p>}
        {headline && <h2 class="bg__title" set:html={headline} />}
      </div>
    )}

    <!-- Featured -->
    {featured && (
      <a href={featured.href ?? '#'} class="bg__featured">
        {featured.image && (
          <div class="bg__featured-img">
            <img src={featured.image} alt={featured.title} loading="lazy" />
          </div>
        )}
        <div class="bg__featured-body">
          {featured.category && <span class="bg__cat">{featured.category}</span>}
          <h3 class="bg__featured-title">{featured.title}</h3>
          <p class="bg__featured-excerpt">{featured.excerpt}</p>
          <div class="bg__meta">
            {featured.authorAvatar && <img src={featured.authorAvatar} alt={featured.author ?? ''} class="bg__author-avatar" />}
            <div class="bg__meta-text">
              {featured.author && <span class="bg__author">{featured.author}</span>}
              <span class="bg__date-time">
                {featured.date}
                {featured.date && featured.readTime ? ' · ' : ''}
                {featured.readTime}
              </span>
            </div>
          </div>
        </div>
      </a>
    )}

    <!-- Regular grid -->
    {regular.length > 0 && (
      <div class="bg__grid">
        {regular.map(post => (
          <a href={post.href ?? '#'} class="bg__card">
            {post.image && (
              <div class="bg__card-img">
                <img src={post.image} alt={post.title} loading="lazy" />
              </div>
            )}
            <div class="bg__card-body">
              {post.category && <span class="bg__cat">{post.category}</span>}
              <h3 class="bg__card-title">{post.title}</h3>
              <p class="bg__card-excerpt">{post.excerpt}</p>
              <div class="bg__meta">
                {post.authorAvatar && <img src={post.authorAvatar} alt={post.author ?? ''} class="bg__author-avatar" />}
                <div class="bg__meta-text">
                  {post.author && <span class="bg__author">{post.author}</span>}
                  <span class="bg__date-time">
                    {post.date}
                    {post.date && post.readTime ? ' · ' : ''}
                    {post.readTime}
                  </span>
                </div>
              </div>
            </div>
          </a>
        ))}
      </div>
    )}

    {ctaLabel && (
      <div class="bg__cta-wrap">
        <a href={ctaHref ?? '#'} class="bg__cta">{ctaLabel}</a>
      </div>
    )}
  </div>
</section>

<style>
  .bg {
    background: var(--color-bg, #fff);
    padding: 5rem 1.5rem;
  }

  .bg__inner {
    max-width: 1200px;
    margin: 0 auto;
  }

  .bg__header {
    margin-bottom: 3rem;
  }

  .bg__eyebrow {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-accent, #6366f1);
    margin-bottom: 0.75rem;
  }

  .bg__title {
    font-size: clamp(1.875rem, 3vw, 2.75rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--color-primary, #0a0a0a);
  }

  .bg__title :global(em) {
    font-style: normal;
    color: var(--color-accent, #6366f1);
  }

  /* Featured */
  .bg__featured {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    align-items: center;
    margin-bottom: 3rem;
    text-decoration: none;
    border: 1px solid rgba(0,0,0,0.07);
    border-radius: calc(var(--radius, 0.5rem) * 2);
    overflow: hidden;
    transition: box-shadow 0.2s;
  }

  .bg__featured:hover { box-shadow: 0 12px 40px rgba(0,0,0,0.08); }

  .bg__featured-img {
    height: 360px;
    overflow: hidden;
  }

  .bg__featured-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
  }

  .bg__featured:hover .bg__featured-img img { transform: scale(1.03); }

  .bg__featured-body { padding: 2.5rem; }

  .bg__featured-title {
    font-size: 1.625rem;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.02em;
    color: var(--color-primary, #0a0a0a);
    margin: 0.75rem 0 0.875rem;
  }

  .bg__featured-excerpt {
    font-size: 1rem;
    line-height: 1.65;
    color: var(--color-muted, #6b7280);
    margin-bottom: 1.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Grid */
  .bg__grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
  }

  .bg__card {
    text-decoration: none;
    border: 1px solid rgba(0,0,0,0.07);
    border-radius: calc(var(--radius, 0.5rem) * 1.5);
    overflow: hidden;
    transition: box-shadow 0.2s;
    display: flex;
    flex-direction: column;
  }

  .bg__card:hover { box-shadow: 0 8px 28px rgba(0,0,0,0.07); }

  .bg__card-img {
    height: 200px;
    overflow: hidden;
  }

  .bg__card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
  }

  .bg__card:hover .bg__card-img img { transform: scale(1.04); }

  .bg__card-body {
    padding: 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  .bg__card-title {
    font-size: 1.0625rem;
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: -0.01em;
    color: var(--color-primary, #0a0a0a);
    margin: 0.625rem 0 0.625rem;
  }

  .bg__card-excerpt {
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--color-muted, #6b7280);
    flex: 1;
    margin-bottom: 1.25rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Common */
  .bg__cat {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-accent, #6366f1);
    background: color-mix(in srgb, var(--color-accent, #6366f1) 10%, transparent);
    padding: 0.25rem 0.625rem;
    border-radius: 100px;
  }

  .bg__meta {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-top: auto;
  }

  .bg__author-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
  }

  .bg__meta-text {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
  }

  .bg__author {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-primary, #0a0a0a);
  }

  .bg__date-time {
    font-size: 0.75rem;
    color: var(--color-muted, #6b7280);
  }

  .bg__cta-wrap {
    text-align: center;
    margin-top: 3rem;
  }

  .bg__cta {
    display: inline-block;
    border: 1.5px solid rgba(0,0,0,0.12);
    color: var(--color-primary, #0a0a0a);
    padding: 0.8125rem 2rem;
    border-radius: var(--radius, 0.5rem);
    font-weight: 700;
    font-size: 0.9375rem;
    text-decoration: none;
    transition: all 0.2s;
  }

  .bg__cta:hover {
    border-color: var(--color-primary, #0a0a0a);
    background: var(--color-primary, #0a0a0a);
    color: #fff;
  }

  @media (max-width: 900px) {
    .bg__grid { grid-template-columns: repeat(2, 1fr); }
    .bg__featured { grid-template-columns: 1fr; }
    .bg__featured-img { height: 240px; }
    .bg__featured-body { padding: 1.5rem; }
  }

  @media (max-width: 540px) {
    .bg__grid { grid-template-columns: 1fr; }
  }
</style>

Props

Prop Type Default Beschrijving
posts * BlogPost[] Blog posts. featured: true voor grote post.
eyebrow string Label boven sectie
headline string Sectie headline
ctaLabel string CTA knop onderaan

* = verplicht