这是一个基于 VitePress 的博客系统,支持自动从 markdown 文件生成博客列表。
docs/posts 和 docs/zh/posts 目录下的 markdown 文件在 docs/posts 目录下创建新的 markdown 文件,格式如下:
---
title: "文章标题"
date: "2024-01-15"
author: "作者名"
tags: ["标签1", "标签2"]
excerpt: "文章摘要(可选)"
---
文章内容...
运行以下命令生成博客数据:
npm run generate-blog
或者直接运行:
node scripts/generate-blog-data.js
npm run docs:dev
这会自动生成博客数据并启动开发服务器。
npm run docs:build
docs/
├── posts/ # 英文博客文章
│ ├── xmake-3-0-release.md
│ ├── building-cross-platform-apps.md
│ └── ...
├── zh/posts/ # 中文博客文章
│ ├── xmake-3-0-release.md
│ ├── cross-platform-development.md
│ └── ...
├── blog/
│ └── index.md # 英文博客首页
├── zh/blog/
│ └── index.md # 中文博客首页
└── .vitepress/
└── theme/
├── blog-data.js # 英文博客数据(自动生成)
└── zh-blog-data.js # 中文博客数据(自动生成)
scripts/
└── generate-blog-data.js # 博客数据生成脚本
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
title |
string | ✅ | 文章标题 |
date |
string | ✅ | 发布日期(YYYY-MM-DD 格式) |
author |
string | ❌ | 作者名称 |
tags |
array | ❌ | 标签数组 |
excerpt |
string | ❌ | 文章摘要,如果不提供会自动生成 |
npm run docs:dev 或 npm run docs:build 时,系统会自动重新生成博客数据YYYY-MM-DD 格式如果遇到问题:
gray-matter 包已正确安装可以通过修改以下文件来自定义博客系统:
scripts/generate-blog-data.js: 修改数据生成逻辑docs/blog/index.md 和 docs/zh/blog/index.md: 修改博客页面布局