Debian Codegraph @

docs/content/en/configuration/media-types.md

raw
1 ---
2 title: Configure media types
3 linkTitle: Media types
4 description: Configure media types.
5 categories: []
6 keywords: []
7 ---
8
9 {{% glossary-term "media type" %}}
10
11 Configured media types serve multiple purposes in Hugo, including the definition of [output formats](g). This is the default media type configuration in tabular form:
12
13 {{< datatable "config" "mediaTypes" "_key" "suffixes" >}}
14
15 The `suffixes` column in the table above shows the suffixes associated with each media type. For example, Hugo associates `.html` and `.htm` files with the `text/html` media type.
16
17 > [!NOTE]
18 > The first suffix is the primary suffix. Use the primary suffix when naming template files. For example, when creating a template for an RSS feed, use the `xml` suffix.
19
20 ## Default configuration
21
22 The following is the default configuration that matches the table above:
23
24 {{< code-toggle file=hugo config=mediaTypes />}}
25
26 `delimiter`
27 : (`string`) The delimiter between the file name and the suffix. The delimiter, in conjunction with the suffix, forms the file extension. Default is `"."`.
28
29 `suffixes`
30 : (`[]string`) The suffixes associated with this media type. The first suffix is the primary suffix.
31
32 ## Modify a media type
33
34 You can modify any of the default media types. For example, to switch the primary suffix for `text/html` from `html` to `htm`:
35
36 {{< code-toggle file=hugo >}}
37 [mediaTypes.'text/html']
38 suffixes = ['htm','html']
39 {{< /code-toggle >}}
40
41 If you alter a default media type, you must also explicitly redefine all output formats that utilize that media type. For example, to ensure the changes above affect the `html` output format, redefine the `html` output format:
42
43 {{< code-toggle file=hugo >}}
44 [outputFormats.html]
45 mediaType = 'text/html'
46 {{< /code-toggle >}}
47
48 ## Create a media type
49
50 You can create new media types as needed. For example, to create a media type for an Atom feed:
51
52 {{< code-toggle file=hugo >}}
53 [mediaTypes.'application/atom+xml']
54 suffixes = ['atom']
55 {{< /code-toggle >}}
56
57 ## Media types without suffixes
58
59 Occasionally, you may need to create a media type without a suffix or delimiter. For example, [Netlify][] recognizes configuration files named `_redirects` and `_headers`, which Hugo can generate using custom [output formats](g).
60
61 To support these custom output formats, register a custom media type with no suffix or delimiter:
62
63 {{< code-toggle file=hugo >}}
64 [mediaTypes.'text/netlify']
65 delimiter = ''
66 {{< /code-toggle >}}
67
68 The custom output format definitions would look something like this:
69
70 {{< code-toggle file=hugo >}}
71 [outputFormats.redir]
72 baseName = '_redirects'
73 isPlainText = true
74 mediatype = 'text/netlify'
75 [outputFormats.headers]
76 baseName = '_headers'
77 isPlainText = true
78 mediatype = 'text/netlify'
79 notAlternative = true
80 {{< /code-toggle >}}
81
82 [Netlify]: https://www.netlify.com/