版本: v1.0 更新日期: 2026-04-03
文章清理功能允许您安全地删除已发布博客的本地文件(Markdown 和资源文件),同时保留数据库记录、平台链接和标签信息。
PublishRecord 表中的所有发布记录tags 字段content/done/ 目录下的 .md 文件currentPath 和 workflowLocationpublished)状态的文章--dry-run)archived# 清理文章
pnpm post:clean <postId>
# 预演模式(不实际删除)
pnpm post:clean <postId> --dry-run
# 预演模式(简写)
pnpm post:clean <postId> -n
# 清理已发布的文章
pnpm post:clean hello-world
# 先预览再清理
pnpm post:clean hello-world --dry-run
pnpm post:clean hello-world
curl -X POST http://localhost:3001/api/posts/<postId>/clean \
-H "Content-Type: application/json" \
-d '{"dryRun": false}'
响应示例:
{
"success": true,
"deletedFiles": [
"/path/to/content/done/hello-world.md",
"/path/to/content/done/assets/image.png"
],
"savedTags": ["javascript", "tutorial"],
"message": "清理完成"
}
publishedcontent/done/ 目录# 1. 检查文章状态
pnpm post:status
# 2. 检查平台链接
pnpm platform:id:status <postId>
# 3. 验证文件位置
ls content/done/<postId>.md
1. 查询文章记录
2. 验证状态是否为 published
3. 检查文件是否存在
1. 读取 Markdown 文件
2. 提取 frontmatter 中的 tags
3. 扫描文章中的资源引用
4. 构建要删除的文件列表
1. 删除 Markdown 文件
2. 删除关联的资源文件
3. 更新数据库:
- 状态 → archived
- tags → JSON 数组
- cleanedAt → 当前时间
- currentPath → null
- workflowLocation → null
1. 确认文件已删除
2. 确认数据库已更新
3. 确认标签已保存
| 字段 | 值 |
|---|---|
status |
published |
currentPath |
/path/to/content/done/post.md |
workflowLocation |
done |
tags |
null |
cleanedAt |
null |
| 字段 | 值 |
|---|---|
status |
archived |
currentPath |
null |
workflowLocation |
null |
tags |
["tag1", "tag2"] |
cleanedAt |
2026-04-03T08:00:00Z |
done 目录恢复文件content/done/assets)PublishRecord 表的记录完整保留PlatformIdMapping 表保留清理后无法直接恢复文件,但可以:
# 1. 从已发布平台复制内容
# 2. 创建新的文章文件
pnpm scan --inject
# 3. 重新发布
pnpm post:publish <newPostId>
# 从平台复制内容后,重置状态
pnpm db-update-status <postId> draft
✅ 定期清理
✅ 归档管理
✅ 测试环境
❌ 可能需要重新编辑
❌ 资源仍在使用
# 发布后等待 1-2 周,确认无需修改
pnpm post:publish <postId>
# 等待...
pnpm post:clean <postId>
# 先预览
pnpm post:clean <postId> --dry-run
# 确认无误后再实际清理
pnpm post:clean <postId>
# 查看已发布 3 个月以上的文章
pnpm post:status | grep "3 months ago"
# 逐个清理
pnpm post:clean <oldPostId>
# 清理前备份到归档目录
mkdir -p content/archived/$(date +%Y%m)
cp content/done/<postId>.md content/archived/$(date +%Y%m)/
# 然后再清理
pnpm post:clean <postId>
错误:只能清理已发布的文章,当前状态: draft
解决:
# 先发布文章
pnpm post:publish <postId>
# 然后再清理
pnpm post:clean <postId>
错误:文件不存在: /path/to/file.md
解决:
# 检查文件位置
ls content/posts/<postId>.md
ls content/done/<postId>.md
# 如果在 posts 目录,先处理工作流
pnpm workflow:process <postId>
问题:清理后标签为空
原因:文章没有 frontmatter 或 tags 字段
解决:
# 清理前先注入 frontmatter
pnpm scan --inject
# 然后再清理
pnpm post:clean <postId>
更新日期: 2026-04-03 版本: v1.0