Featured Posts
Display a list of posts in a card format
Command docs How to add this block to your project
npm run add FeaturedPostsUse the FeaturedPosts component to display a list of posts in a card format. Each post can include an image, badge, title, description, author, and publish date.
Understanding Astro Islands Architecture Josh Wayne 2024/03/12
How Rendering Works in Astro: SSG, SSR, and Hybrid Astro supports static site generation, server-side rendering, and hybrid rendering in a single project. Read more ->
Jane Dane 2024/04/02Using Multiple UI Frameworks in Astro Chris Floyd 2024/05/10Astro allows you to mix and match UI frameworks like React, Vue, and Svelte in the same project. Read more ->
Unlock code How to use the FeaturedPosts component in Astro
---const items = [{ img: { src: '/img/astro-islands.png', alt: 'Diagram explaining Astro Islands architecture', width: 1200, height: 200 }, badge: { text: 'Core Concept', icon: rocket // Pass an SVG string to your icon }, title: 'Understanding Astro Islands Architecture', author: { avatar: { img: '/img/avatars/josh-wayne.png' }, name: 'Josh Wayne' }, publishDate: '2024/03/12', description: 'Astro Islands let you ship zero JavaScript...', href: '/astro-islands', cta: 'Read more ->'}, { ... }, { ... }]---
<FeaturedPosts items={items} />The component only requires a items prop referencing an array of Post object. If posts have a featured image, only the first one will be displayed to increase visual hierarchy. The first post will be displayed in its own column, while the other posts will be displayed in a list layout.
Reverse Layout
In case you want to display the first featured post on the right side, you can set the reverse prop to true to reverse the layout:
Understanding Astro Islands Architecture Josh Wayne 2024/03/12
How Rendering Works in Astro: SSG, SSR, and Hybrid Astro supports static site generation, server-side rendering, and hybrid rendering in a single project. Read more ->
Jane Dane 2024/04/02Using Multiple UI Frameworks in Astro Chris Floyd 2024/05/10Astro allows you to mix and match UI frameworks like React, Vue, and Svelte in the same project. Read more ->
Unlock code How to reverse the layout
<FeaturedPosts items={items} reverse={true}/>API
Unlock code Component API reference
type FeaturedPostsProps = { items: Post[] reverse?: boolean className?: string}| Prop | Purpose |
|---|---|
items | Sets the posts to display. |
reverse | Set to true to reverse the layout. |
className | Pass additional CSS classes for the card. |