Astro 專題 - DevPulse:極簡開發者技術雷達 (Tech Radar)-2

更新 發佈閱讀 3 分鐘

(進階) 在 Astro 5 中讀取並顯示

我們可以直接在頁面中把這些資料抓出來,並根據 status 分類。

在 src/pages/index.astro 中:

---
import { getCollection } from 'astro:content';

// 取得所有技術清單
const allTechs = await getCollection('techs');

// 按照狀態預分類 (這在 Server 端完成,SEO 滿分)
const categories = {
mastered: allTechs.filter(t => t.data.status === 'mastered'),
learning: allTechs.filter(t => t.data.status === 'learning'),
wishlist: allTechs.filter(t => t.data.status === 'wishlist'),
};
---

<div class="grid gap-8">
{Object.entries(categories).map(([status, items]) => (
<section>
<h2 class="text-2xl font-bold capitalize mb-4 border-b border-gray-200 pb-2">
{status}
</h2>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
{items.map(item => (
<div class="p-4 rounded-xl border border-gray-100 bg-white shadow-sm hover:shadow-md transition-shadow">
<span class="text-3xl mb-2 block">{item.data.icon}</span>
<h3 class="font-bold">{item.data.name}</h3>
<p class="text-sm text-gray-500 line-clamp-2">{item.body}</p>
</div>
))}
</div>
</section>
))}
</div>
留言
avatar-img
李昀瑾的沙龍
0會員
37內容數
李昀瑾的沙龍的其他內容
2026/02/26
這是一個讓開發者管理自己「想學、正在學、已精通」技術清單的工具,強調極速的頁面切換與流暢的 UI。 環境架構設計 astro v5 tailwind v4 Nano Stores vercel 佈署
2026/02/26
這是一個讓開發者管理自己「想學、正在學、已精通」技術清單的工具,強調極速的頁面切換與流暢的 UI。 環境架構設計 astro v5 tailwind v4 Nano Stores vercel 佈署
2026/02/19
要在 Astro v5 儀表板中加入互動圖表,最推薦的方式是使用 Recharts 或 Chart.js 配合 React 或 Vue 組件,因為圖表需要客戶端(Client-side)的 JavaScript 來達成縮放、懸停提示等互動功能。
2026/02/19
要在 Astro v5 儀表板中加入互動圖表,最推薦的方式是使用 Recharts 或 Chart.js 配合 React 或 Vue 組件,因為圖表需要客戶端(Client-side)的 JavaScript 來達成縮放、懸停提示等互動功能。
2026/02/12
在 Astro v5 的架構下,為多語系儀表板加入搜索功能,最推薦的方案是 Pagefind。它是一個極其快速、靜態化的搜尋庫,非常適合 Astro 這種注重效能的框架。 以下是將 Pagefind 整合進你的專案的步驟: 1. 安裝與設定 Pagefind 是在構建(Build)完成後掃描
2026/02/12
在 Astro v5 的架構下,為多語系儀表板加入搜索功能,最推薦的方案是 Pagefind。它是一個極其快速、靜態化的搜尋庫,非常適合 Astro 這種注重效能的框架。 以下是將 Pagefind 整合進你的專案的步驟: 1. 安裝與設定 Pagefind 是在構建(Build)完成後掃描
看更多