e161ea09d Add one more Chinese file to workaround reflect: Zero(nil) b595b3a21 Add more Chinese translation 56e4e95d9 Use lang.Merge to "fill in the gaps" for untranslated pages ef079406c Merge commit '650fac3a4e7d256f4505402ab44cfc3c804b8dea' 650fac3a4 Squashed 'themes/gohugoioTheme/' changes from a1768ebb..f31a3dc8 322eff899 Add Chinese language for menus d90b886e0 Fix Markdown table syntax in previous commit 737f3dfca Update the leaf bundle vs branch bundle table 09fa1bc4e Clarify that `.Now` is obsolete 879ea3f6a Make release notes somewhat more consistent 0113e2051 Move 0.40.2-relnotes into content/en/news 77578f5bf Move content/ into new contentDir content/en/ 4dcf7c709 Fix "reflect: Zero(nil)" error in showcase 63dd25505 Release 0.40.2 2076c0d56 releaser: Prepare repository for 0.41-DEV 070fe565e releaser: Add release notes to /docs for release of 0.40.2 4ce52e913 releaser: Bump versions for release of 0.40.2 41907c487 Fix typos in syntax-highlighting.md 91753ef3d Add missing backtick b77274301 Remove duplicate release notes (0.27, 0.27.1, 0.35) 6e00da316 Remove obsolete content/release-notes/ directory 00a6d8c02 Change en dash back to `--` in 0.38.2-relnotes 51b32dc00 Update archetypes.md d0e5c2307 Release 0.40.1 4538a6d5b releaser: Prepare repository for 0.41-DEV 91b391d70 releaser: Add release notes to /docs for release of 0.40.1 e0979d143 releaser: Bump versions for release of 0.40.1 7983967c2 Clean images fe3fdd77d Polish showcase for Flesland Flis e6dde3989 Showcase - Flesland Flis AS by Absoluttweb 73aa62290 Revive @spf13's special Hugo font add67b335 Release Hugo 0.40 c0a26e5a6 Merge branch 'temp40' beeabaaae releaser: Prepare repository for 0.41-DEV e67d5e985 releaser: Add release notes to /docs for release of 0.40 6cdd95273 releaser: Bump versions for release of 0.40 bee21fb9b Revive the other Hugo logos too 4f45e8fe1 Fix the link type attribute for RSS in examples 8c67dc89a Fix example in delimit doc e7f6c00d5 Revive the logo used on the forum 82b0cd26e Merge commit 'a215abf70e018f4bf40d6c09d8bd148d8684b33d' 119c8ca58 Merge commit 'd2ec1a06df8ab6b17ad05cb008d5701b40327d47' db4683bd2 Improve .Get docs 05260b886 .Get function: fix syntax signature git-subtree-dir: docs git-subtree-split: e161ea09d33e3199f4998e4d2e9068d5a850f042
6.6 KiB
title | description | date | keywords | menu | weight | sections_weight | draft | aliases | toc | images | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Hugo 0.32 HOWTO | About page bundles, image processing and more. | 2017-12-28 |
|
|
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:
- The home page with one image resource (
1-logo.png
) - 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. - An article (
hugo-is-cool
) with a folder with some images and one content resource (cats-info.md
). Note that theindex.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 Examples
The photo of the sunset used in the examples below is Copyright Bjørn Erik Pedersen (Creative Commons Attribution-Share Alike 4.0 International license)
{{< imgproc sunset Resize "300x" />}}
{{< imgproc sunset Fill "90x120 left" />}}
{{< imgproc sunset Fill "90x120 right" />}}
{{< imgproc sunset Fit "90x90" />}}
{{< imgproc sunset Resize "300x q10" />}}
This is the shortcode used in the examples above:
{{< code file="layouts/shortcodes/imgproc.html" >}}
{{< readfile file="layouts/shortcodes/imgproc.html" >}}
{{< /code >}}
And it is used like this:
{{</* imgproc sunset Resize "300x" */>}}
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 areCenter
,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