mirror of
https://github.com/gohugoio/hugo.git
synced 2026-09-02 03:32:38 +00:00
Make first round of cleanup for content organization page
This commit is contained in:
@@ -135,14 +135,14 @@ A content's `slug` is either `name.extension` or `name/`. `slug` is determined b
|
||||
* the name of the content file (e.g., `content-name.md`)
|
||||
* front matter overrides
|
||||
|
||||
## `path`
|
||||
#### `path`
|
||||
|
||||
A content's `path` is determined by the section's path to the file. `path`
|
||||
|
||||
* is based on the path to the content's location
|
||||
* excludes the slug
|
||||
|
||||
## `url`
|
||||
#### `url`
|
||||
|
||||
The `url` is the relative URL for the piece of content. The `url`
|
||||
|
||||
@@ -153,13 +153,13 @@ The `url` is the relative URL for the piece of content. The `url`
|
||||
|
||||
As of version v0.18, Hugo now treats "[everything as a page](http://bepsays.com/en/2016/12/19/hugo-018/)". This allows you to add content and front matter to any page, including list pages like [sections][sectiontemplates], [taxonomy list pages][taxonomytemplates], [taxonomy terms pages](/templates/terms/) and even to potential "special case" pages like the [homepage][].
|
||||
|
||||
In order to take advantage of this behaviour you need to do a few things.
|
||||
In order to take advantage of this behavior, you need to do a few things.
|
||||
|
||||
1. Create an \_index.md file that contains the front matter and content you would like to apply.
|
||||
1. Create an `_index.md` file that contains the front matter and content you would like to apply.
|
||||
|
||||
2. Place the \_index.md file in the correct place in the [directory structure][].
|
||||
2. Place the `_index.md` file in the correct place in the directory structure.
|
||||
|
||||
3. Ensure that the respective template is configured to display `{{ .Content }}` if you wish for the content of the \_index.md file to be rendered on the respective page.
|
||||
3. Ensure that the respective template is configured to display `{{ .Content }}` if you wish for the content of the `_index.md` file to be rendered on the respective page.
|
||||
|
||||
### How `_index.md` Works
|
||||
|
||||
@@ -176,14 +176,17 @@ Now that you've got a handle on templates lets recap some Hugo basics to underst
|
||||
|
||||
1. Sections and Taxonomies are 'List' pages, NOT single pages.
|
||||
2. List pages are rendered using the template heirarchy found in the [Content - List Template](http://localhost:1313/templates/list/) docs.
|
||||
3. The Homepage, though technically a List page, can have [it's own template](/templates/homepage/) at layouts/index.html rather than \_default/list.html. Many themes exploit this behaviour so you are likely to encounter this specific use case.
|
||||
4. Taxonomy terms pages are 'lists of metadata' not lists of content, so [have their own templates](/templates/terms/).
|
||||
3. The homepage, though technically a list page, can have [it's own template](/templates/homepage/) at layouts/index.html rather than \_default/list.html. Many themes exploit this behavior so you are likely to encounter this specific use case.
|
||||
4. Taxonomy terms pages are "lists of metadata" and not lists of content and therefore [have their own templates](/templates/terms/).
|
||||
|
||||
Let's put all this information together:
|
||||
|
||||
* `_index.md` file are used in List pages, terms pages or the homepage and are NOT rendered as single pages or with [single page templates][singles].
|
||||
* `_index.md` files are used in list pages, terms pages, or the homepage and are *not* rendered as single pages or with [single page templates][singles].
|
||||
|
||||
{{% note %}}
|
||||
All pages, including List pages, can have front matter and front matter can have markdown content. Thus, `_index.md` files are the way to _provide_ front matter *and* content to the respective list, terms, and homepage templates.
|
||||
{{% /note %}}
|
||||
|
||||
> **All pages, including List pages, can have front matter and front matter can have markdown content - meaning \_index.md files are the way to _provide_ front matter and content to the respective List/Terms/Homepage.**
|
||||
|
||||
Here are a couple of examples to make it clearer...
|
||||
|
||||
@@ -194,11 +197,11 @@ Here are a couple of examples to make it clearer...
|
||||
| /content/categories/hugo/\_index.md | site.com/categories/hugo/ | /layouts/taxonomy/hugo.html |
|
||||
```
|
||||
|
||||
## Why `_index.md files are used`
|
||||
### Why `_index.md` Files are Used
|
||||
|
||||
With a Single page such as a post it's possible to add the front matter and content directly into the .md page itself. With List/Terms/Homepages this is not possible so \_index.md files can be used to provide that front matter/content to them.
|
||||
|
||||
## How to display content from \_index.md files
|
||||
### How to Display Content From `_index.md`
|
||||
|
||||
From the information above it should follow that content within an \_index.md file won't be rendered in its own Single Page, instead it'll be made available to the respective list, terms, Homepage.
|
||||
|
||||
@@ -230,7 +233,7 @@ A very simple example is shown in the following default section list page:
|
||||
|
||||
You can see `{{ .Content }}` just after the `<main>` element. For this particular example, the content of the \_index.md file will show before the main list of summaries.
|
||||
|
||||
## Where to Organize `_index.md` Files
|
||||
### Where to Organize `_index.md` Files
|
||||
|
||||
To add content and front matter to the homepage, a section, a taxonomy or a taxonomy terms listing, add a markdown file with the base name \_index on the relevant place on the file system.
|
||||
|
||||
@@ -250,13 +253,13 @@ To add content and front matter to the homepage, a section, a taxonomy or a taxo
|
||||
└── _index.md
|
||||
```
|
||||
|
||||
In the above example, `_index.md, pages have been added to each section and taxonomy.
|
||||
In the above example, `_index.md` pages have been added to each section and taxonomy.
|
||||
|
||||
An `_index.md` file has also been added in the top level 'content' directory.
|
||||
|
||||
### Where to place `_index.md` for the Homepage Template
|
||||
### Where to Place `_index.md` for the Homepage Template
|
||||
|
||||
Hugo themes are designed to use the 'content' directory as the root of the website, so adding an \_index.md file here (like has been done in the example above) is how you would add front matter/content to the homepage.
|
||||
Hugo themes are designed to use the 'content' directory as the root of the website, so adding an `_index.md` file here (like has been done in the example above) is how you would add front matter and content to the homepage.
|
||||
|
||||
[front matter]: /content-management/front-matter/
|
||||
[homepage]: /templates/homepage/
|
||||
|
||||
@@ -8,19 +8,17 @@ publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
tags: [dates,time]
|
||||
categories: [functions]
|
||||
toc:
|
||||
signature:
|
||||
workson: []
|
||||
hugoversion:
|
||||
relatedfuncs: []
|
||||
deprecated: false
|
||||
draft: false
|
||||
aliases: []
|
||||
---
|
||||
|
||||
`Unix` returns t as a Unix time; i.e., the number of seconds elapsed since January 1, 1970 UTC.
|
||||
|
||||
## `Unix` Example: Show Only Upcoming Events
|
||||
## `Unix` Example 1: Show Only Upcoming Events
|
||||
|
||||
The following assumes you have a content section called `events` (i.e., `content/events/*.md`). The following [partial template][] allows you to only list events that haven't occurred yet.
|
||||
|
||||
@@ -42,4 +40,22 @@ The following assumes you have a content section called `events` (i.e., `content
|
||||
```
|
||||
{{% /code %}}
|
||||
|
||||
## `Unix` Example 2: Days Passed Since Last Modification
|
||||
|
||||
This very simple one-liner uses `Unix` with `Now` to calculate the amount of time that has passed between the `.LastMod` for the current page and the last build of the current page.
|
||||
|
||||
{{% code file="time-passed.html" %}}
|
||||
```golang
|
||||
{{ div (sub .Now.Unix .Lastmod.Unix) 86400 }}
|
||||
```
|
||||
{{% /code %}}
|
||||
|
||||
Since both values are integers, they can be subtracted and then divided by the number of seconds in a day (i.e., `60 * 60 * 24 == 86400`).
|
||||
|
||||
{{% note %}}
|
||||
Adding a value like the preceding example to your Hugo website only provides value if you update every day. Hugo's output is *static*, so a month-old page published on a static website that only publishes monthly could easily be misrepresented as updated *yesterday* rather than 30 days ago.
|
||||
{{% /note %}}
|
||||
|
||||
|
||||
|
||||
[partial template]: /templates/partials/
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="content-header-links">
|
||||
{{- if .Params.godocref -}}
|
||||
<a target="_blank" class="tooltip right godoc-link" data-tooltip="See the related Godocs for {{.Title}}" href="{{.Params.godocref}}" >
|
||||
<a target="_blank" class="tooltip right godoc-link" data-tooltip="See the related Godocs for {{.Title }}" href="{{.Params.godocref}}" >
|
||||
{{ partial "svg-icons/godoc-icon.html" .}}
|
||||
</a>
|
||||
{{- end -}}
|
||||
|
||||
Reference in New Issue
Block a user