← 返回 AI 筆記列表 2 min read
發布日期
最後更新日期
以 Astro 打造 $0 成本的 AI 知識庫與個人靜態站
記錄為何選擇 Astro Static Output、Content Collections 與 Islands 架構,在零伺服器費用的前提下兼顧型別安全與極速載入。
#Astro#AI-Engineering#Architecture
目錄 // TABLE OF CONTENTS (5)
為什麼選擇純靜態架構
建立個人 AI 學習筆記與作品展示站時,最常見的過度設計是直接架設資料庫與後端伺服器。對個人知識庫而言,**純靜態輸出(Static Output)**搭配 Git 版本控制,不僅將託管成本壓到 $0,也能將安全性風險降到最低。
核心設計取捨
- 預設零 JS:純文字閱讀頁面不需要載入任何前端框架 runtime。
- 按需 Islands 掛載:只有在攝影集 Lightbox 或互動篩選元件時才局部注水。
- 型別安全內容層:透過 Zod Schema 在建置期攔截缺少日期或格式錯誤的 Frontmatter。
Content Collections 實戰範例
以下是在 src/content/config.ts 定義型別安全集合的精簡寫法:
import { defineCollection } from 'astro:content';
import { notesSchema } from './schemas';
export const collections = {
notes: defineCollection({
type: 'content',
schema: notesSchema,
}),
};
建置期自動化驗證流程
每次提交前執行以下指令,即可依序完成型別檢查、單元測試與靜態產物契約驗證:
npm run check
npm run test:unit
npm run build
npm run test:build
小結與下一步
透過靜態化與測試驅動開發(TDD),我們能確保文章、財經專欄與攝影集在持續擴充時依然維持乾淨、可預測的輸出品質。