Skip to content

Commit

Permalink
Merge commit 'c0290655825e7bb36e13fb39f89d85b392cf1adc'
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Mar 11, 2018
2 parents 68bf151 + c029065 commit 95d6200
Show file tree
Hide file tree
Showing 88 changed files with 506 additions and 547 deletions.
6 changes: 6 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Note that this repository contains solely the documentation for Hugo. For contri

*Pull requests shall **only** contain changes to the actual documentation. However, changes on the code base of Hugo **and** the documentation shall be a single, atomic pull request in the [hugo](https://github.com/gohugoio/hugo) repository.*

Spelling fixes are most welcomed, and if you want to contribute longer sections to the documentation, it would be great if you had these in mind when writing:

* Short is good. People go to the library to read novels. If there is more than one way to _do a thing_ in Hugo, describe the current _best practice_ (avoid "… but you can also do …" and "… in older versions of Hugo you had to …".
* For examples, try to find short snippets that teaches people about the concept. If the example is also useful as-is (copy and paste), then great, but don't list long and similar examples just so people can use them on their sites.
* Hugo has users from all over the world, so an easy to understand and [simple English](https://simple.wikipedia.org/wiki/Basic_English) is good.

## Branches

* The `master` branch is where the site is automatically built from, and is the place to put changes relevant to the current Hugo version.
Expand Down
171 changes: 27 additions & 144 deletions docs/content/content-management/archetypes.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
title: Archetypes
linktitle: Archetypes
description: Archetypes allow you to create new instances of content types and set default parameters from the command line.
description: Archetypes are templates used when creating new content.
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
keywords: [archetypes,generators,metadata,front matter]
categories: ["content management"]
menu:
Expand All @@ -18,175 +17,59 @@ aliases: [/content/archetypes/]
toc: true
---

{{% note %}}
This section is outdated, see https://github.com/gohugoio/hugoDocs/issues/11
{{% /note %}}
{{% todo %}}
See above
{{% /todo %}}

## 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.

{{< youtube bcme8AzVh6o >}}

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:
**Archetypes** are content template files in the [archetypes directory][] of your project that contain preconfigured [front matter][] and possibly also a content disposition for your website's [content types][]. These will be used when you run `hugo new`.

```
hugo new <content-section>/<file-name.md>
```

We can use this pattern to create a new `.md` file in the `posts` section:
The `hugo new` uses the `content-section` to find the most suitable archetype template in your project. If your project does not contain any archetype files, it will also look in the theme.

{{< code file="archetype-example.sh" >}}
hugo new posts/my-first-post.md
{{< /code >}}

{{% note "Override Content Type in a New File" %}}
To override the content type Hugo infers from `[content-section]`, add the `--kind` flag to the end of the `hugo new` command.
{{% /note %}}

Running this command in a new site that does not have default or custom archetypes will create the following file:

{{< output file="content/posts/my-first-post.md" >}}
+++
date = "2017-02-01T19:20:04-07:00"
title = "my first post"
draft = true
+++
{{< /output >}}

{{% 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 %}}

The auto-populated fields are worth examining:

* `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 Go's [`now()`][] function, which returns the current time.
* The third variable, `draft = true`, is *not* inherited by your default or custom archetypes but is included in Hugo's automatically scaffolded `default.md` 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][lookup] in your `layouts` directory, Hugo looks for a section- or type-specific archetype, then a default archetype, and finally an internal archetype that ships with Hugo. For example, Hugo will look for an archetype for `content/posts/my-first-post.md` in the following order:
The above will create a new content file in `content/posts/my-first-post.md` using the first archetype file found of these:

1. `archetypes/posts.md`
2. `archetypes/default.md`
3. `themes/<THEME>/archetypes/posts.md`
4. `themes/<THEME>/archetypes/default.md` (Auto-generated with `hugo new site`)

{{% note "Using a Theme Archetype" %}}
If you wish to use archetypes that ship with a theme, the `theme` field must be specified in your [configuration file](/getting-started/configuration/).
{{% /note %}}

## Choose Your Archetype's Front Matter Format

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`.

## Default Archetypes

Default archetypes are convenient if your content's front matter stays consistent across multiple [content sections][sections].
3. `themes/my-theme/posts.md`
4. `themes/my-theme/default.md`

### Create the Default Archetype
The last two list items is only applicable if you use a theme and it uses the `my-theme` theme name as an example.

When you create a new Hugo project using `hugo new site`, you'll notice that Hugo has already scaffolded a file at `archetypes/default.md`.
## Create a New Archetype Template

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.
A fictional example for the section `newsletter` and the archetype file `archetypes/newsletter.md`. Create a new file in `archetypes/newsletter.md` and open it in a text editor.

{{< code file="archetypes/default.md" >}}
+++
tags = ["golang", "hugo"]
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 the [troubleshooting article on EOF errors](/troubleshooting/eof-error/) for more information.)
{{% /warning %}}

### Use the Default Archetype

With an `archetypes/default.md` in place, we can use the CLI to create a new post in the `posts` content section:

{{< code file="new-post-from-default.sh" >}}
$ hugo new posts/my-new-post.md
{{< /code >}}

Hugo then creates a new markdown file with the following front matter:

{{< output file="content/posts/my-new-post.md" >}}
+++
categories = ["web development"]
date = "2017-02-01T19:20:04-07:00"
tags = ["golang", "hugo"]
title = "my new post"
+++
{{< /output >}}

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 respect the order of the key-values specified in your archetype files. This is a [known issue](https://github.com/gohugoio/hugo/issues/452).
{{% /note %}}

## Custom Archetypes

Suppose your site's `posts` section requires more sophisticated front matter than what has been specified in `archetypes/default.md`. You can create a custom archetype for your posts at `archetypes/posts.md` that includes the full set of front matter to be added to the two default archetypes fields.

### Create a Custom Archetype

{{< code file="archetypes/posts.md">}}
+++
description = ""
tags = ""
categories = ""
+++
{{< /code >}}
{{< code file="archetypes/newsletter.md" >}}
---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---

### Use a Custom Archetype
**Insert Lead paragraph here.**

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:
## New Cool Posts

{{< code file="new-post-from-custom.sh" >}}
$ hugo new posts/post-from-custom.md
{{ range first 10 ( where .Site.RegularPages "Type" "cool" ) }}
* {{ .Title }}
{{ end }}
{{< /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`:
When you create a new newsletter with:

{{< output file="content/posts/post-from-custom-archetype.md" >}}
+++
categories = ""
date = 2017-02-13T17:24:43-08:00
description = ""
tags = ""
title = "post from custom archetype"
+++
{{< /output >}}
```bash
hugo new newsletter/the-latest-cool.stuff.md
```

### Hugo Docs Custom Archetype
It will create a new newsletter type of content file based on the archetype template.

As an example of archetypes in practice, the following is the `functions` archetype from the Hugo docs:
**Note:** the site will only be built if the `.Site` is in use in the archetype file, and this can be time consuming for big sites.

{{< code file="archetypes/functions.md" >}}
{{< readfile file="/archetypes/functions.md" >}}
{{< /code >}}
The above _newsletter type archetype_ illustrates the possibilities: The full Hugo `.Site` and all of Hugo&#39;s template funcs can be used in the archetype file.

{{% note %}}
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/files/).
{{% /note %}}

[archetypes directory]: /getting-started/directory-structure/
[`now()`]: http://golang.org/pkg/time/#Now
[configuration file]: /getting-started/configuration/
[sections]: /content-management/sections/
[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/
[lookup]: /templates/lookup/
[templates]: /templates/
14 changes: 14 additions & 0 deletions docs/content/content-management/cross-references.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,22 @@ Ensuring heading uniqueness across the site is accomplished with a unique identi
/content-management/cross-references/#hugo-heading-anchors:77cd9ea530577debf4ce0f28c8dca242
```

### Manually Specifying Anchors

For Markdown content files, if the `headerIds` [Blackfriday extension][bfext] is
enabled (which it is by default), user can manually specify the anchor for any
heading.

Few examples:

```
## Alpha 101 {#alpha}
## Version 1.0 {#version-1-dot-0}
```

[built-in Hugo shortcodes]: /content-management/shortcodes/#using-the-built-in-shortcodes
[lists]: /templates/lists/
[output formats]: /templates/output-formats/
[shortcode]: /content-management/shortcodes/
[bfext]: /content-management/formats/#blackfriday-extensions
4 changes: 2 additions & 2 deletions docs/content/content-management/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ See [Shortcodes][sc] for usage, particularly for the built-in shortcodes that sh

### Code Blocks

Hugo supports GitHub-flavored markdown's use of triple back ticks, as well as provides a special [`highlight` nested shortcode][hlsc] to render syntax highlighting via [Pygments][]. For usage examples and a complete explanation, see the [syntax highlighting documentation][hl] in [developer tools][].
Hugo supports GitHub-flavored markdown's use of triple back ticks, as well as provides a special [`highlight` shortcode][hlsc], and syntax highlights those code blocks natively using *Chroma*. Users also have an option to use *Pygments* instead. See the [Syntax Highlighting][hl] section for details.

## Mmark

Expand Down Expand Up @@ -231,7 +231,7 @@ Markdown syntax is simple enough to learn in a single sitting. The following are
[fireball]: https://daringfireball.net/projects/markdown/
[gfmtasks]: https://guides.github.com/features/mastering-markdown/#syntax
[helperssource]: https://github.com/gohugoio/hugo/blob/77c60a3440806067109347d04eb5368b65ea0fe8/helpers/general.go#L65
[hl]: /tools/syntax-highlighting/
[hl]: /content-management/syntax-highlighting/
[hlsc]: /content-management/shortcodes/#highlight
[hugocss]: /css/style.css
[ietf]: https://tools.ietf.org/html/
Expand Down
22 changes: 10 additions & 12 deletions docs/content/content-management/menus.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,17 @@ Here’s an example snippet pulled from a `config.toml`:
Here's the equivalent snippet in a `config.yaml`:

{{< code file="config.yml" >}}
---
menu:
docs:
- Name: "about hugo"
Pre: "<i class='fa fa-heart'></i>"
Weight: -110
Identifier: "about"
URL: "/about/"
- Name: "getting started"
Pre: "<i class='fa fa-road'></i>"
Weight: -100
URL: "/getting-started/"
---
main:
- name: "about hugo"
pre: "<i class='fa fa-heart'></i>"
weight: -110
identifier: "about"
url: "/about/"
- name: "getting started"
pre: "<i class='fa fa-road'></i>"
weight: -100
url: "/getting-started/"
{{< /code >}}

{{% note %}}
Expand Down
24 changes: 6 additions & 18 deletions docs/content/content-management/page-bundles.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ lastmod : 2018-01-28T22:26:40-05:00
linktitle : "Page Bundles"
keywords : ["page", "bundle", "leaf", "branch"]
categories : ["content management"]
draft : true
toc : true
menu :
docs:
Expand All @@ -15,19 +14,16 @@ menu :
weight : 11
---

Page Bundles are a way to organize the content files. It's useful for
cases where a page or section's content needs to be split into
multiple content pages for convenience or has associated attachments
like documents or images.
Page Bundles are a way to group [Page Resources](/content-management/page-resources/).

A Page Bundle can be one of two types:
A Page Bundle can be one of:

- Leaf Bundle
- Branch Bundle
- Leaf Bundle (leaf means it has no children)
- Branch Bundle (home page, section, taxonomy terms, taxonomy list)

| | Leaf Bundle | Branch Bundle |
|-----------------|--------------------------------------------------------|---------------------------------------------------------|
| Usage | Collection of content and attachments for single pages | Collection of content and attachments for section pages |
| Usage           | Collection of resources (pages, images etc.) for single pages | Collection of non-page resources (images etc.)for list pages |
| Index file name | `index.md` [^fn:1] | `_index.md` [^fn:1] |
| Layout type | `single` | `list` |
| Nesting | Doesn't allow nesting of more bundles under it | Allows nesting of leaf/branch bundles under it |
Expand All @@ -37,15 +33,7 @@ A Page Bundle can be one of two types:
## Leaf Bundles {#leaf-bundles}

A _Leaf Bundle_ is a directory at any hierarchy within the `content/`
directory, that contains at least an **`index.md`** file.

{{% note %}}
Here `md` (markdown) is used just as an example. You can use any file
type as a content resource as long as it is a MIME type recognized by
Hugo (`json` files will, as one example, work fine). If you want to
get exotic, you can define your own media type.
{{% /note %}}

directory, that contains an **`index.md`** file.

### Examples of Leaf Bundle organization {#examples-of-leaf-bundle-organization}

Expand Down
4 changes: 2 additions & 2 deletions docs/content/content-management/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ 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 `event` and should render using the `birthday` layout.
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 `event` and should render using the `birthday` layout.

### Create a Type Layout Directory

Expand Down Expand Up @@ -96,4 +96,4 @@ Read [Archetypes][archetypes] for more information on archetype usage with `hugo
[sectiontemplates]: /templates/section-templates/
[sections]: /content-management/sections/
[template]: /templates/
[Tumblr]: https://www.tumblr.com/
[Tumblr]: https://www.tumblr.com/
7 changes: 2 additions & 5 deletions docs/content/functions/format.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: .Format
description: Formats built-in Hugo dates---`.Date`, `.PublishDate`, and `.LastMod`---according to Go's layout string.
description: Formats built-in Hugo dates---`.Date`, `.PublishDate`, and `.Lastmod`---according to Go's layout string.
godocref: https://golang.org/pkg/time/#example_Time_Format
date: 2017-02-01
publishdate: 2017-02-01
Expand All @@ -23,7 +23,7 @@ toc: true

* `.PublishDate`
* `.Date`
* `.LastMod`
* `.Lastmod`

Assuming a key-value of `date: 2017-03-03` in a content file's front matter, your can run the date through `.Format` followed by a layout string for your desired output at build time:

Expand Down Expand Up @@ -69,9 +69,6 @@ date: 2017-03-03T14:15:59-06:00
`"Mon Jan 2 2006"`
: **Returns**: `Fri Mar 3 2017`

`"January 2nd"`
: **Returns**: `March 3rd`

`"January 2006"`
: **Returns**: `March 2017`

Expand Down
2 changes: 1 addition & 1 deletion docs/content/functions/index-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pop_city = 658390
pop_metro = 1717900
```

The example we will use will be an article on Oslo, which front matter should set to exactly the same name as the corresponding file name in `data/locations/`:
The example we will use will be an article on Oslo, whose front matter should be set to exactly the same name as the corresponding file name in `data/locations/`:

```
title = "My Norwegian Vacation"
Expand Down
Loading

0 comments on commit 95d6200

Please sign in to comment.