Home templates
首頁範本是建構網站所需的 唯一 範本,因此對於啟動新網站和範本來說非常有用。如果您正在開發單頁網站,它也是唯一必需的範本。
首頁範本查找順序
請參見 範本查找順序。
為首頁添加內容和 Front Matter
首頁會從 _index.md
檔案中接受內容和 Front Matter。該檔案應位於 content
資料夾的根目錄中(即 content/_index.md
)。然後,您可以像處理任何其他內容檔案一樣,將正文和元數據添加到首頁。
請參閱下面的首頁範本,或參見 內容組織 了解更多有關 _index.md
在為列表頁添加內容和 Front Matter 中的作用。
範例首頁範本
layouts/_default/home.html
{{ define "main" }}
<main aria-role="main">
<header class="home-page-header">
<h1>{{ .Title }}</h1>
{{ with .Params.subtitle }}
<span class="subtitle">{{ . }}</span>
{{ end }}
</header>
<div class="home-page-content">
<!-- 注意,index.html 的內容,作為一種類型的列表頁,會從 content/_index.md 中提取 -->
{{ .Content }}
</div>
<div>
{{ range first 10 .Site.RegularPages }}
{{ .Render "summary" }}
{{ end }}
</div>
</main>
{{ end }}