2013-08-17 08:34:25 -04:00
|
|
|
---
|
2013-10-31 09:51:13 -04:00
|
|
|
title: "Example Index - Category"
|
2013-08-17 08:34:25 -04:00
|
|
|
date: "2013-07-01"
|
2013-10-26 02:18:14 -04:00
|
|
|
linktitle: "Example - Categories"
|
2013-10-31 09:51:13 -04:00
|
|
|
aliases: ["/extras/indexes/category"]
|
|
|
|
groups: ["indexes"]
|
|
|
|
groups_weight: 60
|
2013-08-17 08:34:25 -04:00
|
|
|
---
|
|
|
|
|
2013-10-31 09:51:13 -04:00
|
|
|
This page demonstrates what would be required to add a new index called "categories" to your site.
|
2013-08-17 08:34:25 -04:00
|
|
|
|
|
|
|
### config.yaml
|
|
|
|
First step is to define the index in your config file.
|
|
|
|
*Because we use both the singular and plural name of the index in our rendering it's
|
|
|
|
important to provide both here. We require this, rather than using inflection in
|
|
|
|
effort to support as many languages as possible.*
|
|
|
|
|
2014-01-10 21:19:19 -05:00
|
|
|
{{% highlight yaml %}}
|
|
|
|
---
|
|
|
|
indexes:
|
|
|
|
category: "categories"
|
|
|
|
baseurl: "http://spf13.com/"
|
|
|
|
title: "Steve Francia is spf13.com"
|
|
|
|
---
|
|
|
|
{{% /highlight %}}
|
2013-08-17 08:34:25 -04:00
|
|
|
|
|
|
|
### /layouts/indexes/category.html
|
|
|
|
|
|
|
|
For each index type a template needs to be provided to render the index page.
|
2014-01-10 21:19:19 -05:00
|
|
|
In the case of categories, this will render the content for /categories/`CATEGORYNAME`/.
|
2013-08-17 08:34:25 -04:00
|
|
|
|
2014-01-10 21:19:19 -05:00
|
|
|
{{% highlight html %}}
|
|
|
|
{{ template "chrome/header.html" . }}
|
|
|
|
{{ template "chrome/subheader.html" . }}
|
2013-08-17 08:34:25 -04:00
|
|
|
|
2014-01-10 21:19:19 -05:00
|
|
|
<section id="main">
|
|
|
|
<div>
|
|
|
|
<h1 id="title">{{ .Title }}</h1>
|
|
|
|
{{ range .Data.Pages }}
|
|
|
|
{{ .Render "summary"}}
|
|
|
|
{{ end }}
|
|
|
|
</div>
|
|
|
|
</section>
|
2013-08-17 08:34:25 -04:00
|
|
|
|
2014-01-10 21:19:19 -05:00
|
|
|
{{ template "chrome/footer.html" }}
|
|
|
|
{{% /highlight %}}
|
2013-08-17 08:34:25 -04:00
|
|
|
|
|
|
|
|
|
|
|
### Assigning indexes to content
|
|
|
|
|
|
|
|
Make sure that the index is set in the front matter:
|
|
|
|
|
2014-01-10 21:19:19 -05:00
|
|
|
{{% highlight json %}}
|
|
|
|
{
|
|
|
|
"title": "Hugo: A fast and flexible static site generator",
|
|
|
|
"categories": [
|
|
|
|
"Development",
|
|
|
|
"golang",
|
|
|
|
"Blogging"
|
|
|
|
],
|
|
|
|
"slug": "hugo"
|
|
|
|
}
|
|
|
|
{{% /highlight %}}
|
2013-08-17 08:34:25 -04:00
|
|
|
|