mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
047c4188df
f9a5dc59b Code Toggle block added to doc site final batch Templates ✅ Variables ✅ 4d4107968 Add eSolia as new sponsor 000fed94e Add missing closing tags for li in menu template example f462b620f Clarify that local CSV files cannot be inside data dir ae083641a Added hugo-search-index to list of search tools e2b64d0b7 Remove extra link 2fb4c9af5 Release 0.38.2 59b1c9853 releaser: Prepare repository for 0.39-DEV 92f6a05ea releaser: Add release notes to /docs for release of 0.38.2 76244729e releaser: Bump versions for release of 0.38.2 0960c5fb3 Adjust gray color of tab vs pane in code-toggle. 8ae3aadd7 use code-toggle shortcode when relevant Content Management ✅ 455b8b53b Update related.md 6e8d19090 Release 0.38.1 079ba044c releaser: Prepare repository for 0.39-DEV 6f23e6ec1 releaser: Add release notes to /docs for release of 0.38.1 c51692ceb releaser: Bump versions for release of 0.38.1 d37ea6a5e Update related.md faa2707d0 Update index.md 9ce901dcb Add a forgotten language tag (go-html-template) for code b05aaed14 Update where.md 4d4760819 Fix typo in code-toggle.md c5a5250a1 Use the new go-html-template Chroma lexer 2de831f4b Add the full list of Chroma lexers 18114d4b4 Update Output Formats b069d7f84 Release 0.38 caaa8355a releaser: Prepare repository for 0.39-DEV e45b7cc9f releaser: Add release notes to /docs for release of 0.38 40f40906e releaser: Bump versions for release of 0.38 2d52e2e4e Merge commit 'ed8bf081fdbf336e026517b7e1b123c039014ab5' 1439f64a0 docs: Generate docshelper data 5b0edfd79 Add .Site.IsServer fdb579ad1 Merge commit '0a23baa6a90901f772c234107c4f12c16c76f4aa' 7b71da1f8 hugolib: Add Reset method to delete key from Scratch 63a131664 docs: Add docs for lang.Merge 55cba056d Merge commit '3886fc1fef6ac19d58b9ba1bb642d0c6c9a54031' 6f301ebcc docs: Add docs on the new front matter configuration 7ba35ef56 Merge commit 'c0290655825e7bb36e13fb39f89d85b392cf1adc' 3d2cab754 releaser: Prepare repository for 0.38-DEV 095e888e1 releaser: Add release notes to /docs for release of 0.37.1 593fa0dcb releaser: Bump versions for release of 0.37.1 c18c1df54 releaser: Prepare repository for 0.38-DEV git-subtree-dir: docs git-subtree-split: f9a5dc59b77d15cc2c7534e10bcd90bcfeda7bb4
209 lines
6.6 KiB
Markdown
209 lines
6.6 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
|
|
|
|
```go-html-template
|
|
{{ 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
|
|
|
|
```go-html-template
|
|
{{ 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
|
|
|
|
```go-html-template
|
|
{{ $logo := .Resources.GetByPrefix "logo" }}
|
|
{{ with $logo }}
|
|
{{ end }}
|
|
```
|
|
|
|
#### Include Page Resource Content
|
|
|
|
```go-html-template
|
|
{{ 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:
|
|
|
|
```go-html-template
|
|
{{</* 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
|
|
```
|
|
|
|
|
|
|
|
|
|
|