hugo/content/about/new-in-032.md
Bjørn Erik Pedersen f3cd083961 Squashed 'docs/' changes from 3e663efb2..fc61378a3
fc61378a3 Add Hugo 0.32 related docs
77edf7fd7 commands: Regenerate
af9d25458 Fix Blackfriday's Markdown extension name
1223dd63a Remove roadmap
b8bcb2fb8 Include note to allow hugo write permissions outside home dir
7dbccb936 Fix typo in roadmap
3a38da6f5 Fix spelling
94ebe50ff Merge branch 'master' of github.com:gohugoio/hugoDocs
89376e21d Clarify Hugo Roadmap
03d191fec Mention Reverse function in taxonomy tpl page.
a4ea3402d Fix ref and relref function pages.
b36632b31 Remove non-existing source variable
a638160dc Update Content Organization to match the world
47eb431ca Correct one link in templates/output-formats.md
8bf933629 Spell fix
ce2d48728 Add docs for .AllTranslations
de94b4942 Move sponsor data to theme data
41fe75254 Merge commit 'f463ef99ed2862e4042557e28aece7ca858e1d0a'
f463ef99e Squashed 'themes/gohugoioTheme/' changes from bc851da9..75da2f6b
532c65f2a Move sponsor logo to theme
899e2defe Add sponsor logos to home page and footer
3ca53db97 Release 0.31.1
bb9876ce2 Merge branch 'temp0311'
c7c3ee7e5 releaser: Prepare repository for 0.32-DEV
4ac554792 releaser: Add release notes to /docs for release of 0.31.1
52bfb5c15 releaser: Bump versions for release of 0.31.1
cfdc2e4ea Fix output formats example
5746c10c2 More on output format
de2ee0fe0 Improve suffix redefinition example
c9997839e Update gitlab CI submodule management
82d74e306 Add Bootstrap styling to breadcrumb example
c8c9601a8 Use the code shortcode for the breadcrumb example
16be43e7d Clean up formatting in variable definition lists
149c2c157 Add nested section docs
783c3d636 Sync theme
60a220bbd Squashed 'themes/gohugoioTheme/' changes from 6b632895..bc851da9
4b33a04d0 Fix typo
94cffc43c Fix little typo
a5d4f762f Fix typo
36c5a0b43 Add a note about the 2 in staticDir2
087bd9a9f Add KeyCDN to menu
4ac8aae38 Hugo 0.31 Released
8fdd995e7 releaser: Prepare repository for 0.32-DEV
eb0f38fbb releaser: Add release notes to /docs for release of 0.31
60efdfff7 releaser: Bump versions for release of 0.31
44dafb10b Merge commit '30c0d485eaff6d70df1be0353911ddca485d52bf'
e6b847b95 Merge commit '05e42bc643f1840ed2ad9c2eff82a269d1381683'
15d86a525 Handle Taxonomy permalinks
5c3c18d7f Add support for height argument to figure shortcode

git-subtree-dir: docs
git-subtree-split: fc61378a3227c14883a2942d67c806014e7bb6cb
2017-12-30 09:15:31 +01:00

5.8 KiB

title description date keywords menu weight sections_weight draft aliases toc
Hugo 0.32 HOWTO About page bundles, image processing and more. 2017-12-28
ssg
static
performance
security
docs
parent weight
about 10
10 10 false
true

{{% note %}} This documentation belongs in other places in this documentation site, but is put here first ... to get something up and running fast. {{% /note %}}

Also see this demo project from bep, the clever Norwegian behind these new features:

Page Resources

Organize Your Content

{{< figure src="/images/hugo-content-bundles.png" title="Pages with image resources" >}}

The content folder above shows a mix of content pages (md (i.e. markdown) files) and image resources.

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

The 3 page bundles marked in red explained from top to bottom:

  1. The home page with one image resource (1-logo.png)
  2. The blog section with two images resources and two pages resources (content1.md, content2.md). Note that the _index.md represents the URL for this section.
  3. An article (hugo-is-cool) with a folder with some images and one content resource (cats-info.md). Note that the index.md represents the URL for this article.

