664 字
Nuxt 4 + Nuxt Content v3 静态博客架构实践
ON THIS PAGE
构建个人博客时,最容易陷入的误区就是“过度设计”——还没写几篇文章,就先搭起了 MySQL 数据库、后台管理系统、图床和各种复杂接口。
在本项目中,我采用了本地 Markdown 驱动 + 纯静态预渲染(SSG)的方案,将运维成本降为零。
核心技术栈
- 框架:Nuxt 4(采用全新的
app/扁平目录规范) - 样式:Tailwind CSS v4 +
@tailwindcss/typography - 内容解析:Nuxt Content v3 +
zod强类型校验 - 托管平台:Cloudflare Pages
使用 Zod 保护文章元数据
为了防止写文章时漏写标题、写错日期格式,我们在根目录的 content.config.ts 中定义了严格的 Schema:
import { defineContentConfig, defineCollection } from '@nuxt/content'
import { z } from 'zod'
export default defineContentConfig({
collections: {
posts: defineCollection({
type: 'page',
source: 'posts/**/*.md',
schema: z.object({
title: z.string().min(1),
description: z.string().min(5).max(200),
date: z.coerce.date(),
category: z.string().default('随笔'),
tags: z.array(z.string()).default([]),
draft: z.boolean().default(false)
})
})
}
})
一旦某篇文章缺少必填字段,构建阶段就会立即报错拦截,确保线上站点永远干净可靠。
总结
好的个人博客架构应该像空气一样让人感受不到它的存在:写作时顺畅,发布时自动,阅读时秒开。