mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
337d0c5f51
dce236ad1 Wrap up the bundle etc. edits for now 27d058566 Add the bundle tree to the organization bundle a83f750dd Move organization.md to its own bundle 01ec4f462 Make the image docs a bundle 60de1e090 Some more resources copy-edits 05d763c0c Some resource copy-edits 6299d6dbb Update the imgproc shortcode 59e0fc209 Add headless bundle documentation a3bbf60bf Link Page Resources page from Front Matter page 830576f86 Update order significance section, add counter section 3b1836509 Revert the recent change made to default list template 886ed0e10 Page Bundles draft rev 2 f530d1a7a image processing and page resources made into regular .md ec47cecda Finalised Page Resources and Image Processing Moved Page Resources and Impage Processing out of the Bundle section and at the root of the Content Management section 253092335 Modified front matter metadata exemple. Added yaml version. da5e4f476 Adding date in the front-matter; missed in previous commit 6bc3ced13 Add rough draft for page and section bundles a0e44458f Image processing first draft, Resources second read/fix 2367f0b78 data: Remove duplicate layouts in table c2f179839 First draft of bundles/resources (covers resources and metadata) 2a3f9a613 Add weights to pages in Bundles branch 9a0146cc0 Switch front-matter format of Bundles doc to yaml; add front-matter 1295fc083 First draft for Bundles documentation organization structure 5a2e52231 Fix archetype paths 9c2e5c063 Merge commit '22cced34fc608256f8271ad591a5ccca991bb164' 22cced34f Squashed 'themes/gohugoioTheme/' changes from 75da2f6b..ecad8247 55d16c9a1 Fix broken sentence in multilingual sections a76895ad2 Replace the outdated Emacs package with new one e6cf1dec0 Remove obsolete link to hugo roadmap dd2fd145b Add GitLab Pages to mentioned hosters (#309) a05ce6bf6 Add 0.34 release notes poster 5c0ebdfca Release 0.34 13c2f3dc8 Merge branch 'temp34' e6b5ffa04 Add 0.34 poster 1e1960496 releaser: Add release notes to /docs for release of 0.34 ac3efe182 releaser: Bump versions for release of 0.34 8f91f62d8 Fixes #222 cca35dbe4 Fix example eaaa21ca1 Add missing params key 00d0b0363 Adding new Blogger utility to tools/migrations 7d36d579e Updated the line number for Dockerfile pointer 852188f85 Update installing.md with Fedora instructions 4d151a3ab Update search.md 4c2750bfb Update deployment-with-nanobox.md c3cc9cd49 configuration: Remove defaultExtension from docs f7c96b4b5 Update GitHub Pages documentation 55787f09a Merge branch 'rmetzler-menu-link-title' 2abbd9bd9 Merge branch 'master' into menu-link-title e1fd710b7 Bring archetypes in from theme. daf6f51c0 Mention the significance of leading 0 in int fn string input 07f498755 Add documentation for `cond` function. 050ccd12b Add documentation for the .HasShortcode function 919af9071 Correct anchor under 'Add custom metadata to a Taxonomy Term' 55600b4ff More layouts work 201cf4f67 Add some more single page layout variants d5e7c03e2 Rework the layouts doc 84622e67c Cleans up the code sample c231c9bd5 Add a new note to 0.33 relnotes 328ec9930 Release 0.33 b108fcc7b Merge branch 'temp33' into next ab9d9ee65 releaser: Prepare repository for 0.34-DEV e20c75320 releaser: Add release notes to /docs for release of 0.33 49f24dcd1 releaser: Bump versions for release of 0.33 9c8e5e207 Update 0.33 poster 7655603c8 Regenerate the docshelper data 16dc99583 Add Hugo 0.33 poster ce40cc197 Merge commit '3cf4300097610bb8b5bd0686d96d1df5db641895' 9a3085523 releaser: Prepare repository for 0.33-DEV a52db97d8 fixing typos and syntax for consistency 64525670f ádd title to some menu entries. This needs hugo >= v0.32 85d415ab2 ádd examples for menu .Title and .Page git-subtree-dir: docs git-subtree-split: dce236ad1258a9d9a0ee209f02b2e1f65b46f0fb
209 lines
6.5 KiB
Markdown
209 lines
6.5 KiB
Markdown
---
|
|
title: Hugo 0.32 HOWTO
|
|
description: About page bundles, image processing and more.
|
|
date: 2017-12-28
|
|
keywords: [ssg,static,performance,security]
|
|
menu:
|
|
docs:
|
|
parent: "about"
|
|
weight: 10
|
|
weight: 10
|
|
sections_weight: 10
|
|
draft: false
|
|
aliases: []
|
|
toc: true
|
|
images:
|
|
- images/blog/sunset.jpg
|
|
---
|
|
|
|
|
|
{{% 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](https://github.com/bep/), the clever Norwegian behind these new features:
|
|
|
|
* http://hugotest.bep.is/
|
|
* https://github.com/bep/hugotest (source)
|
|
|
|
## 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](/templates/output-formats/#media-types).
|
|
{{% /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
|
|
|
|
```html
|
|
{{ 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
|
|
|
|
```html
|
|
{{ 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
|
|
|
|
```html
|
|
{{ $logo := .Resources.GetByPrefix "logo" }}
|
|
{{ with $logo }}
|
|
{{ end }}
|
|
```
|
|
|
|
#### Include Page Resource Content
|
|
|
|
```html
|
|
{{ 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](https://github.com/golang/go/search?q=exif&type=Issues&utf8=%E2%9C%93). 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](https://commons.wikimedia.org/wiki/User:Bep) (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:
|
|
|
|
```html
|
|
{{</* 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 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](https://github.com/golang/go/issues/4341) 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:
|
|
|
|
```bash
|
|
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:
|
|
|
|
```toml
|
|
[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
|
|
```
|
|
|
|
|
|
|
|
|
|
|