Do a small language cleanup for output formats page

This commit is contained in:
Ryan Watters 2017-04-10 22:56:27 -05:00
parent 33db41438c
commit 08ff6f6176
3 changed files with 49 additions and 48 deletions

View File

@ -1,6 +1,4 @@
baseurl = "https://hugodocs.info"
buildDrafts = false
buildFuture = false
canonifyurls = true
# Pointing to this file
config = "config.toml"
@ -41,9 +39,6 @@ watch = true
# Add GA Tracking Code Here. This leverages a built-in (ie, "internal") partial from HUGO: https://gohugo.io/extras/analytics#configuring-google-analytics
googleAnalytics = "UA-76549364-1"
[permalinks]
temp = "/:title"
#CUSTOM PARAMS
[params]
## Used for views in rendered HTML (i.e., rather than using the .Hugo variable)

View File

@ -1,6 +1,6 @@
---
title: Custom Output Formats
linktitle: Custom Outputs
linktitle: Output Formats
description: Hugo can output content in multiple formats to make quick work of
date: 2017-03-22
publishdate: 2017-03-22
@ -20,11 +20,11 @@ wip: true
Hugo `0.20` introduced the powerful feature **Custom Output Formats**; Hugo isn't just that "static HTML with an added RSS feed" anymore. _Say hello_ to calendars, e-book formats, Google AMP, and JSON search indexes, to name a few.
This page describes how to properly configure your site with the media types and output formats you need.
This page describes how to properly configure your site with the media types and output formats, as well as where to create your templates for your custom outputs.
## Media Types
A [media type](https://en.wikipedia.org/wiki/Media_type) (also known as MIME type and content type) is a two-part identifier for file formats and format contents transmitted on the Internet.
A [media type][] (also known as *MIME type* and *content type*) is a two-part identifier for file formats and format contents transmitted on the Internet.
This is the full set of built-in media types in Hugo:
@ -32,12 +32,12 @@ This is the full set of built-in media types in Hugo:
**Note:**
* It is possible to add custom media types or change the defaults (if you, say, want to change the suffix to `asp` for `text/html`).
* It is possible to add custom media types or change the defaults; e.g., if want to change the suffix for `text/html` to `asp`.
* The `Suffix` is the value that will be used for URLs and filenames for that media type in Hugo.
* The `Type` is the identifier that must be used when defining new `Output Formats` (see below).
* The `Type` is the identifier that must be used when defining new/custom `Output Formats` (see below).
* The full set of media types will be registered in Hugo's built-in development server to make sure they are recognized by the browser.
To add or modify a media type, define it in a `mediaTypes` section in your site config (either for all sites or for a given language).
To add or modify a media type, define it in a `mediaTypes` section in your [site configuration][config], either for all sites or for a given language.
Example in `config.toml`:
@ -53,21 +53,17 @@ The above example adds one new media type, `text/enriched`, and changes the suff
## Output Formats
Given a media type and some additional configuration, you get an `Output Format`.
Given a media type and some additional configuration, you get an `Output Format`:
This is the full set of built-in output formats in Hugo:
This is the full set of Hugo's built-in output formats:
{{< datatable "output" "formats" "Name" "MediaType" "Path" "BaseName" "Rel" "Protocol" "IsPlainText" "IsHTML" "NoUgly">}}
**Note:**
* A page can be output in as many output formats as you want, and you can have an infinite amount of output formats defined **as long as they resolve to a unique path on the file system**. In the above table, the best example of this is `AMP` vs. `HTML`. `AMP` has the value `amp` for `Path` so it doesn't overwrite the `HTML` version; e.g. we can now have both `/index.html` and `/amp/index.html`.
* The `MediaType` must match the `Type` of an already defined media type.
* You can define new output formats or redefine built-in output formats; e.g., if you want to put `AMP` pages in a different path.
* A page can be output in as many output formats as you want, and you can have an infinite amount of output formats defined, as long as _they resolve to a unique path on the file system_. In the table above, the best example of this is `AMP` vs. `HTML`: We have given `AMP` a value for `Path` so it doesn't overwrite the `HTML` version, i.e. we can now have both `/index.html` and `/amp/index.html`.
* The `MediaType` must match the `Type` of an already defined media type (see above).
* You can define new or redefine built-in output formats (if you, as an example, want to put `AMP` pages in a different path).
To add or modify a media type, define it in a `outputFormats` section in your site config (either for all sites or for a given language).
Example in `config.toml`:
To add or modify an output format, define it in an `outputFormats` section in your site's [configuration file](/templates/configuration/), either for all sites or for a given language.
```toml
[outputFormats.MyEnrichedFormat]
@ -79,42 +75,43 @@ protocol = "bep://"
The above example is fictional, but if used for the homepage on a site with `baseURL` `http://example.org`, it will produce a plain text homepage with the URL `bep://example.org/myindex.enr`.
### Configuring Output Formats
The following is the full list of configuration options for output formats and their default values:
`Name`
: The output format identifier. This is used to define what output format(s) you want for your pages.
: the output format identifier. This is used to define what output format(s) you want for your pages.
`MediaType`
: This must match the `Type` of a defined media type.
: this must match the `Type` of a defined media type.
`Path`
: Sub path to save the output files.
: sub path to save the output files.
`BaseName`
: The base filename for the list filenames (homepage etc.). **Default:** `index`.
: the base filename for the list filenames (homepage, etc.). **Default:** `index`.
`Rel`
: Can be used to create `rel` values in `link` tags. **Default:** `alternate`.
: can be used to create `rel` values in `link` tags. **Default:** `alternate`.
`Protocol`
: Will replace the "http://" or "https://" in your `baseURL` for this output format.
: will replace the "http://" or "https://" in your `baseURL` for this output format.
`IsPlainText`
: Use Go's plain text templates parser for the templates. **Default:** `false`.
: use Go's plain text templates parser for the templates. **Default:** `false`.
`IsHTML`
: Used in situations only relevant for `HTML`-type formats; e.g., page aliases.
: used in situations only relevant for `HTML`-type formats; e.g., page aliases.
`NoUgly`
: Used to turn off ugly URLs If `uglyURLs` is set to `true` in your site. **Default:** `false`.
: used to turn off ugly URLs If `uglyURLs` is set to `true` in your site. **Default:** `false`.
`NotAlternative`
: Enable if it doesn't make sense to include this format in an `AlternativeOutputFormats` format listing on `Page` (e.g., with `CSS`). Note that we use the term *alternative* and not *alternate* here, as it does not necessarily replace the other format. **Default:** `false`.
: enable if it doesn't make sense to include this format in an `AlternativeOutputFormats` format listing on `Page` (e.g., with `CSS`). Note that we use the term *alternative* and not *alternate* here, as it does not necessarily replace the other format. **Default:** `false`.
## Output Formats for Pages
## Output Formats for your pages
A `Page` in Hugo can be rendered to multiple representations on the file system: In its default configuration all will get an `HTML` page and some of them will get an `RSS` page (homepage, sections etc.).
A `Page` in Hugo can be rendered to multiple representations on the file system. By default, all pages will render as `HTML` with some of them also as `RSS` (homepage, sections, etc.).
This can be changed by defining an `outputs` list of output formats in either the `Page` front matter or in the site configuration (either for all sites or per language).
@ -134,13 +131,12 @@ outputs:
page: ["HTML"]
```
{{% note %}}
* The output definition is per `Page` `Kind` (i.e, `page`, `home`, `section`, `taxonomy`, or `taxonomyTerm`).
* The names used must match the `Name` of a defined `Output Format`.
* Any `Kind` without a definition will default to `HTML`.
* These can be overridden per `Page` in the front matter of content files.
* Output formats are case insensitive.
{{% /note %}}
The following is an example of `YAML` front matter in a content file that defines output formats for the rendered `Page`:
@ -156,7 +152,7 @@ outputs:
## Linking to Output Formats
+ `Page` has both `.OutputFormats` (all formats including the current) and `.AlternativeOutputFormats`, the latter useful for creating a `link rel` list in your `head` section:
Each `Page` has both an `.OutputFormats` (all formats, including the current) and an `.AlternativeOutputFormats` variable, the latter of which is useful for creating a `link rel` list in your site's `<head>`:
```
{{ range .AlternativeOutputFormats -}}
@ -164,7 +160,7 @@ outputs:
{{ end -}}
```
Note that `.Permalink` on `RelPermalink` on `Page` will return the first output format defined for that page (usually `HTML` if nothing else is defined).
Note that `.Permalink` and `.RelPermalink` on `Page` will return the first output format defined for that page (usually `HTML` if nothing else is defined).
This is how you link to a given output format:
@ -186,18 +182,16 @@ From content files, you can use the [`ref` or `relref` shortcodes](/content-mana
A new output format needs needs a corresponding template in order to render anything useful.
{{% note %}}
The key distinction for Hugo versions 0.20 and newer is that Hugo looks at an output format´s `Name` and MediaType´s `Suffix` when we choose the templates to use to render a given `Page`.**
The key distinction for Hugo versions 0.20 and newer is that Hugo looks at an output format's `Name` and MediaType's `Suffix` when choosing the template used to render a given `Page`.
{{% /note %}}
And with so many possible variations, this is best explained with some examples:
The following table shows examples of different output formats, the suffix used, and Hugo's respective template [lookup order][]. All of the examples in the table can:
* Use a [base template][base].
* Include [partial templates][partials]
{{< datatable "output" "layouts" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}
**Note**
* All of the above examples can use a [base template][base].
* All of the above examples can also include partials.
Hugo will now also detect the media type and output format of partials, if possible, and use that information to decide if the partial should be parsed as a plain text template or not.
Hugo will look for the name given, so you can name it whatever you want. But if you want it treated as plain text, you should use the file suffix and, if needed, the name of the Output Format. The pattern is as follows:
@ -212,6 +206,12 @@ The partial below is a plain text template (Outpuf Format is `CSV`, and since th
{{ partial "mytextpartial.csv" . }}
```
Also note that plain text partials can currently only be included in plain text templates, and vice versa. See [this issue](https://github.com/spf13/hugo/issues/3273) for some background.
{{% note %}}
Plain text partials can currently only be included in plain text templates, and vice versa. See [this issue](https://github.com/spf13/hugo/issues/3273) for some background.
{{% /note %}}
[base]: /templates/base/
[base]: /templates/base/
[config]: /getting-started/configuration/
[lookup order]: /templates/lookup/
[media type]: https://en.wikipedia.org/wiki/Media_type
[partials]: /templates/partials/

View File

@ -18,7 +18,7 @@ aliases: [/variables/page/]
toc: true
---
The following is a list of page-level variables that can be defined for a piece of content. Many of these will be defined in the front matter, derived from file location, or extracted from the content itself.
The following is a list of page-level variables. Many of these will be defined in the front matter, derived from file location, or extracted from the content itself.
{{% note "`.Scratch`" %}}
See [`.Scratch`](/functions/scratch/) for page-scoped, writable variables.
@ -26,6 +26,9 @@ See [`.Scratch`](/functions/scratch/) for page-scoped, writable variables.
## Page Variables
`.AlternativeOutputFormats`
: contains all alternative formats for a given page; this variable is especially useful `link rel` list in your site's `<head>`. (See [Output Formats](/templates/output-formats/).)
`.Content`
: the content itself, defined below the front matter.
@ -87,6 +90,9 @@ See [`.Scratch`](/functions/scratch/) for page-scoped, writable variables.
`.NextInSection`
: pointer to the following content within the same section (based on `publishdate` in front matter).
`.OutputFormats`
: contains all formats, including the current format, for a given page. Can be combined the with [`.Get` function](/functions/get/) to grab a specific format. (See [Output Formats](/templates/output-formats/).)
`.Pages`
: a collection of associated pages. This value will be `nil` for regular content pages. `.Pages` is an alias for `.Data.Pages`.