一个极简、无数据库的博客系统,直接读取Markdown文件,支持代码高亮和响应式布局。
minimal-blog/ ├── posts/ # 存放Markdown文章 │ ├── hello-world.md # 示例文章 │ ├── markdown-guide.md # 示例文章 │ └── deployment.md # 示例文章 ├── public/ # 前端静态文件 │ ├── css/ │ │ └── style.css # 样式文件 │ ├── js/ │ │ ├── app.js # 主页脚本 │ │ └── post.js # 文章页脚本 │ ├── index.html # 主页HTML │ ├── post.html # 文章详情页HTML │ └── _headers # Cloudflare Pages配置 ├── functions/ # Cloudflare Pages函数 │ └── api/ │ └── [...path].js # API处理函数 ├── server.js # Express服务器(开发环境) ├── vercel.json # Vercel配置 └── package.json # 项目依赖
npm install
npm start
或者使用nodemon(开发环境):
npm run dev
访问 http://localhost:3000 查看博客。
在posts目录下创建新的.md文件,文件名将作为文章的URL slug。
在文件顶部添加YAML格式的元数据:
---
title: "文章标题"
date: "2023-10-15"
tags: ["标签1", "标签2"]
author: "作者名"
excerpt: "文章简介"
coverImage: "封面图片URL"
---
这里是文章的Markdown内容...
使用标准Markdown语法编写文章内容,支持:
详细步骤请参考:部署指南
详细步骤请参考:部署指南
编辑public/css/style.css文件来自定义博客的外观。
编辑以下文件来扩展功能:
server.js - 后端API逻辑public/js/app.js - 前端主页功能public/js/post.js - 前端文章页功能public目录下创建新的HTML文件server.js中添加路由(开发环境)获取所有文章列表。
响应示例:
[
{
"slug": "hello-world",
"title": "你好,世界!",
"date": "2023-10-15",
"tags": ["技术", "博客"],
"excerpt": "文章简介...",
"author": "作者名",
"coverImage": "封面图片URL"
}
]
获取单篇文章内容。
响应示例:
{
"slug": "hello-world",
"title": "你好,世界!",
"date": "2023-10-15",
"tags": ["技术", "博客"],
"excerpt": "文章简介...",
"author": "作者名",
"coverImage": "封面图片URL",
"content": "<p>HTML格式的文章内容...</p>"
}
posts目录.mdMIT License - 详见 LICENSE 文件。
欢迎提交Issue和Pull Request来改进这个项目!