../../CLAUDE.md > content
内容模块
模块职责
Content 模块负责管理网站的所有内容文件,包括博客文章、静态页面等。该模块遵循 Hugo 的内容管理规范,支持 Markdown 格式和 Front Matter 元数据。
入口与启动
内容创建
使用 Hugo 命令创建新内容:
# 创建新文章
hugo new posts/my-new-post.md
# 创建带日期的文件夹
hugo new posts/2025/my-new-post.md
内容组织
- 文章文件放置在
posts/目录下 - 支持嵌套文件夹结构
- 文件名自动转换为 URL 路径
对外接口
内容路由
- 文章列表:
/posts/ - 单篇文章:
/posts/{文件名}/ - 分类页面:
/categories/ - 标签页面:
/tags/
模板绑定
- 列表页:
themes/port-hugo/layouts/_default/list.html - 单页:
themes/port-hugo/layouts/_default/single.html - 首页:
themes/port-hugo/layouts/index.html
关键依赖与配置
Archetypes (内容模板)
archetypes/default.md: 默认内容模板- 定义文章的 Front Matter 结构
- 包含标题、日期、草稿状态等字段
支持的 Front Matter 字段
---
title: "文章标题" # 文章标题
date: 2025-12-15T12:39:02+08:00 # 创建日期
draft: true # 草稿状态 (true/false)
description: "文章描述" # 文章描述
keywords: ["标签1", "标签2"] # 关键词
categories: ["分类1"] # 分类
tags: ["标签1", "标签2"] # 标签
toc: true # 是否显示目录
---
数据模型
文章文件结构
content/
└── posts/
└── my-first-post.md
示例文章 (my-first-post.md)
---
title: "My First Post"
date: 2025-12-15T12:39:02+08:00
draft: true
---
这是文章内容...
内容格式
- Markdown: 支持标准 Markdown 语法
- Shortcodes: 支持 Hugo Shortcodes
- 模板函数: 可使用 Hugo 模板函数
- 资源引用: 使用 Hugo 的资源处理功能
测试与质量
内容验证
- 检查 Front Matter 格式
- 验证 Markdown 语法
- 测试链接有效性
- 检查图片引用路径
预览测试
# 包含草稿的预览
hugo server -D
# 生产环境预览
hugo server --disableFastRender
SEO 优化
- 确保每篇文章都有描述
- 使用合适的标题层级
- 添加内部链接
- 优化图片 alt 属性
常见问题 (FAQ)
Q: 如何创建草稿?
A: 在 Front Matter 中设置 draft: true,或使用 hugo new posts/draft.md。
Q: 如何设置文章别名?
A: 在 Front Matter 中添加 aliases 字段:
aliases:
- /old-url/
- /another-old-url/
Q: 如何引用图片?
A:
- 将图片放入
static/images/目录 - 在 Markdown 中使用:
 - 或使用 Hugo 的资源功能处理图片
Q: 如何自定义文章模板?
A:
- 在
archetypes/目录创建新的模板 - 在 Front Matter 中指定
archetype字段 - 或在
layouts/_default/中创建自定义模板
相关文件清单
内容文件
posts/my-first-post.md- 示例文章
模板文件
../archetypes/default.md- 默认内容模板../themes/port-hugo/layouts/_default/list.html- 列表页模板../themes/port-hugo/layouts/_default/single.html- 单页模板
配置文件
../hugo.toml- Hugo 主配置../themes/port-hugo/layouts/index.html- 首页模板
变更记录
2025-12-15
- 初始化内容模块
- 创建示例文章文件
- 配置默认内容模板
- 建立内容管理规范