The content files below blog/posts are just regular standalone pages.

{{% note %}} Note that changes to any resource inside the content folder will trigger a reload when running in watch (aka server or live reload mode), it will even work with --navigateToChanged. {{% /note %}}

Sort Order

  • Pages are sorted according to standard Hugo page sorting rules.
  • Images and other resources are sorted in lexicographical order.

Handle Page Resources in Templates

List all Resources

{{ range .Resources }}
<li><a href="{{ .RelPermalink }}">{{ .ResourceType | title }}</a></li>
{{ end }}

For an absolute URL, use .Permalink.

Note: The permalink will be relative to the content page, respecting permalink settings. Also, included page resources will not have a value for RelPermalink.

List All Resources by Type

{{ with .Resources.ByType "image" }}
{{ end }}

Type here is page for pages, else the main type in the MIME type, so image, json etc.

Get a Specific Resource

{{ $logo := .Resources.GetByPrefix "logo" }}
{{ with $logo }}
{{ end }}

Include Page Resource Content

{{ with .Resources.ByType "page" }}
{{ range . }}
<h3>{{ .Title }}</h3>
{{ .Content }}
{{ end }}
{{ end }}

Image Processing

The image resource implements the methods Resize, Fit and Fill:

Resize
Resize to the given dimension, {{ $logo.Resize "200x" }} will resize to 200 pixels wide and preserve the aspect ratio. Use {{ $logo.Resize "200x100" }} to control both height and width.
Fit
Scale down the image to fit the given dimensions, e.g. {{ $logo.Fit "200x100" }} will fit the image inside a box that is 200 pixels wide and 100 pixels high.
Fill
Resize and crop the image given dimensions, e.g. {{ $logo.Fill "200x100" }} will resize and crop to width 200 and height 100

{{% note %}} Image operations in Hugo currently do not preserve EXIF data as this is not supported by Go's image package. This will be improved on in the future. {{% /note %}}

Image Processing Options

In addition to the dimensions (e.g. 200x100) where either height or width can be omitted, Hugo supports a set of additional image options:

Anchor
Only relevant for Fill. This is useful for thumbnail generation where the main motive is located in, say, the left corner. Valid are Center, TopLeft, Top, TopRight, Left, Right, BottomLeft, Bottom, BottomRight. Example: {{ $logo.Fill "200x100 BottomLeft" }}
JPEG Quality
Only relevant for JPEG images, values 1 to 100 inclusive, higher is better. Default is 75. {{ $logo.Resize "200x q50" }}
Rotate
Rotates an image by the given angle counter-clockwise. The rotation will be performed first to get the dimensions correct. {{ $logo.Resize "200x r90" }}. The main use of this is to be able to manually correct for EXIF orientation of JPEG images.
Resample Filter
Filter used in resizing. Default is Box, a simple and fast resampling filter appropriate for downscaling. See https://github.com/disintegration/imaging for more. If you want to trade quality for faster processing, this may be a option to test.

Performance

Processed images are stored below <project-dir>/resources (can be set with resourceDir config setting). This folder is deliberately placed in the project, as it is recommended to check these into source control as part of the project. These images are not "Hugo fast" to generate, but once generated they can be reused.

If you change your image settings (e.g. size), remove or rename images etc., you will end up with unused images taking up space and cluttering your project.

To clean up, run:

hugo --gc

{{% note %}} GC is short for Garbage Collection. {{% /note %}}

Configuration

Default Image Processing Config

You can configure an imaging section in config.toml with default image processing options:

[imaging]
# Default resample filter used for resizing. Default is Box,
# a simple and fast averaging filter appropriate for downscaling.
# See https://github.com/disintegration/imaging
resampleFilter = "box"

# Defatult JPEG quality setting. Default is 75.
quality = 68