Overview
TheProjects component displays a preview of your recent projects on the homepage. It shows the 3 oldest projects by start date, with title, description, and date range.
Location
Source:src/components/sections/Projects.astro
Purpose
This component:- Displays a preview of your projects on the homepage
- Shows project title, description, and date range
- Links to individual project detail pages
- Provides a “View More” button to see all projects
Data Source
The component fetches data from theprojects Content Collection using Astro’s getCollection() API:
src/content/config.ts:
Usage
The component is used insrc/pages/index.astro:
Sorting Logic
Projects are sorted by start date in ascending order (oldest first):The component displays the 3 oldest projects. This might be counterintuitive - you may want to change this to show the most recent projects by reversing the sort order.
Display Format
For each project, the component shows:- Title - Linked to the project detail page (
/projects/[slug]) - Description - Short project description
- Date Range - Formatted start date and optional end date
Date Formatting
The component uses theformateLocalDate() utility function from src/lib/utils.ts to display dates in a user-friendly format.
Adding Projects
To add a new project that will appear in this component:- Create a new
.mdor.mdxfile insrc/content/projects/ - Add the required frontmatter:
View More Button
The component includes a link to view all projects:/projects route in your Astro site, which displays your complete projects list.
Customization
Change Number of Projects Displayed
Modify the slice number in the component:Change Sort Order
To show the most recent projects first:Related Components
- See the Card component for container styling