From cd4613d84a4d8f15214143e4ac05a73387108235 Mon Sep 17 00:00:00 2001 From: Ryan Watters Date: Mon, 27 Feb 2017 01:08:27 -0600 Subject: [PATCH] Make first round of cleanup for content organization page --- content/content-management/organization.md | 35 ++++++++++--------- content/functions/unix.md | 22 ++++++++++-- .../partials/content-header-links.html | 2 +- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/content/content-management/organization.md b/content/content-management/organization.md index 8aa5642e1..a352a194e 100644 --- a/content/content-management/organization.md +++ b/content/content-management/organization.md @@ -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 `
` 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/ diff --git a/content/functions/unix.md b/content/functions/unix.md index 7213610d8..4561baa06 100644 --- a/content/functions/unix.md +++ b/content/functions/unix.md @@ -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/ \ No newline at end of file diff --git a/themes/hugodocs/layouts/partials/content-header-links.html b/themes/hugodocs/layouts/partials/content-header-links.html index 11b039207..e5ee15a69 100644 --- a/themes/hugodocs/layouts/partials/content-header-links.html +++ b/themes/hugodocs/layouts/partials/content-header-links.html @@ -1,6 +1,6 @@