Welcome to mirror list, hosted at ThFree Co, Russian Federation.

archetypes.md « content « content « docs - github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9004542efb04f21513dba4e3a8567e1e152b1858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
date: 2014-05-14T02:13:50Z
menu:
  main:
    parent: content
next: /content/ordering
prev: /content/types
title: Archetypes
weight: 50
---

Hugo v0.11 introduced the concept of a content builder. Using the
command: `hugo new [relative new content path]` you can start a content file
with the date and title automatically set. This is a welcome feature, but 
active writers need more. 

Hugo presents the concept of archetypes which are archetypal content files.

## Example archetype

In this example scenario I have a blog with a single content type (blog post).
I use ‘tags’ and ‘categories’ for my taxonomies.

### archetypes/default.md

    +++
    tags = ["x", "y"]
    categories = ["x", "y"]
    +++


## using archetypes

If I wanted to create a new post in the `posts` section I would run the following command...

`hugo new posts/my-new-post.md`

Hugo would create the file with the following contents:

### contents/posts/my-new-post.md

    +++
    title = "my new post"
    date = 2014-05-14T02:13:50Z
    tags = ["x", "y"]
    categories = ["x", "y"]
    +++


## Using a different front matter format

By default the front matter will be created in the TOML format
regardless of what format the archetype is using.

You can specify a different default format in your config file using
the `MetaDataFormat` directive. Possible values are `toml`, `yaml` and `json`.


## Which archtype is being used

The following rules apply:

* If an archetype with a filename that matches the content type being created it will be used.
* If no match is found `archetypes/default.md` will be used.
* If neither are present and a theme is in use then within the theme...
    * If an archetype with a filename that matches the content type being created it will be used.
    * If no match is found `archetypes/default.md` will be used.
* If no archetype files are present then the one that ships with hugo will be used.

Hugo provides a simple archetype which sets the title (based on the
file name) and the date based on now().

Content type is automatically detected based on the path. You are welcome to declare which 
type to create using the `--kind` flag during creation.