在默认的 JBake 配置下,首页会完整展示 type=post 页面的内容(即全文),而不仅仅是标题。
这个行为主要由你使用的**模板(index.ftl)**决定。
默认行为分析
JBake 的标准示例模板中,index.ftl 通常会这样遍历文章:
<#list posts as post>
<h2><a href="${post.uri}">${post.title}</a></h2>
<p>${post.date?string("yyyy-MM-dd")}</p>
${post.body} <#-- 这行会输出全文 -->
</#list>
${post.body} 会输出文章的完整内容,所以首页会显示全文。
如何让首页只显示摘要?
方法一:使用 summary 元数据(推荐)
在文章头部添加 summary 字段:
title=我的文章
type=post
date=2026-08-01
tags=Java
status=published
summary=这是文章的简短摘要,只会在首页显示这部分内容。
这里是文章的完整正文...
然后修改 `index.ftl`:
```freemarker
<#list posts as post>
<h2><a href="${post.uri}">${post.title}</a></h2>
<p>${post.date?string("yyyy-MM-dd")}</p>
<#if post.summary??>
<p>${post.summary}</p>
<#else>
<p>${post.body?substring(0, 100)}...</p> <#-- 如果没有摘要,截取前100个字符 -->
</#if>
<a href="${post.uri}">阅读全文 →</a>
</#list>
方法二:截取正文前 N 个字符
在 index.ftl 中使用 Freemarker 的 substring 方法:
<#list posts as post>
<h2><a href="${post.uri}">${post.title}</a></h2>
<p>${post.date?string("yyyy-MM-dd")}</p>
<p>${post.body?substring(0, 150)}...</p>
<a href="${post.uri}">阅读全文 →</a>
</#list>
⚠️ 注意: substring 方法对中文可能不友好(截断时可能乱码),推荐用 summary 方式。
方法三:使用 <!-- more --> 标签(如果模板支持)
有些模板支持在正文中插入 <!-- more --> 来分割摘要和全文:
---
title=我的文章
type=post
date=2026-08-01
status=published
---
这是文章的摘要部分,会显示在首页。
<!-- more -->
这是文章的完整正文,只有在点击"阅读全文"后才显示。
但这需要模板显式支持(如通过 <#if post.body?contains("<!-- more -->")> 来处理)。
如何让首页只显示标题?
如果希望首页只显示文章标题列表,修改 index.ftl:
<#list posts as post>
<li>
<a href="${post.uri}">${post.title}</a>
<span>${post.date?string("yyyy-MM-dd")}</span>
</li>
</#list>
总结
| 首页显示方式 | 需要的配置 | 修改位置 |
|---|---|---|
| 显示全文 | 默认 | 无需修改 |
| 显示摘要 | 使用 summary 字段 | index.ftl |
| 只显示标题 | 仅输出 title 和 date | index.ftl |
最简单推荐: 使用 summary 方法,既保留了首页的简洁,又能控制展示内容,对中文也友好。