mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 23:38:53 +00:00
Finalize types page under content organization
This commit is contained in:
@@ -13,4 +13,4 @@ aliases: [/about-hugo/]
|
||||
toc: false
|
||||
---
|
||||
|
||||
Hugo is not just a static site generator: it's a powerful templating engine written in Golang, an enthusiastic community of open-source developers, and, most importantly, it's a tool that allows website creation to be fun again.
|
||||
Hugo is not your average static site generator.
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: Hugo Features
|
||||
linktitle: Hugo Features
|
||||
description: In addition to blistering speed, Hugo also includes robust content management features and a powerful templating language that make it appropriate for websites of all sizes and types.
|
||||
description: Hugo boasts blistering speed, robust content management, and a powerful templating language that make it appropriate for all kinds of static websites.
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
@@ -55,8 +55,8 @@ See what's coming next in the [Hugo roadmap][].
|
||||
[Ace]: /templates/ace-templating/
|
||||
[aliases]: /content-management/urls/#aliases
|
||||
[Amber]: https://github.com/eknkc/amber
|
||||
[content summaries]: /content-management/content-summaries/
|
||||
[content types]: /content-management/content-types/
|
||||
[content summaries]: /content-management/summaries/
|
||||
[content types]: /content-management/types/
|
||||
[Disqus]: https://disqus.com/
|
||||
[Dynamic menu]: /templates/menus/
|
||||
[Extremely fast]: https://github.com/bep/hugo-benchmark
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: Roadmap
|
||||
linktitle: Roadmap
|
||||
description: Take a look at what's in the pipeline for future versions of the Hugo project, as well related GitHub issues and Hugo Forum discussions for new features.
|
||||
description: Take a look at what's in the pipeline for future versions of the Hugo project.
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: What is Hugo
|
||||
linktitle: What is Hugo
|
||||
description: Hugo is the world's fastest static site generator and written in Golang.
|
||||
description: Hugo is a fast and modern static site generator written in Go and designed to make website creation fun again.
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
|
||||
@@ -12,3 +12,5 @@ draft: false
|
||||
aliases: [/content/]
|
||||
toc: false
|
||||
---
|
||||
|
||||
A static site generator needs to extend beyond front matter and a couple templates to be both scalable and *manageable*. Hugo was designed with not only developers in mind, but also content managers and authors.
|
||||
|
||||
@@ -11,14 +11,13 @@ weight: 70
|
||||
draft: false
|
||||
aliases: [/content/archetypes/]
|
||||
toc: true
|
||||
wip: true
|
||||
---
|
||||
|
||||
## What are Archetypes?
|
||||
|
||||
**Archetypes** are content files in the [archetypes directory][] of your project that contain preconfigured [front matter][] for your website's [content types][]. Archetypes facilitate consistent metadata across your website content and allow content authors to quickly generate instances of a content type via the `hugo new` command.
|
||||
|
||||
Hugo's generator assumes your working directory is the content folder at the root of your project. Hugo is able to infer the appropriate archetype by assuming the content type from the content section passed to the CLI command:
|
||||
The `hugo new` generator for archetypes assumes your working directory is the content folder at the root of your project. Hugo is able to infer the appropriate archetype by assuming the content type from the content section passed to the CLI command:
|
||||
|
||||
```bash
|
||||
hugo new [content-section/file-name.md]
|
||||
@@ -42,21 +41,27 @@ Running this command in a new site that does not have default or custom archetyp
|
||||
```toml
|
||||
+++
|
||||
date = "2017-02-01T19:20:04-07:00"
|
||||
title = my first post
|
||||
title = "my first post"
|
||||
draft = true
|
||||
+++
|
||||
```
|
||||
{{% /output %}}
|
||||
|
||||
Note that if you do not already have a `posts` directory, Hugo will create both `content/posts/` and `content/posts/my-first-post.md`.
|
||||
{{% note %}}
|
||||
In this example, if you do not already have a `content/posts` directory, Hugo will create both `content/posts/` and `content/posts/my-first-post.md` for you.
|
||||
{{% /note %}}
|
||||
|
||||
`date` and `title` are the variables that ship with Hugo and are therefore included in *all* content files created with the Hugo CLI. `title` is generated from the new content's filename. `date` is generated in [RFC 3339 format][] by way of Golang's [`now()`][] function, which returns the current time. The third variable, `draft = true` is not carried over into your default archetype but has been added as a convenience to the Hugo's internal/base archetype.
|
||||
The auto-populated fields are worth examining:
|
||||
|
||||
Three variables per content file are often not enough for effective content management of larger websites. Luckily, Hugo provides a simple mechanism for extending the number of variables through default and custom archetypes.
|
||||
* `title` is generated from the new content's filename (i.e. in this case, `my-first-post` becomes `"my first post"`)
|
||||
* `date` and `title` are the variables that ship with Hugo and are therefore included in *all* content files created with the Hugo CLI. `date` is generated in [RFC 3339 format][] by way of Golang's [`now()`][] function, which returns the current time.
|
||||
* The third variable, `draft = true`, is *not* inherited by your default or custom archetypes but is include in Hugo's internal/base archetype for convenience.
|
||||
|
||||
Three variables per content file are often not enough for effective content management of larger websites. Luckily, Hugo provides a simple mechanism for extending the number of variables through custom archetypes, as well as default archetypes to keep content creation DRY.
|
||||
|
||||
## Lookup Order for Archetypes
|
||||
|
||||
Similar to the lookup order for [templates in the `layouts` directory][], Hugo looks for a default file before falling back on the base/internal archetype. For the `my-first-post.md` example, Hugo looks for the new content's archetype file in the following order:
|
||||
Similar to the lookup order for [templates in the `layouts` directory][lookup], Hugo looks for a default file before falling back on the base/internal archetype. For the `my-first-post.md` example, Hugo looks for the new content's archetype file in the following order:
|
||||
|
||||
1. `archetypes/posts.md`
|
||||
2. `archetypes/default.md`
|
||||
@@ -65,12 +70,12 @@ Similar to the lookup order for [templates in the `layouts` directory][], Hugo l
|
||||
5. `_internal` (i.e., `title` and `date`)
|
||||
|
||||
{{% note "Using a Theme Archetype" %}}
|
||||
If you wish to use archetypes that ship with a theme, `theme` must be specified in your [configuration file](/project-organization/configuration/).
|
||||
If you wish to use archetypes that ship with a theme, the `theme` field must be specified in your [configuration file](/project-organization/configuration/).
|
||||
{{% /note %}}
|
||||
|
||||
## Choosing Your Front Matter Format
|
||||
|
||||
By default, `hugo new` content files include front matter in the TOML format regardless of the format used in `archetypes/*md`.
|
||||
By default, `hugo new` content files include front matter in the TOML format regardless of the format used in `archetypes/*.md`.
|
||||
|
||||
You can specify a different default format in your site [configuration file][] file using the `metaDataFormat` directive. Possible values are `toml`, `yaml`, and `json`.
|
||||
|
||||
@@ -80,7 +85,7 @@ Default archetypes are convenient if your content's front matter stays consisten
|
||||
|
||||
### Creating the Default Archetype
|
||||
|
||||
The following examples are from a site using `tags` and `categories` as [taxonomies][]. If we assume that all content files will require these two key-values, we can create a `default.md` archetype that *extends* Hugo's base archetype. In this example, we are including "golang" and "hugo" as tags and "web development" as a category.
|
||||
The following examples are from a site that's using `tags` and `categories` as [taxonomies][]. If we assume that all content files will require these two key-values, we can create a `default.md` archetype that *extends* Hugo's base archetype. In this example, we are including "golang" and "hugo" as tags and "web development" as a category.
|
||||
|
||||
{{% code file="archetypes/default.md" %}}
|
||||
```toml
|
||||
@@ -92,7 +97,7 @@ categories = ["web development"]
|
||||
{{% /code %}}
|
||||
|
||||
{{% warning "EOL Characters in Text Editors"%}}
|
||||
If you get an `EOF error` when using `hugo new`, add a carriage return after the closing `+++` or `---` for your TOML or YAML front matter, respectively. (See [troubleshooting](/troubleshooting/eof-error/).)
|
||||
If you get an `EOF error` when using `hugo new`, add a carriage return after the closing `+++` or `---` for your TOML or YAML front matter, respectively. (See the [troubleshooting article on EOF errors](/troubleshooting/eof-error/) for more information.)
|
||||
{{% /warning %}}
|
||||
|
||||
### Using the Default Archetype
|
||||
@@ -121,7 +126,7 @@ title = "my new post"
|
||||
We see that the `title` and `date` key-values have been added in addition to the `tags` and `categories` key-values from `archetypes/default.md`.
|
||||
|
||||
{{% note "Ordering of Front Matter" %}}
|
||||
You may notice that content files created with `hugo new` do not observe the order of the key-values specified in your archetype files and instead list your front matter alphabetically. This is a [known issue](https://github.com/spf13/hugo/issues/452).
|
||||
You may notice that content files created with `hugo new` do not respect the order of the key-values specified in your archetype files. This is a [known issue](https://github.com/spf13/hugo/issues/452).
|
||||
{{% /note %}}
|
||||
|
||||
## Custom Archetypes
|
||||
@@ -142,7 +147,7 @@ categories = ""
|
||||
|
||||
### Using a Custom Archetype
|
||||
|
||||
With an `archetypes/posts.md` in place, you can use the Hugo CLI to create a new post with your custom `posts` metadata in the `posts` content section:
|
||||
With an `archetypes/posts.md` in place, you can use the Hugo CLI to create a new post with your preconfigured front matter in the `posts` content section:
|
||||
|
||||
{{% code file="new-post-from-custom.sh" %}}
|
||||
```bash
|
||||
@@ -150,16 +155,16 @@ $ hugo new posts/post-from-custom.md
|
||||
```
|
||||
{{% /code %}}
|
||||
|
||||
This time, Hugo recognizes our custom `archetypes/posts.md` archetype and uses it instead of `archetypes/default.md`. The generated file will now include the full list of front matter parameters, as well as the base archetype's `title` and `date`.
|
||||
This time, Hugo recognizes our custom `archetypes/posts.md` archetype and uses it instead of `archetypes/default.md`. The generated file will now include the full list of front matter parameters, as well as the base archetype's `title` and `date`:
|
||||
|
||||
{{% output file="content/posts/post-from-custom.md" %}}
|
||||
{{% output file="content/posts/post-from-custom-archetype.md" %}}
|
||||
```toml
|
||||
+++
|
||||
categories = ""
|
||||
date = 2017-02-13T17:24:43-08:00
|
||||
description = ""
|
||||
tags = ""
|
||||
title = post from custom
|
||||
title = post from custom archetype
|
||||
+++
|
||||
```
|
||||
{{% /output %}}
|
||||
@@ -178,13 +183,13 @@ As an example of archetypes in practice, the following is the `functions` archet
|
||||
The preceding archetype is kept up to date with every Hugo build by using Hugo's [`readFile` function](/functions/readfile/). For similar examples, see [Local File Templates](/templates/local-file-templates/).
|
||||
{{% /note %}}
|
||||
|
||||
[archetypes directory]: /project-organization/directory-structure/
|
||||
[archetypes directory]: /getting-started/directory-structure/
|
||||
[`now()`]: http://golang.org/pkg/time/#Now
|
||||
[configuration file]: /project-organization/configuration/
|
||||
[sections]: /sections/
|
||||
[content types]: /content-management/content-types/
|
||||
[content types]: /content-management/types/
|
||||
[front matter]: /content-management/front-matter/
|
||||
[RFC 3339 format]: https://www.ietf.org/rfc/rfc3339.txt
|
||||
[taxonomies]: /content-management/taxonomies/
|
||||
[templates in the `layouts` directory]: /templates/base/
|
||||
[lookup]: /templates/lookup/
|
||||
[templates]: /templates/
|
||||
@@ -11,14 +11,13 @@ weight: 140
|
||||
draft: false
|
||||
aliases: [/extras/comments/]
|
||||
toc: true
|
||||
wip: true
|
||||
---
|
||||
|
||||
The most common interaction people ask for in static websites is the ability to add comments.
|
||||
|
||||
Hugo ships with support for [Disqus](https://disqus.com/), a third-party service that provides comment and community capabilities to websites via JavaScript.
|
||||
|
||||
Your theme may already support Disqus. If not, it is easy to add.
|
||||
Your theme may already support Disqus, but if not, it is easy to add to your templates via [Hugo's built-in Disqus partial][disquspartial].
|
||||
|
||||
## Adding Disqus
|
||||
|
||||
@@ -26,7 +25,7 @@ Hugo comes with all the code you need to load Disqus into your templates. Before
|
||||
|
||||
### Configuring Disqus
|
||||
|
||||
Disqus comments require you set a single value in your [site's configuration file][configuration]. The following show the configuration variable in TOML and YAML, respectively:
|
||||
Disqus comments require you set a single value in your [site's configuration file][configuration]. The following show the configuration variable in a `config.toml` and `config.yml`, respectively:
|
||||
|
||||
```toml
|
||||
disqusShortname = "yourdiscussshortname"
|
||||
@@ -36,7 +35,7 @@ disqusShortname = "yourdiscussshortname"
|
||||
disqusShortname: "yourdiscussshortname"
|
||||
```
|
||||
|
||||
For many website, this is enough configuration. However, you also have the option to set the following in the [front matter][] of a single content file:
|
||||
For many websites, this is enough configuration. However, you also have the option to set the following in the [front matter][] of a single content file:
|
||||
|
||||
* `disqus_identifier`
|
||||
* `disqus_title`
|
||||
@@ -48,7 +47,7 @@ See [Partial Templates][partials] to learn how to add the Disqus partial to your
|
||||
|
||||
## Commenting Alternatives
|
||||
|
||||
There are a few alternatives to commenting on static sites for those who do not want to use Hugo's built-in Disqus support:
|
||||
There are a few alternatives to commenting on static sites for those who do not want to use Disqus:
|
||||
|
||||
* [Static Man](https://staticman.net/)
|
||||
* [IntenseDebate](http://intensedebate.com/)
|
||||
@@ -59,7 +58,7 @@ There are a few alternatives to commenting on static sites for those who do not
|
||||
* [Tutorial on Implementing Isso with Hugo][issotutorial]
|
||||
|
||||
|
||||
<!-- I don't think this is worth including in the documentation since it seems that Steve is no longer supporting or developing this project. RW.-->
|
||||
<!-- I don't think this is worth including in the documentation since it seems that Steve is no longer supporting or developing this project. rdwatters - 2017-02-29.-->
|
||||
<!-- * [Kaiju](https://github.com/spf13/kaiju) -->
|
||||
|
||||
<!-- ## Kaiju
|
||||
@@ -71,6 +70,7 @@ Written using Go, Socket.io, and [MongoDB][], Kaiju is very fast and easy to dep
|
||||
It is in early development but shows promise. If you have interest, please help by contributing via pull request, [opening an issue in the Kaiju GitHub repository][kaijuissue], or [Tweeting about it][tweet]. Every bit helps. -->
|
||||
|
||||
[configuration]: /getting-started/configuration/
|
||||
[disquspartial]: /templates/partials/#disqus
|
||||
[disqussetup]: https://disqus.com/profile/signup/
|
||||
[forum]: https://discuss.gohugo.io
|
||||
[front matter]: /content-management/front-matter/
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
---
|
||||
title: Content Types
|
||||
linktitle: Content Types
|
||||
description: Hugo provides support for sites with multiple content types and assumes your site will be organized into sections, where each section will use the corresponding type.
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [content management]
|
||||
tags: [lists,sections,content types,types,organization]
|
||||
weight: 60
|
||||
draft: false
|
||||
aliases: [/content/types]
|
||||
toc: true
|
||||
wip: true
|
||||
---
|
||||
|
||||
Hugo provides full support for sites with multiple content types. A **content type** can have a unique set of metadata (i.e., [front matter][]) or customized [template][] and can be created by the `hugo new` command via content [archetypes][].
|
||||
|
||||
{{% note "Hugo Content Type != MIME Type" %}}
|
||||
It's important to distinguish the difference between Hugo's content types and [MIME types](https://en.wikipedia.org/wiki/Media_type). In Hugo, a content type is a piece of information (i.e. content item) that has multiple attributes (i.e. front matter/metadata and a content block). It is not necessarily related to a file format or file extension.
|
||||
{{% /note %}}
|
||||
|
||||
A good example of when multiple types are needed is to look at [Tumblr][]. A piece of "content" could be a photo, quote or post, each with different meta data and rendered differently.
|
||||
|
||||
## Assigning a Content Type
|
||||
|
||||
Hugo assumes that your site will be organized into [sections][] and each section will use the corresponding type. If you are taking advantage of this, then each new piece of content you place into a section will automatically inherit the type.
|
||||
|
||||
Alternatively, you can set the content type in a content file's metadata (i.e., [front matter][]) under the key "`type`".
|
||||
|
||||
## Creating New Content of a Specific Type
|
||||
|
||||
You can manually add files to your content directories, but Hugo has the ability to create and populate a new content file with preconfigured front matter via [archetypes][].
|
||||
|
||||
## Defining a Content Type
|
||||
|
||||
Creating a new content type is easy in Hugo. You simply provide the templates and archetype that the new type will use. You only need to define the templates, archetypes and/or views unique to that content type. Hugo will fall back to using the general templates and default archetype whenever a specific file is not present.
|
||||
|
||||
{{% note "Declaring Content Types" %}}
|
||||
Remember, all of the following are *optional*. If you do not specifically declare content types in your front matter or develop specific layouts for content types, Hugo is smart enough to infer the content type from the file path and content section (see [content sections](/content-management/sections/)).
|
||||
{{% /note %}}
|
||||
|
||||
### Create a Type Layout Directory
|
||||
|
||||
Create a directory with the name of the type in `/layouts`. Type is always singular; e.g., even if your content directory is `content/posts`, create `/layouts/post/`.
|
||||
|
||||
### Create a Single Template
|
||||
|
||||
Create a file called `single.html` inside your directory. *E.g. `/layouts/post/single.html`*.
|
||||
|
||||
### Create a List Template
|
||||
|
||||
Create a file called `post.html` inside the section lists template directory, `/layouts/section`; e.g., `/layouts/section/post.html`.
|
||||
|
||||
### Create views
|
||||
|
||||
Many sites support rendering content in a few different ways, for instance, a single page view and a summary view to be used when displaying a [list of section contents][]. Hugo makes no assumptions about how you want to display your content and will support as many different views of a content type as your site requires. All that is required for these additional views is that a template exists in each `/layouts/TYPE` directory with the same name.
|
||||
|
||||
### Create a Corresponding Archetype
|
||||
|
||||
Create an archetype file for your type at `yourtype.md` in the `/archetypes` directory; e.g., `/archetypes/post.md`.
|
||||
|
||||
More details about archetypes can be found in the [archetypes documentation][].
|
||||
|
||||
[archetypes]: /content-management/archetypes/
|
||||
[archetypes documentation]: /content-management/archetypes/
|
||||
[sections]: /content-management/sections/
|
||||
[front matter]: /content-management/front-matter/
|
||||
[list of section contents]: /templates/section-templates/
|
||||
[template]: /templates/
|
||||
[Tumblr]: https://www.tumblr.com/
|
||||
@@ -124,7 +124,7 @@ See [site configuration][] for more information on setting up global Blackfriday
|
||||
* [JSON Spec][]
|
||||
|
||||
[aliases]: /content-management/urls/#aliases/
|
||||
[content type]: /content-management/content-types/
|
||||
[content type]: /content-management/types/
|
||||
[site configuration]: /project-organization/configuration/ "Hugo documentation for site configuration"
|
||||
[JSON Spec]: /documents/ecma-404-json-spec.pdf "Specification for JSON, JavaScript Object Notation"
|
||||
[TOML Spec]: https://github.com/toml-lang/toml "Specification for TOML, Tom's Obvious Minimal Language"
|
||||
|
||||
@@ -57,7 +57,7 @@ Hugo themes developed before v0.18 often used an `index.md`(i.e., without the le
|
||||
By default, everything created within a section will use the [content type][] that matches the section name. For example, Hugo will assume that `posts/post-1.md` has a `posts` content type. If you are using an [archetype][] for your posts section, Hugo will generate front matter according to what is finds in `archetypes/posts.md`.
|
||||
|
||||
[archetype]: /content-management/archetypes/
|
||||
[content type]: /content-management/content-types/
|
||||
[content type]: /content-management/types/
|
||||
[directory structure]: /getting-started/directory-structure/
|
||||
[section templates]: /templates/section-templates/
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Content Summaries
|
||||
linktitle:
|
||||
linktitle: Summaries
|
||||
description: Hugo can generate summaries of your content to show snippets in summary views. You have the option to split these summaries yourself or let Hugo automatically generate them for you.
|
||||
date: 2017-01-10
|
||||
publishdate: 2017-01-10
|
||||
@@ -9,7 +9,7 @@ categories: [content management]
|
||||
tags: [summaries,abstracts,read more]
|
||||
weight: 90
|
||||
draft: false
|
||||
aliases: [/content/summaries/,/content-management/summaries]
|
||||
aliases: [/content/summaries/,/content-management/content-summaries/]
|
||||
toc: true
|
||||
---
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
---
|
||||
title: Content Types
|
||||
linktitle: Types
|
||||
description: Hugo provides support for sites with multiple content types and assumes your site will be organized into sections, where each section will use the corresponding type.
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [content management]
|
||||
tags: [lists,sections,content types,types,organization]
|
||||
weight: 60
|
||||
draft: false
|
||||
aliases: [/content/types]
|
||||
toc: true
|
||||
---
|
||||
|
||||
Hugo provides full support for sites with multiple content types. A **content type** can have a unique set of metadata (i.e., [front matter][]) or customized [template][] and can be created by the `hugo new` command via [archetypes][].
|
||||
|
||||
{{% note "Hugo Content Type != MIME Type" %}}
|
||||
It's important to distinguish the difference between Hugo's content types and [MIME types](https://en.wikipedia.org/wiki/Media_type). In Hugo, a content type is a piece of information (i.e. a content item) that has multiple attributes---typically front matter followed by a content block---and is *not* necessarily related to a file format or file extension (e.g., `.json`, `.amp.html`).
|
||||
{{% /note %}}
|
||||
|
||||
[Tumblr][] is a good example of a website containing multiple content types. A piece of "content" could be a photo, quote, or a post, each with different sets of metadata and different visual rendering.
|
||||
|
||||
## Assigning a Content Type
|
||||
|
||||
Hugo assumes that your site will be organized into [sections][] and each section will use a corresponding type. This is to reduce the amount of configuration necessary for new Hugo projects.
|
||||
|
||||
If you are taking advantage of this default behavior, each new piece of content you place into a section will automatically inherit the type. Alternatively, you can set the content type in a content file's [front matter][] in the field "`type`".
|
||||
|
||||
## Creating New Content of a Specific Type
|
||||
|
||||
You can manually add files to your content directories, but Hugo has the ability to create and populate a new content file with preconfigured front matter via [archetypes][].
|
||||
|
||||
## Defining a Content Type
|
||||
|
||||
Creating a new content type is easy in Hugo. You simply define and provide the templates and archetype unique to your new content type. Hugo will fall back to using the general templates and default archetype whenever a specific file is not present.
|
||||
|
||||
{{% note "Declaring Content Types" %}}
|
||||
Remember, all of the following are *optional*. If you do not specifically declare content types in your front matter or develop specific layouts for content types, Hugo is smart enough to assume the content type from the file path and content section. (See [Content Sections](/content-management/sections/) for more information.)
|
||||
{{% /note %}}
|
||||
|
||||
The following examples take you stepwise through creating a new type layout for a content file that contains the following front matter:
|
||||
|
||||
{{% code file="content/events/my-first-event.md" copy="false" %}}
|
||||
```toml
|
||||
+++
|
||||
title: My First Event
|
||||
date = "2016-06-24T19:20:04-07:00"
|
||||
description = "Today is my 36th birthday. My how time flies."
|
||||
type = "event"
|
||||
layout = "birthday"
|
||||
+++
|
||||
```
|
||||
{{% /code %}}
|
||||
|
||||
By default, Hugo assumes `*.md` under `events` is of the `events` content type. However, we have specified that this particular file at `content/events/ my-first-event.md` is of type `special` and should render using the `birthday` layout.
|
||||
|
||||
### Create a Type Layout Directory
|
||||
|
||||
Create a directory with the name of the type in `/layouts`. **Type is always singular**; e.g., `events => event` and `posts => post`.
|
||||
|
||||
For the above example, you would create a layout directory at `layouts/event/birthday.html`.
|
||||
|
||||
{{% note %}}
|
||||
If you have multiple content files in your `events` directory that are of the `special` type and you don't want to define the `layout` specifically for each individual, you can create a layout at `layouts/special/single.html` to observe the [single page template lookup order](/templates/single-page-templates/).
|
||||
{{% /note %}}
|
||||
|
||||
{{% warning %}}
|
||||
With the "everything is a page" data model introduced in v0.18 (see [Content Organization](/content-management/organization/)), you can use `_index.md` in content directories to add both content and front matter to [section templates](/templates/section-templates). However, `type` and `layout` declared in the front matter of `_index.md` are *not* currently respected at build time as of v0.19. This is a known issue [(#3005)](https://github.com/spf13/hugo/issues/3005).
|
||||
{{% /warning %}}
|
||||
|
||||
### Create Views
|
||||
|
||||
Many sites support rendering content in a few different ways; e.g., a single page view and a summary view to be used when displaying a [list of section contents][sectiontemplates].
|
||||
|
||||
Hugo limits assumptions about how you want to display your content to an intuitive set of sane defaults and will support as many different views of a content type as your site requires. All that is required for these additional views is that a template exists in each `/layouts/<TYPE>` directory with the same name.
|
||||
|
||||
### Custom Content Type Template Lookup Order
|
||||
|
||||
The lookup order for the `content/events/my-first-event.md` templates would be as follows:
|
||||
|
||||
* `layouts/event/birthday.html`
|
||||
* `layouts/event/single.html`
|
||||
* `layouts/events/single.html`
|
||||
* `layouts/_default/single.html`
|
||||
|
||||
### Create a Corresponding Archetype
|
||||
|
||||
We can then create a custom archetype with preconfigured front matter at `event.md` in the `/archetypes` directory; i.e. `archetypes/event.md`.
|
||||
|
||||
Read [Archetypes][archetypes] for more information on archetype usage with `hugo new`.
|
||||
|
||||
[archetypes]: /content-management/archetypes/
|
||||
[front matter]: /content-management/front-matter/
|
||||
[sectiontemplates]: /templates/section-templates/
|
||||
[sections]: /content-management/sections/
|
||||
[template]: /templates/
|
||||
[Tumblr]: https://www.tumblr.com/
|
||||
@@ -134,5 +134,5 @@ This `li.html` content view template is used for [spf13.com][spf]. ([See source
|
||||
[spfsourceli]: https://github.com/spf13/spf13.com/blob/master/layouts/_default/li.html
|
||||
[spfsourcesection]: https://github.com/spf13/spf13.com/blob/master/layouts/_default/section.html
|
||||
[spfsourcesummary]: https://github.com/spf13/spf13.com/blob/master/layouts/_default/summary.html
|
||||
[summaries]: /content-management/content-summaries/
|
||||
[summaries]: /content-management/summaries/
|
||||
[taxonomylists]: /templates/taxonomy-templates/
|
||||
@@ -10,7 +10,7 @@ categories: [templates]
|
||||
tags: [lookup,fundamentals]
|
||||
weight: 15
|
||||
draft: false
|
||||
aliases: []
|
||||
aliases: [/templates/lookup/]
|
||||
wip: true
|
||||
---
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ To easily generate new instances of this content type (e.g., new `.md` files in
|
||||
|
||||
[archetypes]: /content-management/archetypes/
|
||||
[config]: /getting-started/configuration/
|
||||
[content type]: /content-management/content-types/
|
||||
[content type]: /content-management/types/
|
||||
[directory structure]: /getting-started/directory-structure/
|
||||
[dry]: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
|
||||
[front matter]: /content-management/front-matter/
|
||||
|
||||
@@ -124,7 +124,7 @@ http://remarkjs.com)
|
||||
: see [Site Variables](/variables/site-variables/).
|
||||
|
||||
`.Summary`
|
||||
: a generated summary of the content for easily showing a snippet in a summary view. The breakpoint can be set manually by inserting <code><!--more--></code> at the appropriate place in the content page. See [Content Summaries](/content-management/content-summaries/) for more details.
|
||||
: a generated summary of the content for easily showing a snippet in a summary view. The breakpoint can be set manually by inserting <code><!--more--></code> at the appropriate place in the content page. See [Content Summaries](/content-management/summaries/) for more details.
|
||||
|
||||
`.TableOfContents`
|
||||
: the rendered [table of contents](/content-management/toc/) for the page.
|
||||
@@ -136,10 +136,10 @@ http://remarkjs.com)
|
||||
: a list of translated versions of the current page. See [Multilingual Mode](/content-management/multilingual/) for more information.
|
||||
|
||||
`.Truncated`
|
||||
: a boolean, `true` if the `.Summary` is truncated. Useful for showing a "Read more..." link only when necessary. See [Summaries](/content-management/content-summaries/) for more information.
|
||||
: a boolean, `true` if the `.Summary` is truncated. Useful for showing a "Read more..." link only when necessary. See [Summaries](/content-management/summaries/) for more information.
|
||||
|
||||
`.Type`
|
||||
: the [content type](/content-management/content-types/) of the content (e.g., `post`).
|
||||
: the [content type](/content-management/types/) of the content (e.g., `post`).
|
||||
|
||||
`.URL`
|
||||
: the relative URL for the page. Note that the `URL` set directly in front
|
||||
|
||||
@@ -41,6 +41,6 @@ docsearch({
|
||||
apiKey: '41fdb7fafd9b009498ef9ab6d3fb1886',
|
||||
indexName: 'hugodocsconcept',
|
||||
inputSelector: '#search-input',
|
||||
debug: true // Set debug to true if you want to inspect the dropdown
|
||||
debug: false // Set debug to true if you want to inspect the dropdown
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user