Merge commit '13e64d72763bf8d6d92d4cdfc15ed45ee9debfab'
|
@ -28,6 +28,7 @@ toc: true
|
|||
Note that:
|
||||
|
||||
* These settings have their defaults setting set to _off_, i.e. how it worked before Hugo `0.41`. You must do your own evaluation of your site and apply the appropriate settings.
|
||||
* These settings work with the [internal templates](/templates/internal/). Some theme may contain custom templates for embedding services like Google Analytics. In that case these options have no effect.
|
||||
* We will continue this work and improve this further in future Hugo versions.
|
||||
|
||||
## All Privacy Settings
|
||||
|
|
|
@ -35,7 +35,7 @@ The above will create a new content file in `content/posts/my-first-post.md` usi
|
|||
3. `themes/my-theme/archetypes/posts.md`
|
||||
4. `themes/my-theme/archetypes/default.md`
|
||||
|
||||
The last two list items is only applicable if you use a theme and it uses the `my-theme` theme name as an example.
|
||||
The last two list items are only applicable if you use a theme and it uses the `my-theme` theme name as an example.
|
||||
|
||||
## Create a New Archetype Template
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ There are a few alternatives to commenting on static sites for those who do not
|
|||
* [Muut](http://muut.com/)
|
||||
* [isso](http://posativ.org/isso/) (Self-hosted, Python)
|
||||
* [Tutorial on Implementing Isso with Hugo][issotutorial]
|
||||
|
||||
* [Utterances](https://utteranc.es/) (Open source, Github comments widget built on Github issues)
|
||||
|
||||
<!-- I don't think this is worth including in the documentation since it seems that Steve is no longer supporting or developing this project. rdwatters - 2017-02-29.-->
|
||||
<!-- * [Kaiju](https://github.com/spf13/kaiju) -->
|
||||
|
|
|
@ -240,7 +240,7 @@ Markdown syntax is simple enough to learn in a single sitting. The following are
|
|||
[mdcheatsheet]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet
|
||||
[mdguide]: https://www.markdownguide.org/
|
||||
[mdtutorial]: http://www.markdowntutorial.com/
|
||||
[Miek Gieben's website]: https://miek.nl/2016/March/05/mmark-syntax-document/
|
||||
[Miek Gieben's website]: https://miek.nl/2016/march/05/mmark-syntax-document/
|
||||
[mmark]: https://github.com/miekg/mmark
|
||||
[mmarkgh]: https://github.com/miekg/mmark/wiki/Syntax
|
||||
[org]: http://orgmode.org/
|
||||
|
|
|
@ -80,7 +80,7 @@ You can also add entries to menus that aren’t attached to a piece of content.
|
|||
|
||||
Here’s an example snippet pulled from a configuration file:
|
||||
|
||||
{{< code-toggle file="config.toml" >}}
|
||||
{{< code-toggle file="config" >}}
|
||||
[[menu.main]]
|
||||
name = "about hugo"
|
||||
pre = "<i class='fa fa-heart'></i>"
|
||||
|
@ -90,6 +90,7 @@ Here’s an example snippet pulled from a configuration file:
|
|||
[[menu.main]]
|
||||
name = "getting started"
|
||||
pre = "<i class='fa fa-road'></i>"
|
||||
post = "<span class='alert'>New!</span>"
|
||||
weight = -100
|
||||
url = "/getting-started/"
|
||||
{{< /code-toggle >}}
|
||||
|
|
|
@ -14,13 +14,13 @@ aliases: [/content/related/,/related/]
|
|||
toc: true
|
||||
---
|
||||
|
||||
{{% note %}}
|
||||
We currently do not index **Page content**. We thought we would release something that will make most people happy before we start solving [Sherlock's last case](https://github.com/joearms/sherlock).
|
||||
{{% /note %}}
|
||||
|
||||
Hugo uses a set of factors to identify a page's related content based on Front Matter parameters. This can be tuned to the desired set of indices and parameters or left to Hugo's default [Related Content configuration](#configure-related-content).
|
||||
|
||||
## List Related Content
|
||||
|
||||
To list up to 5 related pages is as simple as including something similar to this partial in your single page template:
|
||||
|
||||
To list up to 5 related pages (which share the same _date_ or _keyword_ parameters) is as simple as including something similar to this partial in your single page template:
|
||||
|
||||
{{< code file="layouts/partials/related.html" >}}
|
||||
{{ $related := .Site.RegularPages.Related . | first 5 }}
|
||||
|
@ -34,67 +34,62 @@ To list up to 5 related pages is as simple as including something similar to thi
|
|||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
### Methods
|
||||
|
||||
Here is the list of "Related" methods available on a page collection such `.RegularPages`.
|
||||
|
||||
#### .Related PAGE
|
||||
Returns a collection of pages related the given one.
|
||||
|
||||
```
|
||||
{{ $related := .RegularPages.Related . }}
|
||||
```
|
||||
|
||||
#### .RelatedIndices PAGE INDICE1 [INDICE2 ...]
|
||||
Returns a collection of pages related to a given one restricted to a list of indices.
|
||||
|
||||
```
|
||||
{{ $related := .RegularPages.RelatedIndices . "tags" "date" }}
|
||||
```
|
||||
|
||||
#### .RelatedTo KEYVALS [KEYVALS2 ...]
|
||||
Returns a collection of pages related together by a set of indices and their match.
|
||||
|
||||
In order to build those set and pass them as argument, one must use the `keyVals` function where the first agrument would be the `indice` and the consective ones its potential `matches`.
|
||||
|
||||
```
|
||||
{{ $related := .RegularPages.RelatedTo ( keyVals "tags" "hugo" "rocks") ( keyVals "date" .Date ) }}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
Read [this blog article](https://regisphilibert.com/blog/2018/04/hugo-optmized-relashionships-with-related-content/) for a great explanation of more advanced usage of this feature.
|
||||
{{% /note %}}
|
||||
|
||||
The full set of methods available on the page lists can be seen in this Go interface:
|
||||
|
||||
```go
|
||||
// A PageGenealogist finds related pages in a page collection. This interface is implemented
|
||||
// by Pages and PageGroup, which makes it available as `{{ .RegularPages.Related . }}` etc.
|
||||
type PageGenealogist interface {
|
||||
|
||||
// Template example:
|
||||
// {{ $related := .RegularPages.Related . }}
|
||||
Related(doc related.Document) (Pages, error)
|
||||
|
||||
// Template example:
|
||||
// {{ $related := .RegularPages.RelatedIndices . "tags" "date" }}
|
||||
RelatedIndices(doc related.Document, indices ...interface{}) (Pages, error)
|
||||
|
||||
// Template example:
|
||||
// {{ $related := .RegularPages.RelatedTo ( keyVals "tags" "hugo" "rocks") ( keyVals "date" .Date ) }}
|
||||
RelatedTo(args ...types.KeyValues) (Pages, error)
|
||||
}
|
||||
```
|
||||
## Configure Related Content
|
||||
Hugo provides a sensible default configuration of Related Content, but you can fine-tune this in your configuration, on the global or language level if needed.
|
||||
|
||||
### Default configuration
|
||||
|
||||
Without any `related` configuration set on the project, Hugo's Related Content methods will use the following.
|
||||
|
||||
```yaml
|
||||
related:
|
||||
threshold: 80
|
||||
includeNewer: false
|
||||
toLower: false
|
||||
indices:
|
||||
- name: keywords
|
||||
weight: 100
|
||||
- name: date
|
||||
weight: 10
|
||||
```
|
||||
|
||||
Custom configuration should be set using the same syntax.
|
||||
|
||||
{{% note %}}
|
||||
If you add a `related` config section, you need to add a complete configuration. It is not possible to just set, say, `includeNewer` and use the rest from the Hugo defaults.
|
||||
{{% /note %}}
|
||||
|
||||
Below is a sample `config.toml` section:
|
||||
|
||||
```
|
||||
[related]
|
||||
|
||||
# Only include matches with rank >= threshold. This is a normalized rank between 0 and 100.
|
||||
threshold = 80
|
||||
|
||||
# To get stable "See also" sections we, by default, exclude newer related pages.
|
||||
includeNewer = false
|
||||
|
||||
# Will lower case keywords in both queries and in the indexes.
|
||||
toLower = false
|
||||
|
||||
[[related.indices]]
|
||||
name = "keywords"
|
||||
weight = 150
|
||||
[[related.indices]]
|
||||
name = "author"
|
||||
toLower = true
|
||||
weight = 30
|
||||
[[related.indices]]
|
||||
name = "tags"
|
||||
weight = 100
|
||||
[[related.indices]]
|
||||
name = "date"
|
||||
weight = 10
|
||||
pattern = "2006"
|
||||
```
|
||||
### Top Level Config Options
|
||||
|
||||
threshold
|
||||
|
@ -135,9 +130,6 @@ He should now be able to add an improved version of that "Related Content" secti
|
|||
* If you don't use any of the `Related` methods, you will not use the Relate Content feature, and performance will be the same as before.
|
||||
* Calling `.RegularPages.Related` etc. will create one inverted index, also sometimes named posting list, that will be reused for any lookups in that same page collection. Doing that in addition to, as an example, calling `.Pages.Related` will work as expected, but will create one additional inverted index. This should still be very fast, but worth having in mind, especially for bigger sites.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{{% note %}}
|
||||
We currently do not index **Page content**. We thought we would release something that will make most people happy before we start solving [Sherlock's last case](https://github.com/joearms/sherlock).
|
||||
{{% /note %}}
|
||||
|
|
|
@ -21,32 +21,40 @@ With the use of the `.Summary` [page variable][pagevariables], Hugo generates su
|
|||
|
||||
## Summary Splitting Options
|
||||
|
||||
* Hugo-defined Summary Split
|
||||
* User-defined Summary Split
|
||||
* Automatic Summary Split
|
||||
* Manual Summary Split
|
||||
|
||||
It is natural to accompany the summary with links to the original content, and a common design pattern is to see this link in the form of a "Read More ..." button. See the `.RelPermalink`, `.Permalink`, and `.Truncated` [page variables][pagevariables].
|
||||
|
||||
### Hugo-defined: Automatic Summary Splitting
|
||||
### Automatic Summary Splitting
|
||||
|
||||
By default, Hugo automatically takes the first 70 words of your content as its summary and stores it into the `.Summary` page variable for use in your templates. Taking the Hugo-defined approach to summaries may save time, but it has pros and cons:
|
||||
|
||||
* **Pros:** Automatic, no additional work on your part.
|
||||
* **Cons:** All HTML tags are stripped from the summary, and the first 70 words, whether they belong to a heading or to different paragraphs, are all put into one paragraph.
|
||||
By default, Hugo automatically takes the first 70 words of your content as its summary and stores it into the `.Summary` page variable for use in your templates. You may customize the summary length by setting `summaryLength` in your [site configuration](/getting-started/configuration/).
|
||||
|
||||
{{% note %}}
|
||||
The Hugo-defined summaries are set to use word count calculated by splitting the text by one or more consecutive white space characters. If you are creating content in a `CJK` language and want to use Hugo's automatic summary splitting, set `hasCJKLanguage` to `true` in you [site configuration](/getting-started/configuration/).
|
||||
You can customize how HTML tags in the summary are loaded using functions such as `plainify` and `safeHTML`.
|
||||
{{% /note %}}
|
||||
|
||||
### User-defined: Manual Summary Splitting
|
||||
{{% note %}}
|
||||
The Hugo-defined summaries are set to use word count calculated by splitting the text by one or more consecutive whitespace characters. If you are creating content in a `CJK` language and want to use Hugo's automatic summary splitting, set `hasCJKLanguage` to `true` in your [site configuration](/getting-started/configuration/).
|
||||
{{% /note %}}
|
||||
|
||||
Alternatively, you may add the <code><!--more--></code> summary divider where you want to split the article. For [org content][org], use `# more` where you want to split the article. Content that comes before the summary divider will be used as that content's summary and stored in the `.Summary` page variable with all HTML formatting intact.
|
||||
### Manual Summary Splitting
|
||||
|
||||
Alternatively, you may add the <code><!--more--></code> summary divider where you want to split the article.
|
||||
|
||||
For [Org mode content][org], use `# more` where you want to split the article.
|
||||
|
||||
Content that comes before the summary divider will be used as that content's summary and stored in the `.Summary` page variable with all HTML formatting intact.
|
||||
|
||||
{{% note "Summary Divider"%}}
|
||||
The concept of a *summary divider* is not unique to Hugo. It is also called the "more tag" or "excerpt separator" in other literature.
|
||||
{{% /note %}}
|
||||
|
||||
* Pros: Freedom, precision, and improved rendering. All HTML tags and formatting are preserved.
|
||||
* Cons: Extra work for content authors, since they need to remember to type <code><!--more--></code> (or `# more` for [org content][org]) in each content file. This can be automated by adding the summary divider below the front matter of an [archetype](/content-management/archetypes/).
|
||||
Pros
|
||||
: Freedom, precision, and improved rendering. All HTML tags and formatting are preserved.
|
||||
|
||||
Cons
|
||||
: Extra work for content authors, since they need to remember to type <code><!--more--></code> (or `# more` for [org content][org]) in each content file. This can be automated by adding the summary divider below the front matter of an [archetype](/content-management/archetypes/).
|
||||
|
||||
{{% warning "Be Precise with the Summary Divider" %}}
|
||||
Be careful to enter <code><!--more--></code> exactly; i.e., all lowercase and with no whitespace.
|
||||
|
|
|
@ -15,7 +15,6 @@ menu:
|
|||
weight: 10
|
||||
sections_weight: 10
|
||||
draft: false
|
||||
aliases: [/contribute/development/]
|
||||
toc: true
|
||||
---
|
||||
|
||||
|
|
|
@ -94,15 +94,15 @@ Code blocks are crucial for providing examples of Hugo's new features to end use
|
|||
|
||||
### Standard Syntax
|
||||
|
||||
Across all pages on the Hugo docs, the typical triple-back-tick markdown syntax is used. If you do not want to take the extra time to implement the following code block shortcodes, please use standard GitHub-flavored markdown. The Hugo docs use a version of [highlight.js](https://highlightjs.org/) with a specific set of languages.
|
||||
Across many pages on the Hugo docs, the typical triple-back-tick markdown syntax (```` ``` ````) is used. If you do not want to take the extra time to implement the following code block shortcodes, please use standard GitHub-flavored markdown. The Hugo docs use a version of [highlight.js](https://highlightjs.org/) with a specific set of languages.
|
||||
|
||||
Your options for languages are `xml`/`html`, `go`/`golang`, `md`/`markdown`/`mkd`, `handlebars`, `apache`, `toml`, `yaml`, `json`, `css`, `asciidoc`, `ruby`, `powershell`/`ps`, `scss`, `sh`/`zsh`/`bash`/`git`, `http`/`https`, and `javascript`/`js`.
|
||||
|
||||
```
|
||||
````
|
||||
```
|
||||
<h1>Hello world!</h1>
|
||||
```
|
||||
```
|
||||
````
|
||||
|
||||
### Code Block Shortcode
|
||||
|
||||
|
@ -118,14 +118,13 @@ With the `code` shortcodes, *you must include triple back ticks and a language d
|
|||
|
||||
```
|
||||
{{%/* code file="smart/file/name/with/path.html" download="download.html" copy="true" */%}}
|
||||
```
|
||||
A whole bunch of coding going on up in here!
|
||||
```
|
||||
{{%/* /code */%}}
|
||||
```
|
||||
|
||||
The following are the arguments passed into `code`:
|
||||
|
||||
|
||||
***`file`***
|
||||
: the only *required* argument. `file` is needed for styling but also plays an important role in helping users create a mental model around Hugo's directory structure. Visually, this will be displayed as text in the top left of the code block.
|
||||
|
||||
|
@ -194,10 +193,8 @@ The `output` shortcode is almost identical to the `code` shortcode but only take
|
|||
|
||||
```
|
||||
{{%/* output file="post/my-first-post/index.html" */%}}
|
||||
```
|
||||
<h1>This is my First Hugo Blog Post</h1>
|
||||
<p>I am excited to be using Hugo.</p>
|
||||
```
|
||||
{{%/* /output */%}}
|
||||
```
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ aliases: []
|
|||
|
||||
This method wil return `nil` when no page could be found, so the above will not print anything if the blog section is not found.
|
||||
|
||||
To fund a regular page in the blog section::
|
||||
To find a regular page in the blog section::
|
||||
|
||||
```go-html-template
|
||||
{{ with .Site.GetPage "/blog/my-post.md" }}{{ .Title }}{{ end }}
|
||||
|
|
|
@ -22,7 +22,7 @@ aliases: []
|
|||
needsexamples: false
|
||||
---
|
||||
|
||||
`default` checks whether a given value is set and returns a default value if it is not. *Set* in this context means different things depending on date type:
|
||||
`default` checks whether a given value is set and returns a default value if it is not. *Set* in this context means different things depending on the data type:
|
||||
|
||||
* non-zero for numeric types and times
|
||||
* non-zero length for strings, arrays, slices, and maps
|
||||
|
|
|
@ -19,27 +19,7 @@ deprecated: false
|
|||
aliases: []
|
||||
---
|
||||
|
||||
The elements supported are strings, integers, and floats (only float64).
|
||||
|
||||
A useful example of `intersect` functionality is a "related posts" block. `isset` allows us to create a list of links to other posts that have tags that intersect with the tags in the current post.
|
||||
|
||||
The following is an example of a "related posts" [partial template][partials] that could be added to a [single page template][single]:
|
||||
|
||||
{{< code file="layouts/partials/related-posts.html" download="related-posts.html" >}}
|
||||
<ul>
|
||||
{{ $page_link := .Permalink }}
|
||||
{{ $tags := .Params.tags }}
|
||||
{{ range .Site.Pages }}
|
||||
{{ $page := . }}
|
||||
{{ $has_common_tags := intersect $tags .Params.tags | len | lt 0 }}
|
||||
{{ if and $has_common_tags (ne $page_link $page.Permalink) }}
|
||||
<li><a href="{{ $page.Permalink }}">{{ $page.Title }}</a></li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{< /code >}}
|
||||
|
||||
This is also very useful to use as `AND` filters when combined with where:
|
||||
An useful example is to use it as `AND` filters when combined with where:
|
||||
|
||||
```
|
||||
{{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }}
|
||||
|
|
33
docs/content/en/functions/os.Stat.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
title: os.Stat
|
||||
description: Gets a file information of a given path.
|
||||
godocref:
|
||||
date: 2018-08-07
|
||||
publishdate: 2018-08-07
|
||||
lastmod: 2018-08-07
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [files]
|
||||
signature: ["os.Stat PATH"]
|
||||
workson: []
|
||||
hugoversion:
|
||||
relatedfuncs: [readDir]
|
||||
deprecated: false
|
||||
aliases: []
|
||||
---
|
||||
|
||||
If your current project working directory has a single file named `README.txt` (30 bytes):
|
||||
```
|
||||
{{ $stat := os.Stat "README.txt" }}
|
||||
{{ $stat.Name }} → "README.txt"
|
||||
{{ $stat.Size }} → 30
|
||||
```
|
||||
|
||||
Function [`os.Stat`][Stat] returns [`os.FileInfo`][osfileinfo].
|
||||
For further information of `os.FileInfo`, see [golang page][osfileinfo].
|
||||
|
||||
|
||||
[Stat]: /functions/os.Stat/
|
||||
[osfileinfo]: https://golang.org/pkg/os/#FileInfo
|
|
@ -343,7 +343,7 @@ You'll need a place to store the Hugo executable, your [content][], and the gene
|
|||
3. Find the Windows files near the bottom (they're in alphabetical order, so Windows is last) – download either the 32-bit or 64-bit file depending on whether you have 32-bit or 64-bit Windows. (If you don't know, [see here](https://esupport.trendmicro.com/en-us/home/pages/technical-support/1038680.aspx).)
|
||||
4. Move the ZIP file into your `C:\Hugo\bin` folder.
|
||||
5. Double-click on the ZIP file and extract its contents. Be sure to extract the contents into the same `C:\Hugo\bin` folder – Windows will do this by default unless you tell it to extract somewhere else.
|
||||
6. You should now have three new files: hugo executable (e.g. `hugo_0.18_windows_amd64.exe`), `license.md`, and `readme.md`. (You can delete the ZIP download now.) Rename that hugo executable (`hugo_hugo-version_platform_arch.exe`) to `hugo.exe` for ease of use.
|
||||
6. You should now have three new files: The hugo executable (`hugo.exe`), `LICENSE`, and `README.md`.
|
||||
|
||||
Now you need to add Hugo to your Windows PATH settings:
|
||||
|
||||
|
@ -472,6 +472,14 @@ For the latest version, the Hugo package maintained by [@daftaupe](https://githu
|
|||
|
||||
See the [related discussion in the Hugo forums][redhatforum].
|
||||
|
||||
### Solus
|
||||
|
||||
Solus includes Hugo in its package repository, it may be installed with:
|
||||
|
||||
```
|
||||
sudo eopkg install hugo
|
||||
```
|
||||
|
||||
## OpenBSD
|
||||
|
||||
OpenBSD provides a package for Hugo via `pkg_add`:
|
||||
|
|
|
@ -24,7 +24,7 @@ toc: true
|
|||
## Assumptions
|
||||
|
||||
* You have an account with GitHub, GitLab, or Bitbucket.
|
||||
* You have completed the [Quick Start][] or have Hugo website you are ready to deploy and share with the world.
|
||||
* You have completed the [Quick Start][] or have a Hugo website you are ready to deploy and share with the world.
|
||||
* You do not already have a Netlify account.
|
||||
|
||||
## Create a Netlify account
|
||||
|
@ -59,7 +59,7 @@ Select the repo you want to use for continuous deployment. If you have a large n
|
|||
|
||||
Once selected, you'll be brought to a screen for basic setup. Here you can select the branch you wanted published, your [build command][], and your publish (i.e. deploy) directory. The publish directory should mirror that of what you've set in your [site configuration][config], the default of which is `public`. The following steps assume you are publishing from the `master` branch.
|
||||
|
||||
## Configure Hugo Version in Netlify
|
||||
## Configure Hugo Version in Netlify
|
||||
|
||||
You can [set Hugo version](https://www.netlify.com/blog/2017/04/11/netlify-plus-hugo-0.20-and-beyond/) for your environments in `netlify.toml` file or set `HUGO_VERSION` as a build environment variable in the Netlify console.
|
||||
|
||||
|
@ -80,7 +80,7 @@ For testing:
|
|||
The Netlify configuration file can be a little hard to understand and get right for the different environment, and you may get some inspiration and tips from this site's `netlify.toml`:
|
||||
|
||||
{{< code file="netlify.toml" nocode="true" >}}
|
||||
{{< readfile file="netlify.toml" highlight="toml" >}}
|
||||
{{< readfile file="netlify.toml" highlight="toml" >}}
|
||||
{{< /code >}}
|
||||
|
||||
## Build and Deploy Site
|
||||
|
|
|
@ -27,7 +27,9 @@ The resource will be processed using the project's or theme's own `postcss.confi
|
|||
```
|
||||
|
||||
{{% note %}}
|
||||
Hugo Pipe's PostCSS requires `postcss-cli` javascript package to be installed on the environement along with any PostCSS plugin used.
|
||||
Hugo Pipe's PostCSS requires the `postcss-cli` JavaScript package to be installed in the environment (`npm install -g postcss-cli`) along with any PostCSS plugin(s) used (e.g., `npm install -g autoprefixer`).
|
||||
|
||||
If you are using the Hugo Snap package, PostCSS and plugin(s) need to be installed locally within your Hugo site directory, e.g., `npm install postcss-cli` without the `-g` flag.
|
||||
{{% /note %}}
|
||||
### Options
|
||||
|
||||
|
|
|
@ -43,3 +43,7 @@ includePaths [string slice]
|
|||
{{ $options := (dict "targetPath" "style.css" "outputStyle" "compressed" "enableSourceMap" true "includePaths" (slice "node_modules/myscss")) }}
|
||||
{{ $style := resources.Get "sass/main.scss" | resources.ToCSS $options }}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
Setting `outputStyle` to `compressed` will handle SASS/SCSS files minification better than the more generic [`resources.Minify`]({{< ref "minification">}}).
|
||||
{{% /note %}}
|
||||
|
|
BIN
docs/content/en/news/0.47-relnotes/featured-hugo-47-poster.png
Normal file
After Width: | Height: | Size: 86 KiB |
|
@ -1,12 +1,12 @@
|
|||
|
||||
---
|
||||
date: 2018-08-17
|
||||
title: "0.47"
|
||||
description: "0.47"
|
||||
title: "Output Minification, Live-Reload Fixes and More"
|
||||
description: "Hugo 0.47: Adds minification of rendered output, but is mostly a massive bug fix release."
|
||||
categories: ["Releases"]
|
||||
---
|
||||
|
||||
Hugo `0.47` is named **Hugo Reloaded**. It adds minification support for the final rendered output (run `hugo --minify`), but it is mostly a bug fix release. And most notably, it fixes a set of issues with live-reloading/partial rebuilds when running `hugo server`. Working with bundles should now be a more pleasant experience, to pick one example.
|
||||
Hugo `0.47` is named **Hugo Reloaded**. It adds minification support for the final rendered output (run `hugo --minify`), but it is mostly a bug fix release. And most notably, it fixes a set of issues with live-reloading/partial rebuilds when running `hugo server`. Working with bundles should now be a more pleasant experience, to pick one example.
|
||||
|
||||
This release represents **35 contributions by 6 contributors** to the main Hugo code base.
|
||||
[@bep](https://github.com/bep) leads the Hugo development with a significant amount of contributions, but also a big shoutout to [@satotake](https://github.com/satotake), [@anthonyfok](https://github.com/anthonyfok), and [@coliff](https://github.com/coliff) for their ongoing contributions.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
---
|
||||
date: 2018-08-20
|
||||
title: "0.47.1"
|
||||
description: "0.47.1"
|
||||
title: "Two Bug Fixes"
|
||||
description: "Hugo 0.47.1: Two Bug Fixes"
|
||||
categories: ["Releases"]
|
||||
images:
|
||||
- images/blog/hugo-bug-poster.png
|
||||
|
|
BIN
docs/content/en/news/0.48-relnotes/featured-hugo-48-poster.png
Normal file
After Width: | Height: | Size: 93 KiB |
|
@ -1,17 +1,17 @@
|
|||
|
||||
---
|
||||
date: 2018-08-29
|
||||
title: "0.48"
|
||||
description: "0.48"
|
||||
title: "This One Goes to 11!"
|
||||
description: "With Go 1.11, Hugo finally gets support for variable overwrites in templates!"
|
||||
categories: ["Releases"]
|
||||
---
|
||||
|
||||
Hugo `0.48` is built with the brand new Go 1.11. On the technical side this means that Hugo now uses [Go Modules](https://github.com/golang/go/wiki/Modules) for the build. The big new functional thing in Go 1.11 for Hugo is added support for [variable overwrites](https://github.com/golang/go/issues/10608). This means that you can now do:
|
||||
Hugo `0.48` is built with the brand new Go 1.11. On the technical side this means that Hugo now uses [Go Modules](https://github.com/golang/go/wiki/Modules) for the build. The big new functional thing in Go 1.11 for Hugo is added support for [variable overwrites](https://github.com/golang/go/issues/10608). This means that you can now do this and get the expected result:
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ $var := "Hugo Page" }}
|
||||
{{ if .IsHome }}
|
||||
{{ $var = "Hugo Home" }}
|
||||
{{ $var = "Hugo Home" }}
|
||||
{{ end }}
|
||||
Var is {{ $var }}
|
||||
```
|
||||
|
|
5
docs/content/en/showcase/over/bio.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
The site is built by:
|
||||
|
||||
* [Lauren Waller](https://twitter.com/waller_texas)
|
||||
* [Wayne Ashley Berry](https://twitter.com/waynethebrain)
|
||||
|
BIN
docs/content/en/showcase/over/featured-over.png
Normal file
After Width: | Height: | Size: 230 KiB |
17
docs/content/en/showcase/over/index.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
title: Over
|
||||
date: 2018-09-12
|
||||
description: "Showcase: \"People from all disciplines contribute to our website; Hugo’s single static binary makes that possible.\""
|
||||
siteURL: https://madewithover.com/
|
||||
|
||||
---
|
||||
|
||||
At Over we're into creativity, and technology should not get in the way. We want it to be easy for everyone to create, and Hugo does the same for us. That's one of the reasons many of us are fond of using it.
|
||||
|
||||
People from all disciplines contribute to our website, be it legal documentation, layout and design, recruiting, marketing and of course… engineering. Hugo allows us to do this with as little friction as possible. A lot of this comes down to Hugo being distributed as a single static binary. Copy, paste, run... and you're up and running!
|
||||
|
||||
We use [Wercker](https://www.wercker.com/) for continuous integration and deployments, [GitHub](https://github.com/) for contributing to and writing markdown and [Firebase](https://firebase.google.com/docs/hosting/) for hosting.
|
||||
|
||||
This infrastructure takes all the pressure off our engineers, anyone can contribute to our website. Anyone else can review the changes, and of course anyone with permission can deploy those approved changes as well!
|
||||
|
||||
We're busy working on a few new features for our website, and Hugo continues to deliver above and beyond. We're so happy with the choice we made to use Hugo and to us it has become the de-facto static site generator.
|
|
@ -50,6 +50,7 @@ Your 404.html file can be set to load automatically when a visitor enters a mist
|
|||
* Apache. You can specify `ErrorDocument 404 /404.html` in an `.htaccess` file in the root of your site.
|
||||
* Nginx. You might specify `error_page 404 /404.html;` in your `nginx.conf` file.
|
||||
* Amazon AWS S3. When setting a bucket up for static web serving, you can specify the error file from within the S3 GUI.
|
||||
* Amazon CloudFont. You can specify the page in the Error Pages section in the CloudFont Console. [Details here](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/custom-error-pages.html)
|
||||
* Caddy Server. Using `errors { 404 /404.html }`. [Details here](https://caddyserver.com/docs/errors)
|
||||
|
||||
{{% note %}}
|
||||
|
|
|
@ -104,12 +104,12 @@ And here is the result as [called directly in the Hugo docs][] and rendered for
|
|||
|
||||
{{< readfile file="/content/en/readfiles/testing.txt" markdown="true">}}
|
||||
|
||||
[called directly in the Hugo docs]: https://github.com/gohugoio/hugo/blob/master/docs/content/templates/files.md
|
||||
[called directly in the Hugo docs]: https://github.com/gohugoio/hugoDocs/blob/master/content/en/templates/files.md
|
||||
[dirindex]: https://github.com/gohugoio/hugo/blob/master/docs/layouts/shortcodes/directoryindex.html
|
||||
[osfileinfo]: https://golang.org/pkg/os/#FileInfo
|
||||
[readDir]: /functions/readdir/
|
||||
[readFile]: /functions/readfile/
|
||||
[sc]: /content-management/shortcodes/
|
||||
[sct]: /templates/shortcode-templates/
|
||||
[readfilesource]: https://github.com/gohugoio/hugo/blob/master/
|
||||
[testfile]: https://github.com/gohugoio/hugo/blob/master/docs/testfile
|
||||
[readfilesource]: https://github.com/gohugoio/hugoDocs/blob/master/layouts/shortcodes/readfile.html
|
||||
[testfile]: https://github.com/gohugoio/hugoDocs/blob/master/content/en/readfiles/testing.txt
|
||||
|
|
|
@ -20,26 +20,39 @@ toc: true
|
|||
---
|
||||
|
||||
{{% note %}}
|
||||
The following is only a primer on Go templates. For an in-depth look into Go templates, check the official [Go docs](http://golang.org/pkg/html/template/).
|
||||
The following is only a primer on Go Templates. For an in-depth look into Go Templates, check the official [Go docs](http://golang.org/pkg/html/template/).
|
||||
{{% /note %}}
|
||||
|
||||
Go templates provide an extremely simple template language that adheres to the belief that only the most basic of logic belongs in the template or view layer.
|
||||
Go Templates provide an extremely simple template language that adheres to the belief that only the most basic of logic belongs in the template or view layer.
|
||||
|
||||
{{< youtube gnJbPO-GFIw >}}
|
||||
|
||||
## Basic Syntax
|
||||
|
||||
Go templates are HTML files with the addition of [variables][variables] and [functions][functions]. Go template variables and functions are accessible within `{{ }}`.
|
||||
Go Templates are HTML files with the addition of [variables][variables] and [functions][functions]. Go Template variables and functions are accessible within `{{ }}`.
|
||||
|
||||
### Access a Predefined Variable
|
||||
|
||||
```
|
||||
{{ foo }}
|
||||
A _predefined variable_ could be a variable already existing in the
|
||||
current scope (like the `.Title` example in the [Variables]({{< relref
|
||||
"#variables" >}}) section below) or a custom variable (like the
|
||||
`$address` example in that same section).
|
||||
|
||||
|
||||
```go-html-template
|
||||
{{ .Title }}
|
||||
{{ $address }}
|
||||
```
|
||||
|
||||
Parameters for functions are separated using spaces. The following example calls the `add` function with inputs of `1` and `2`:
|
||||
Parameters for functions are separated using spaces. The general syntax is:
|
||||
|
||||
```
|
||||
{{ FUNCTION ARG1 ARG2 .. }}
|
||||
```
|
||||
|
||||
The following example calls the `add` function with inputs of `1` and `2`:
|
||||
|
||||
```go-html-template
|
||||
{{ add 1 2 }}
|
||||
```
|
||||
|
||||
|
@ -47,64 +60,88 @@ Parameters for functions are separated using spaces. The following example calls
|
|||
|
||||
Accessing the Page Parameter `bar` defined in a piece of content's [front matter][].
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ .Params.bar }}
|
||||
```
|
||||
|
||||
#### Parentheses Can be Used to Group Items Together
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ if or (isset .Params "alt") (isset .Params "caption") }} Caption {{ end }}
|
||||
```
|
||||
|
||||
## Variables
|
||||
## Variables {#variables}
|
||||
|
||||
Each Go template gets a data object. In Hugo, each template is passed a `Page`. See [variables][] for more information.
|
||||
Each Go Template gets a data object. In Hugo, each template is passed
|
||||
a `Page`. In the below example, `.Title` is one of the elements
|
||||
accessible in that [`Page` variable][pagevars].
|
||||
|
||||
This is how you access a `Page` variable from a template:
|
||||
With the `Page` being the default scope of a template, the `Title`
|
||||
element in current scope (`.` -- "the **dot**") is accessible simply
|
||||
by the dot-prefix (`.Title`):
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
<title>{{ .Title }}</title>
|
||||
```
|
||||
|
||||
Values can also be stored in custom variables and referenced later:
|
||||
|
||||
```
|
||||
{{ $address := "123 Main St."}}
|
||||
{{% note %}}
|
||||
The custom variables need to be prefixed with `$`.
|
||||
{{% /note %}}
|
||||
|
||||
```go-html-template
|
||||
{{ $address := "123 Main St." }}
|
||||
{{ $address }}
|
||||
```
|
||||
|
||||
{{% warning %}}
|
||||
Variables defined inside `if` conditionals and similar are not visible on the outside. See [https://github.com/golang/go/issues/10608](https://github.com/golang/go/issues/10608).
|
||||
For Hugo v0.47 and older versions, variables defined inside `if`
|
||||
conditionals and similar are not visible on the outside.
|
||||
See [https://github.com/golang/go/issues/10608](https://github.com/golang/go/issues/10608).
|
||||
|
||||
Hugo has created a workaround for this issue in [Scratch](/functions/scratch).
|
||||
|
||||
{{% /warning %}}
|
||||
|
||||
For **Hugo v0.48** and newer, variables can be re-defined using the
|
||||
new `=` operator (new in Go 1.11).
|
||||
|
||||
Below example will work only in these newer Hugo versions. The example
|
||||
prints "Var is Hugo Home" on the home page, and "Var is Hugo Page" on
|
||||
all other pages:
|
||||
|
||||
```go-html-template
|
||||
{{ $var := "Hugo Page" }}
|
||||
{{ if .IsHome }}
|
||||
{{ $var = "Hugo Home" }}
|
||||
{{ end }}
|
||||
Var is {{ $var }}
|
||||
```
|
||||
|
||||
## Functions
|
||||
|
||||
Go templates only ship with a few basic functions but also provide a mechanism for applications to extend the original set.
|
||||
Go Templates only ship with a few basic functions but also provide a mechanism for applications to extend the original set.
|
||||
|
||||
[Hugo template functions][functions] provide additional functionality specific to building websites. Functions are called by using their name followed by the required parameters separated by spaces. Template functions cannot be added without recompiling Hugo.
|
||||
|
||||
### Example 1: Adding Numbers
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ add 1 2 }}
|
||||
=> 3
|
||||
<!-- prints 3 -->
|
||||
```
|
||||
|
||||
### Example 2: Comparing Numbers
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ lt 1 2 }}
|
||||
=> true (i.e., since 1 is less than 2)
|
||||
<!-- prints true (i.e., since 1 is less than 2) -->
|
||||
```
|
||||
|
||||
Note that both examples make use of Go template's [math functions][].
|
||||
Note that both examples make use of Go Template's [math functions][].
|
||||
|
||||
{{% note "Additional Boolean Operators" %}}
|
||||
There are more boolean operators than those listed in the Hugo docs in the [Go template documentation](http://golang.org/pkg/text/template/#hdr-Functions).
|
||||
There are more boolean operators than those listed in the Hugo docs in the [Go Template documentation](http://golang.org/pkg/text/template/#hdr-Functions).
|
||||
{{% /note %}}
|
||||
|
||||
## Includes
|
||||
|
@ -124,116 +161,174 @@ within Hugo.
|
|||
The [`partial`][partials] function is used to include *partial* templates using
|
||||
the syntax `{{ partial "<PATH>/<PARTIAL>.<EXTENSION>" . }}`.
|
||||
|
||||
Example:
|
||||
Example of including a `layouts/partials/header.html` partial:
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ partial "header.html" . }}
|
||||
```
|
||||
|
||||
### Template
|
||||
|
||||
The `template` function was used to include *partial* templates in much older
|
||||
Hugo versions. Now it is still useful for calling [*internal*
|
||||
templates][internal_templates]:
|
||||
The `template` function was used to include *partial* templates
|
||||
in much older Hugo versions. Now it useful only for calling
|
||||
[*internal* templates][internal_templates]. The syntax is `{{ template
|
||||
"_internal/<TEMPLATE>.<EXTENSION>" . }}`.
|
||||
|
||||
```
|
||||
{{% note %}}
|
||||
The available **internal** templates can be found
|
||||
[here](https://github.com/gohugoio/hugo/tree/master/tpl/tplimpl/embedded/templates).
|
||||
{{% /note %}}
|
||||
|
||||
Example of including the internal `opengraph.html` template:
|
||||
|
||||
```go-html-template
|
||||
{{ template "_internal/opengraph.html" . }}
|
||||
```
|
||||
|
||||
## Logic
|
||||
|
||||
Go templates provide the most basic iteration and conditional logic.
|
||||
Go Templates provide the most basic iteration and conditional logic.
|
||||
|
||||
### Iteration
|
||||
|
||||
Just like in Go, the Go templates make heavy use of `range` to iterate over
|
||||
a map, array, or slice. The following are different examples of how to use
|
||||
range.
|
||||
The Go Templates make heavy use of `range` to iterate over a _map_,
|
||||
_array_, or _slice_. The following are different examples of how to
|
||||
use `range`.
|
||||
|
||||
#### Example 1: Using Context
|
||||
#### Example 1: Using Context (`.`)
|
||||
|
||||
```
|
||||
{{ range array }}
|
||||
{{ . }}
|
||||
```go-html-template
|
||||
{{ range $array }}
|
||||
{{ . }} <!-- The . represents an element in $array -->
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
#### Example 2: Declaring Value => Variable name
|
||||
#### Example 2: Declaring a variable name for an array element's value
|
||||
|
||||
```
|
||||
{{range $element := array}}
|
||||
{{ $element }}
|
||||
```go-html-template
|
||||
{{ range $elem_val := $array }}
|
||||
{{ $elem_val }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
#### Example 3: Declaring Key-Value Variable Name
|
||||
#### Example 3: Declaring variable names for an array element's index _and_ value
|
||||
|
||||
For an array or slice, the first declared variable will map to each
|
||||
element's index.
|
||||
|
||||
```go-html-template
|
||||
{{ range $elem_index, $elem_val := $array }}
|
||||
{{ $elem_index }} -- {{ $elem_val }}
|
||||
{{ end }}
|
||||
```
|
||||
{{range $index, $element := array}}
|
||||
{{ $index }}
|
||||
{{ $element }}
|
||||
|
||||
#### Example 4: Declaring variable names for a map element's key _and_ value
|
||||
|
||||
For a map, the first declared variable will map to each map element's
|
||||
key.
|
||||
|
||||
```go-html-template
|
||||
{{ range $elem_key, $elem_val := $map }}
|
||||
{{ $elem_key }} -- {{ $elem_val }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
### Conditionals
|
||||
|
||||
`if`, `else`, `with`, `or`, and `and` provide the framework for handling conditional logic in Go Templates. Like `range`, each statement is closed with an `{{end}}`.
|
||||
`if`, `else`, `with`, `or`, and `and` provide the framework for handling conditional logic in Go Templates. Like `range`, each statement is closed with an `{{ end }}`.
|
||||
|
||||
Go Templates treat the following values as false:
|
||||
Go Templates treat the following values as **false**:
|
||||
|
||||
* false
|
||||
* 0
|
||||
* any zero-length array, slice, map, or string
|
||||
- `false` (boolean)
|
||||
- 0 (integer)
|
||||
- any zero-length array, slice, map, or string
|
||||
|
||||
#### Example 1: `if`
|
||||
#### Example 1: `with`
|
||||
|
||||
```
|
||||
{{ if isset .Params "title" }}<h4>{{ index .Params "title" }}</h4>{{ end }}
|
||||
```
|
||||
It is common to write "if something exists, do this" kind of
|
||||
statements using `with`.
|
||||
|
||||
#### Example 2: `if` … `else`
|
||||
{{% note %}}
|
||||
`with` rebinds the context `.` within its scope (just like in `range`).
|
||||
{{% /note %}}
|
||||
|
||||
```
|
||||
{{ if isset .Params "alt" }}
|
||||
{{ index .Params "alt" }}
|
||||
{{else}}
|
||||
{{ index .Params "caption" }}
|
||||
It skips the block if the variable is absent, or if it evaluates to
|
||||
"false" as explained above.
|
||||
|
||||
```go-html-template
|
||||
{{ with .Params.title }}
|
||||
<h4>{{ . }}</h4>
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
#### Example 3: `and` & `or`
|
||||
#### Example 2: `with` .. `else`
|
||||
|
||||
```
|
||||
{{ if and (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr")}}
|
||||
```
|
||||
Below snippet uses the "description" front-matter parameter's value if
|
||||
set, else uses the default `.Summary` [Page variable][pagevars]:
|
||||
|
||||
#### Example 4: `with`
|
||||
|
||||
An alternative way of writing "`if`" and then referencing the same value
|
||||
is to use "`with`" instead. `with` rebinds the context `.` within its scope
|
||||
and skips the block if the variable is absent.
|
||||
|
||||
The first example above could be simplified as:
|
||||
|
||||
```
|
||||
{{ with .Params.title }}<h4>{{ . }}</h4>{{ end }}
|
||||
```
|
||||
|
||||
#### Example 5: `if` … `else if`
|
||||
|
||||
```
|
||||
{{ if isset .Params "alt" }}
|
||||
{{ index .Params "alt" }}
|
||||
{{ else if isset .Params "caption" }}
|
||||
{{ index .Params "caption" }}
|
||||
```go-html-template
|
||||
{{ with .Param "description" }}
|
||||
{{ . }}
|
||||
{{ else }}
|
||||
{{ .Summary }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
See the [`.Param` function][param].
|
||||
|
||||
#### Example 3: `if`
|
||||
|
||||
An alternative (and a more verbose) way of writing `with` is using
|
||||
`if`. Here, the `.` does not get rebinded.
|
||||
|
||||
Below example is "Example 1" rewritten using `if`:
|
||||
|
||||
```go-html-template
|
||||
{{ if isset .Params "title" }}
|
||||
<h4>{{ index .Params "title" }}</h4>
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
#### Example 4: `if` .. `else`
|
||||
|
||||
Below example is "Example 2" rewritten using `if` .. `else`, and using
|
||||
[`isset` function][isset] + `.Params` variable (different from the
|
||||
[`.Param` **function**][param]) instead:
|
||||
|
||||
```go-html-template
|
||||
{{ if (isset .Params "description") }}
|
||||
{{ index .Params "description" }}
|
||||
{{ else }}
|
||||
{{ .Summary }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
#### Example 5: `if` .. `else if` .. `else`
|
||||
|
||||
Unlike `with`, `if` can contain `else if` clauses too.
|
||||
|
||||
```go-html-template
|
||||
{{ if (isset .Params "description") }}
|
||||
{{ index .Params "description" }}
|
||||
{{ else if (isset .Params "summary") }}
|
||||
{{ index .Params "summary" }}
|
||||
{{ else }}
|
||||
{{ .Summary }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
#### Example 6: `and` & `or`
|
||||
|
||||
```go-html-template
|
||||
{{ if (and (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr")) }}
|
||||
```
|
||||
|
||||
## Pipes
|
||||
|
||||
One of the most powerful components of Go templates is the ability to stack actions one after another. This is done by using pipes. Borrowed from Unix pipes, the concept is simple: each pipeline's output becomes the input of the following pipe.
|
||||
One of the most powerful components of Go Templates is the ability to stack actions one after another. This is done by using pipes. Borrowed from Unix pipes, the concept is simple: each pipeline's output becomes the input of the following pipe.
|
||||
|
||||
Because of the very simple syntax of Go templates, the pipe is essential to being able to chain together function calls. One limitation of the pipes is that they can only work with a single value and that value becomes the last parameter of the next pipeline.
|
||||
Because of the very simple syntax of Go Templates, the pipe is essential to being able to chain together function calls. One limitation of the pipes is that they can only work with a single value and that value becomes the last parameter of the next pipeline.
|
||||
|
||||
A few simple examples should help convey how to use the pipe.
|
||||
|
||||
|
@ -241,26 +336,26 @@ A few simple examples should help convey how to use the pipe.
|
|||
|
||||
The following two examples are functionally the same:
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ shuffle (seq 1 5) }}
|
||||
```
|
||||
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ (seq 1 5) | shuffle }}
|
||||
```
|
||||
|
||||
### Example 2: `index`
|
||||
|
||||
The following accesses the page parameter called "disqus_url" and escapes the HTML. This example also uses the [`index` function][index], which is built into Go templates:
|
||||
The following accesses the page parameter called "disqus_url" and escapes the HTML. This example also uses the [`index` function][index], which is built into Go Templates:
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ index .Params "disqus_url" | html }}
|
||||
```
|
||||
|
||||
### Example 3: `or` with `isset`
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ if or (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr") }}
|
||||
Stuff Here
|
||||
{{ end }}
|
||||
|
@ -268,7 +363,7 @@ Stuff Here
|
|||
|
||||
Could be rewritten as
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ if isset .Params "caption" | or isset .Params "title" | or isset .Params "attr" }}
|
||||
Stuff Here
|
||||
{{ end }}
|
||||
|
@ -278,7 +373,7 @@ Stuff Here
|
|||
|
||||
By default, Go Templates remove HTML comments from output. This has the unfortunate side effect of removing Internet Explorer conditional comments. As a workaround, use something like this:
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ "<!--[if lt IE 9]>" | safeHTML }}
|
||||
<script src="html5shiv.js"></script>
|
||||
{{ "<![endif]-->" | safeHTML }}
|
||||
|
@ -286,13 +381,24 @@ By default, Go Templates remove HTML comments from output. This has the unfortun
|
|||
|
||||
Alternatively, you can use the backtick (`` ` ``) to quote the IE conditional comments, avoiding the tedious task of escaping every double quotes (`"`) inside, as demonstrated in the [examples](http://golang.org/pkg/text/template/#hdr-Examples) in the Go text/template documentation:
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ `<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"><![endif]-->` | safeHTML }}
|
||||
```
|
||||
|
||||
## Context (aka "the dot")
|
||||
## Context (aka "the dot") {#the-dot}
|
||||
|
||||
The most easily overlooked concept to understand about Go templates is that `{{ . }}` always refers to the current context. In the top level of your template, this will be the data set made available to it. Inside of an iteration, however, it will have the value of the current item in the loop; i.e., `{{ . }}` will no longer refer to the data available to the entire page. If you need to access page-level data (e.g., page params set in front matter) from within the loop, you will likely want to do one of the following:
|
||||
The most easily overlooked concept to understand about Go Templates is
|
||||
that `{{ . }}` always refers to the **current context**.
|
||||
|
||||
- In the top level of your template, this will be the data set made
|
||||
available to it.
|
||||
- Inside of an iteration, however, it will have the value of the
|
||||
current item in the loop; i.e., `{{ . }}` will no longer refer to
|
||||
the data available to the entire page.
|
||||
|
||||
If you need to access page-level data (e.g., page params set in front
|
||||
matter) from within the loop, you will likely want to do one of the
|
||||
following:
|
||||
|
||||
### 1. Define a Variable Independent of Context
|
||||
|
||||
|
@ -337,9 +443,9 @@ The built-in magic of `$` would cease to work if someone were to mischievously r
|
|||
|
||||
Go 1.6 includes the ability to trim the whitespace from either side of a Go tag by including a hyphen (`-`) and space immediately beside the corresponding `{{` or `}}` delimiter.
|
||||
|
||||
For instance, the following Go template will include the newlines and horizontal tab in its HTML output:
|
||||
For instance, the following Go Template will include the newlines and horizontal tab in its HTML output:
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
<div>
|
||||
{{ .Title }}
|
||||
</div>
|
||||
|
@ -347,7 +453,7 @@ For instance, the following Go template will include the newlines and horizontal
|
|||
|
||||
Which will output:
|
||||
|
||||
```
|
||||
```html
|
||||
<div>
|
||||
Hello, World!
|
||||
</div>
|
||||
|
@ -355,7 +461,7 @@ Which will output:
|
|||
|
||||
Leveraging the `-` in the following example will remove the extra white space surrounding the `.Title` variable and remove the newline:
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
<div>
|
||||
{{- .Title -}}
|
||||
</div>
|
||||
|
@ -363,11 +469,11 @@ Leveraging the `-` in the following example will remove the extra white space su
|
|||
|
||||
Which then outputs:
|
||||
|
||||
```
|
||||
```html
|
||||
<div>Hello, World!</div>
|
||||
```
|
||||
|
||||
Go considers the following characters whitespace:
|
||||
Go considers the following characters _whitespace_:
|
||||
|
||||
* <kbd>space</kbd>
|
||||
* horizontal <kbd>tab</kbd>
|
||||
|
@ -378,13 +484,13 @@ Go considers the following characters whitespace:
|
|||
|
||||
In order to keep your templates organized and share information throughout your team, you may want to add comments to your templates. There are two ways to do that with Hugo.
|
||||
|
||||
### Go templates comments
|
||||
### Go Templates comments
|
||||
|
||||
Go templates support `{{/*` and `*/}}` to open and close a comment block. Nothing within that block will be rendered.
|
||||
Go Templates support `{{/*` and `*/}}` to open and close a comment block. Nothing within that block will be rendered.
|
||||
|
||||
For example:
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
Bonsoir, {{/* {{ add 0 + 2 }} */}}Eliott.
|
||||
```
|
||||
|
||||
|
@ -394,24 +500,24 @@ Will render `Bonsoir, Eliott.`, and not care about the syntax error (`add 0 + 2`
|
|||
|
||||
If you need to produce HTML comments from your templates, take a look at the [Internet Explorer conditional comments](#ie-conditional-comments) example. If you need variables to construct such HTML comments, just pipe `printf` to `safeHTML`. For example:
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ printf "<!-- Our website is named: %s -->" .Site.Title | safeHTML }}
|
||||
```
|
||||
|
||||
#### HTML comments containing Go templates
|
||||
#### HTML comments containing Go Templates
|
||||
|
||||
HTML comments are by default stripped, but their content is still evaluated. That means that although the HTML comment will never render any content to the final HTML pages, code contained within the comment may fail the build process.
|
||||
|
||||
{{% note %}}
|
||||
Do **not** try to comment out Go template code using HTML comments.
|
||||
Do **not** try to comment out Go Template code using HTML comments.
|
||||
{{% /note %}}
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
<!-- {{ $author := "Emma Goldman" }} was a great woman. -->
|
||||
{{ $author }}
|
||||
```
|
||||
|
||||
The templating engine will strip the content within the HTML comment, but will first evaluate any Go template code if present within. So the above example will render `Emma Goldman`, as the `$author` variable got evaluated in the HTML comment. But the build would have failed if that code in the HTML comment had an error.
|
||||
The templating engine will strip the content within the HTML comment, but will first evaluate any Go Template code if present within. So the above example will render `Emma Goldman`, as the `$author` variable got evaluated in the HTML comment. But the build would have failed if that code in the HTML comment had an error.
|
||||
|
||||
## Hugo Parameters
|
||||
|
||||
|
@ -423,7 +529,7 @@ You can provide variables to be used by templates in individual content's [front
|
|||
|
||||
An example of this is used in the Hugo docs. Most of the pages benefit from having the table of contents provided, but sometimes the table of contents doesn't make a lot of sense. We've defined a `notoc` variable in our front matter that will prevent a table of contents from rendering when specifically set to `true`.
|
||||
|
||||
Here is the example front matter:
|
||||
Here is the example front matter (YAML):
|
||||
|
||||
```
|
||||
---
|
||||
|
@ -447,7 +553,7 @@ Here is an example of corresponding code that could be used inside a `toc.html`
|
|||
{{.TableOfContents}}
|
||||
</aside>
|
||||
<a href="#" id="toc-toggle"></a>
|
||||
{{end}}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
We want the *default* behavior to be for pages to include a TOC unless otherwise specified. This template checks to make sure that the `notoc:` field in this page's front matter is not `true`.
|
||||
|
@ -467,31 +573,33 @@ params:
|
|||
|
||||
Within a footer layout, you might then declare a `<footer>` that is only rendered if the `copyrighthtml` parameter is provided. If it *is* provided, you will then need to declare the string is safe to use via the [`safeHTML` function][safehtml] so that the HTML entity is not escaped again. This would let you easily update just your top-level config file each January 1st, instead of hunting through your templates.
|
||||
|
||||
```
|
||||
{{if .Site.Params.copyrighthtml}}<footer>
|
||||
<div class="text-center">{{.Site.Params.CopyrightHTML | safeHTML}}</div>
|
||||
</footer>{{end}}
|
||||
```go-html-template
|
||||
{{ if .Site.Params.copyrighthtml }}
|
||||
<footer>
|
||||
<div class="text-center">{{.Site.Params.CopyrightHTML | safeHTML}}</div>
|
||||
</footer>
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
An alternative way of writing the "`if`" and then referencing the same value is to use [`with`][with] instead. `with` rebinds the context (`.`) within its scope and skips the block if the variable is absent:
|
||||
|
||||
{{< code file="layouts/partials/twitter.html" >}}
|
||||
{{with .Site.Params.twitteruser}}
|
||||
<div>
|
||||
<a href="https://twitter.com/{{.}}" rel="author">
|
||||
<img src="/images/twitter.png" width="48" height="48" title="Twitter: {{.}}" alt="Twitter"></a>
|
||||
</div>
|
||||
{{end}}
|
||||
{{ with .Site.Params.twitteruser }}
|
||||
<div>
|
||||
<a href="https://twitter.com/{{.}}" rel="author">
|
||||
<img src="/images/twitter.png" width="48" height="48" title="Twitter: {{.}}" alt="Twitter"></a>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
Finally, you can pull "magic constants" out of your layouts as well. The following uses the [`first`][first] function, as well as the [`.RelPermalink`][relpermalink] page variable and the [`.Site.Pages`][sitevars] site variable.
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
<nav>
|
||||
<h1>Recent Posts</h1>
|
||||
<ul>
|
||||
{{- range first .Site.Params.SidebarRecentLimit .Site.Pages -}}
|
||||
<li><a href="{{.RelPermalink}}">{{.Title}}</a></li>
|
||||
<li><a href="{{.RelPermalink}}">{{.Title}}</a></li>
|
||||
{{- end -}}
|
||||
</ul>
|
||||
</nav>
|
||||
|
@ -505,16 +613,16 @@ Go allows you to do more than what's shown here. Using Hugo's [`where` function]
|
|||
<h4>Upcoming Events</h4>
|
||||
<ul class="upcoming-events">
|
||||
{{ range where .Pages.ByDate "Section" "events" }}
|
||||
{{ if ge .Date.Unix .Now.Unix }}
|
||||
<li>
|
||||
<!-- add span for event type -->
|
||||
<span>{{ .Type | title }} —</span>
|
||||
{{ .Title }} on
|
||||
<!-- add span for event date -->
|
||||
<span>{{ .Date.Format "2 January at 3:04pm" }}</span>
|
||||
at {{ .Params.place }}
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ if ge .Date.Unix now.Unix }}
|
||||
<li>
|
||||
<!-- add span for event type -->
|
||||
<span>{{ .Type | title }} —</span>
|
||||
{{ .Title }} on
|
||||
<!-- add span for event date -->
|
||||
<span>{{ .Date.Format "2 January at 3:04pm" }}</span>
|
||||
at {{ .Params.place }}
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{< /code >}}
|
||||
|
@ -535,7 +643,10 @@ Go allows you to do more than what's shown here. Using Hugo's [`where` function]
|
|||
[relpermalink]: /variables/page/
|
||||
[safehtml]: /functions/safehtml/
|
||||
[sitevars]: /variables/site/
|
||||
[pagevars]: /variables/page/
|
||||
[variables]: /variables/ "See the full extent of page-, site-, and other variables that Hugo make available to you in your templates."
|
||||
[where]: /functions/where/
|
||||
[with]: /functions/with/
|
||||
[godocsindex]: http://golang.org/pkg/text/template/ "Godocs page for index function"
|
||||
[param]: /functions/param/
|
||||
[isset]: /functions/isset/
|
||||
|
|
|
@ -66,7 +66,7 @@ A Taxonomy is a `map[string]WeightedPages`.
|
|||
|
||||
Since Maps are unordered, an OrderedTaxonomy is a special structure that has a defined order.
|
||||
|
||||
```
|
||||
```go
|
||||
[]struct {
|
||||
Name string
|
||||
WeightedPages WeightedPages
|
||||
|
@ -91,7 +91,7 @@ Each element of the slice has:
|
|||
|
||||
WeightedPages is simply a slice of WeightedPage.
|
||||
|
||||
```
|
||||
```go
|
||||
type WeightedPages []WeightedPage
|
||||
```
|
||||
|
||||
|
@ -103,16 +103,16 @@ type WeightedPages []WeightedPage
|
|||
|
||||
## Displaying custom metadata in Taxonomy Terms Templates
|
||||
|
||||
If you need to display custom metadata for each taxonomy term, you will need to create a page for that term at `/content/<TAXONOMY>/<TERM>/_index.md` and add your metadata in it's front matter, [as explained in the taxonomies documentation](/content-management/taxonomies/#add-custom-meta-data-to-a-taxonomy-term). Based on the Actors taxonomy example shown there, within your taxonomy terms template, you may access your custom fields by iterating through the variable `.Pages` as such:
|
||||
If you need to display custom metadata for each taxonomy term, you will need to create a page for that term at `/content/<TAXONOMY>/<TERM>/_index.md` and add your metadata in its front matter, [as explained in the taxonomies documentation](/content-management/taxonomies/#add-custom-meta-data-to-a-taxonomy-term). Based on the Actors taxonomy example shown there, within your taxonomy terms template, you may access your custom fields by iterating through the variable `.Pages` as such:
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
<ul>
|
||||
{{ range .Pages }}
|
||||
<li>
|
||||
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
||||
{{ .Params.wikipedia }}
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ range .Pages }}
|
||||
<li>
|
||||
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
||||
{{ .Params.wikipedia }}
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
|
@ -124,34 +124,46 @@ Taxonomies can be ordered by either alphabetical key or by the number of content
|
|||
|
||||
### Order Alphabetically Example
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
<ul>
|
||||
{{ $data := .Data }}
|
||||
{{ range $key, $value := .Data.Terms.Alphabetical }}
|
||||
<li><a href="{{ $.Site.LanguagePrefix }}/{{ $data.Plural }}/{{ $value.Name | urlize }}"> {{ $value.Name }} </a> {{ $value.Count }} </li>
|
||||
{{ end }}
|
||||
{{ $type := .Type }}
|
||||
{{ range $key, $value := .Data.Terms.Alphabetical }}
|
||||
{{ $name := .Name }}
|
||||
{{ $count := .Count }}
|
||||
{{ with $.Site.GetPage (printf "/%s/%s" $type $name) }}
|
||||
<li><a href="{{ .Permalink }}">{{ $name }}</a> {{ $count }}</li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
### Order by Popularity Example
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
<ul>
|
||||
{{ $data := .Data }}
|
||||
{{ range $key, $value := .Data.Terms.ByCount }}
|
||||
<li><a href="{{ $.Site.LanguagePrefix }}/{{ $data.Plural }}/{{ $value.Name | urlize }}"> {{ $value.Name }} </a> {{ $value.Count }} </li>
|
||||
{{ end }}
|
||||
{{ $type := .Type }}
|
||||
{{ range $key, $value := .Data.Terms.ByCount }}
|
||||
{{ $name := .Name }}
|
||||
{{ $count := .Count }}
|
||||
{{ with $.Site.GetPage (printf "/%s/%s" $type $name) }}
|
||||
<li><a href="{{ .Permalink }}">{{ $name }}</a> {{ $count }}</li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
### Order by Least Popular Example
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
<ul>
|
||||
{{ $data := .Data }}
|
||||
{{ range $key, $value := .Data.Terms.ByCount.Reverse }}
|
||||
<li><a href="{{ $.Site.LanguagePrefix }}/{{ $data.Plural }}/{{ $value.Name | urlize }}"> {{ $value.Name }} </a> {{ $value.Count }} </li>
|
||||
{{ end }}
|
||||
{{ $type := .Type }}
|
||||
{{ range $key, $value := .Data.Terms.ByCount.Reverse }}
|
||||
{{ $name := .Name }}
|
||||
{{ $count := .Count }}
|
||||
{{ with $.Site.GetPage (printf "/%s/%s" $type $name) }}
|
||||
<li><a href="{{ .Permalink }}">{{ $name }}</a> {{ $count }}</li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
|
@ -221,11 +233,15 @@ Because we are leveraging the front matter system to define taxonomies for conte
|
|||
|
||||
### Example: List Tags in a Single Page Template
|
||||
|
||||
```
|
||||
<ul id="tags">
|
||||
{{ range .Params.tags }}
|
||||
<li><a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</a> </li>
|
||||
{{ end }}
|
||||
```go-html-template
|
||||
{{ $taxo := "tags" }} <!-- Use the plural form here -->
|
||||
<ul id="{{ $taxo }}">
|
||||
{{ range .Param $taxo }}
|
||||
{{ $name := . }}
|
||||
{{ with $.Site.GetPage (printf "/%s/%s" $taxo $name) }}
|
||||
<li><a href="{{ .Permalink }}">{{ $name }}</a></li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
|
@ -235,10 +251,16 @@ To list such taxonomies, use the following:
|
|||
|
||||
### Example: Comma-delimit Tags in a Single Page Template
|
||||
|
||||
```
|
||||
{{ if .Params.directors }}
|
||||
<strong>Director{{ if gt (len .Params.directors) 1 }}s{{ end }}:</strong>
|
||||
{{ range $index, $director := .Params.directors }}{{ if gt $index 0 }}, {{ end }}<a href="{{ "directors/" | relURL }}{{ . | urlize }}">{{ . }}</a>{{ end }}
|
||||
```go-html-template
|
||||
{{ $taxo := "directors" }} <!-- Use the plural form here -->
|
||||
{{ with .Param $taxo }}
|
||||
<strong>Director{{ if gt (len .) 1 }}s{{ end }}:</strong>
|
||||
{{ range $index, $director := . }}
|
||||
{{- if gt $index 0 }}, {{ end -}}
|
||||
{{ with $.Site.GetPage (printf "/%s/%s" $taxo $director) -}}
|
||||
<a href="{{ .Permalink }}">{{ $director }}</a>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
|
@ -250,11 +272,11 @@ If you are using a taxonomy for something like a series of posts, you can list i
|
|||
|
||||
### Example: Showing Content in Same Series
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
<ul>
|
||||
{{ range .Site.Taxonomies.series.golang }}
|
||||
<li><a href="{{ .Page.RelPermalink }}">{{ .Page.Title }}</a></li>
|
||||
{{ end }}
|
||||
{{ range .Site.Taxonomies.series.golang }}
|
||||
<li><a href="{{ .Page.RelPermalink }}">{{ .Page.Title }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
|
@ -264,14 +286,14 @@ This would be very useful in a sidebar as “featured content”. You could even
|
|||
|
||||
### Example: Grouping "Featured" Content
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
<section id="menu">
|
||||
<ul>
|
||||
{{ range $key, $taxonomy := .Site.Taxonomies.featured }}
|
||||
<li> {{ $key }} </li>
|
||||
<li>{{ $key }}</li>
|
||||
<ul>
|
||||
{{ range $taxonomy.Pages }}
|
||||
<li hugo-nav="{{ .RelPermalink}}"><a href="{{ .Permalink}}"> {{ .LinkTitle }} </a> </li>
|
||||
<li hugo-nav="{{ .RelPermalink}}"><a href="{{ .Permalink}}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
|
@ -287,13 +309,15 @@ This may take the form of a tag cloud, a menu, or simply a list.
|
|||
|
||||
The following example displays all terms in a site's tags taxonomy:
|
||||
|
||||
### Example: List All Site Tags
|
||||
### Example: List All Site Tags {#example-list-all-site-tags}
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
<ul id="all-tags">
|
||||
{{ range $name, $taxonomy := .Site.Taxonomies.tags }}
|
||||
<li><a href="{{ "/tags/" | relLangURL }}{{ $name | urlize }}">{{ $name }}</a></li>
|
||||
{{ end }}
|
||||
{{ range $name, $taxonomy := .Site.Taxonomies.tags }}
|
||||
{{ with $.Site.GetPage (printf "/tags/%s" $name) }}
|
||||
<li><a href="{{ .Permalink }}">{{ $name }}</a></li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
|
@ -303,40 +327,47 @@ This example will list all taxonomies and their terms, as well as all the conten
|
|||
|
||||
{{< code file="layouts/partials/all-taxonomies.html" download="all-taxonomies.html" download="all-taxonomies.html" >}}
|
||||
<section>
|
||||
<ul id="all-taxonomies">
|
||||
{{ range $taxonomyname, $taxonomy := .Site.Taxonomies }}
|
||||
<li><a href="{{ "/" | relLangURL}}{{ $taxonomyname | urlize }}">{{ $taxonomyname }}</a>
|
||||
<ul>
|
||||
{{ range $key, $value := $taxonomy }}
|
||||
<li> {{ $key }} </li>
|
||||
<ul>
|
||||
{{ range $value.Pages }}
|
||||
<li hugo-nav="{{ .RelPermalink}}"><a href="{{ .Permalink}}"> {{ .LinkTitle }} </a> </li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
<ul id="all-taxonomies">
|
||||
{{ range $taxonomy_term, $taxonomy := .Site.Taxonomies }}
|
||||
{{ with $.Site.GetPage (printf "/%s" $taxonomy_term) }}
|
||||
<li><a href="{{ .Permalink }}">{{ $taxonomy_term }}</a>
|
||||
<ul>
|
||||
{{ range $key, $value := $taxonomy }}
|
||||
<li>{{ $key }}</li>
|
||||
<ul>
|
||||
{{ range $value.Pages }}
|
||||
<li hugo-nav="{{ .RelPermalink}}">
|
||||
<a href="{{ .Permalink}}">{{ .LinkTitle }}</a>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
</section>
|
||||
{{< /code >}}
|
||||
|
||||
## `.Site.GetPage` for Taxonomies
|
||||
|
||||
Because taxonomies are lists, the [`.GetPage` function][getpage] can be used to get all the pages associated with a particular taxonomy term using a terse syntax. The following ranges over the full list of tags on your site and links to each of the individual taxonomy pages for each term without having to use the more fragile URL construction of the "List All Site Tags" example above:
|
||||
Because taxonomies are lists, the [`.GetPage` function][getpage] can be used to get all the pages associated with a particular taxonomy term using a terse syntax. The following ranges over the full list of tags on your site and links to each of the individual taxonomy pages for each term without having to use the more fragile URL construction of the ["List All Site Tags" example above]({{< relref "#example-list-all-site-tags" >}}):
|
||||
|
||||
{{< code file="links-to-all-tags" >}}
|
||||
<ul class="tags">
|
||||
{{ range ($.Site.GetPage "taxonomyTerm" "tags").Pages }}
|
||||
<li><a href="{{ .Permalink }}">{{ .Title}}</a></li>
|
||||
{{ end }}
|
||||
{{< code file="links-to-all-tags.html" >}}
|
||||
{{ $taxo := "tags" }}
|
||||
<ul class="{{ $taxo }}">
|
||||
{{ with ($.Site.GetPage (printf "/%s" $taxo)) }}
|
||||
{{ range .Pages }}
|
||||
<li><a href="{{ .Permalink }}">{{ .Title}}</a></li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{< /code >}}
|
||||
|
||||
<!--### `.Site.GetPage` Taxonomy List Example
|
||||
<!-- TODO: ### `.Site.GetPage` Taxonomy List Example -->
|
||||
|
||||
### `.Site.GetPage` Taxonomy Terms Example -->
|
||||
<!-- TODO: ### `.Site.GetPage` Taxonomy Terms Example -->
|
||||
|
||||
|
||||
[delimit]: /functions/delimit/
|
||||
|
|
|
@ -47,6 +47,7 @@ Alternatively, you can use the new [Jekyll import command](/commands/hugo_import
|
|||
## WordPress
|
||||
|
||||
- [wordpress-to-hugo-exporter](https://github.com/SchumacherFM/wordpress-to-hugo-exporter) - A one-click WordPress plugin that converts all posts, pages, taxonomies, metadata, and settings to Markdown and YAML which can be dropped into Hugo. (Note: If you have trouble using this plugin, you can [export your site for Jekyll](https://wordpress.org/plugins/jekyll-exporter/) and use Hugo's built in Jekyll converter listed above.)
|
||||
- [exitwp-for-hugo](https://github.com/wooni005/exitwp-for-hugo) - A python script which works with the xml export from Wordpress and converts Wordpress pages and posts to Markdown and YAML for hugo.
|
||||
- [blog2md](https://github.com/palaniraja/blog2md) - Works with [exported xml](https://en.support.wordpress.com/export/) file of your free YOUR-TLD.wordpress.com website. It also saves approved comments to `YOUR-POST-NAME-comments.md` file along with posts.
|
||||
|
||||
## Tumblr
|
||||
|
@ -68,6 +69,7 @@ Alternatively, you can use the new [Jekyll import command](/commands/hugo_import
|
|||
- [blogimport](https://github.com/natefinch/blogimport) - A tool to import from Blogger posts to Hugo.
|
||||
- [blogger-to-hugo](https://bitbucket.org/petraszd/blogger-to-hugo) - Another tool to import Blogger posts to Hugo. It also downloads embedded images so they will be stored locally.
|
||||
- [blog2md](https://github.com/palaniraja/blog2md) - Works with [exported xml](https://support.google.com/blogger/answer/41387?hl=en) file of your YOUR-TLD.blogspot.com website. It also saves comments to `YOUR-POST-NAME-comments.md` file along with posts.
|
||||
- [BloggerToHugo](https://github.com/huanlin/blogger-to-hugo) - Yet another tool to import Blogger posts to Hugo. For Windows platform only, and .NET Framework 4.5 is required. See README.md before using this tool.
|
||||
|
||||
## Contentful
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ linktitle: Starter Kits
|
|||
description: A list of community-developed projects designed to help you get up and running with Hugo.
|
||||
date: 2017-02-22
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-22
|
||||
lastmod: 2018-08-11
|
||||
keywords: [starters,assets,pipeline]
|
||||
menu:
|
||||
docs:
|
||||
|
@ -23,6 +23,7 @@ Know of a Hugo-related starter kit that isn't mentioned here? [Please add it to
|
|||
The following starter kits are developed by active members of the Hugo community. If you find yourself having issues with any of the projects, it's best to file an issue directly with the project's maintainer(s).
|
||||
{{% /note %}}
|
||||
|
||||
* [Hugo Wrapper][hugow]. Hugo Wrapper is a POSIX-style shell script which acts as a wrapper to download and run Hugo binary for your platform. It can be executed in variety of [Operating Systems][hugow-test] and [Command Shells][hugow-test].
|
||||
* [Victor Hugo][]. Victor Hugo is a Hugo boilerplate for creating truly epic websites using Gulp + Webpack as an asset pipeline. Victor Hugo uses post-css and Babel for CSS and JavaScript, respectively, and is actively maintained.
|
||||
* [GOHUGO AMP][]. GoHugo AMP is a starter theme that aims to make it easy to adopt [Google's AMP Project][amp]. The starter kit comes with 40+ shortcodes and partials plus automatic structured data. The project also includes a [separate site with extensive documentation][gohugodocs].
|
||||
* [Blaupause][]. Blaupause is a developer-friendly Hugo starter kit based on Gulp tasks. It comes ES6-ready with several helpers for SVG and fonts and basic structure for HTML, SCSS, and JavaScript.
|
||||
|
@ -35,6 +36,8 @@ The following starter kits are developed by active members of the Hugo community
|
|||
[Blaupause]: https://github.com/fspoettel/blaupause
|
||||
[GOHUGO AMP]: https://github.com/wildhaber/gohugo-amp
|
||||
[gohugodocs]: https://gohugo-amp.gohugohq.com/
|
||||
[hugow]: https://github.com/khos2ow/hugo-wrapper
|
||||
[hugow-test]: https://github.com/khos2ow/hugo-wrapper#tested-on
|
||||
[hugulp]: https://github.com/jbrodriguez/hugulp
|
||||
[Victor Hugo]: https://github.com/netlify/victor-hugo
|
||||
[Atlas]: https://github.com/indigotree/atlas
|
||||
|
|
|
@ -53,6 +53,6 @@ The `GitInfo` object contains the following fields:
|
|||
|
||||
## `.Lastmod`
|
||||
|
||||
If the `.GitInfo` feature is enabled, **and** if the `lastmod` field in the content's front matter is not set, `.Lastmod` (on `Page`) is fetched from Git i.e. `.GitInfo.AuthorDate`.
|
||||
If the `.GitInfo` feature is enabled, `.Lastmod` (on `Page`) is fetched from Git i.e. `.GitInfo.AuthorDate`. This behaviour can be changed by adding your own [front matter configuration for dates](/getting-started/configuration/#configure-front-matter).
|
||||
|
||||
[configuration]: /getting-started/configuration/
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
|
||||
[[article]]
|
||||
title = "How to use Firebase to host a Hugo site"
|
||||
url = "https://www.m0d3rnc0ad.com/post/static-site-firebase/"
|
||||
url = "https://code.selfmadefighter.com/post/static-site-firebase/"
|
||||
author = "Andrew Cuga"
|
||||
date= "2017-02-04"
|
||||
|
||||
|
|
|
@ -2838,6 +2838,19 @@
|
|||
}
|
||||
},
|
||||
"os": {
|
||||
"Stat": {
|
||||
"Description": "Stat returns a file infomation under the given path.",
|
||||
"Args": [
|
||||
"i"
|
||||
],
|
||||
"Aliases": null,
|
||||
"Examples": [
|
||||
[
|
||||
"{{ (os.Stat \"foo.txt\").Name }}",
|
||||
"foo.txt"
|
||||
]
|
||||
]
|
||||
},
|
||||
"FileExists": {
|
||||
"Description": "FileExists checks whether a file exists under the given path.",
|
||||
"Args": [
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
[[quotes]]
|
||||
name = "Joshua Steven"
|
||||
twitter_handle = "@jscarto"
|
||||
quote = "Can't overstate how much I enjoy @GoHugoIO. My site is relatively small, but *18 ms* to build the whole thing made template development and proofing a breeze."
|
||||
link = "https://twitter.com/jscarto/status/1039648827815485440"
|
||||
date = 2018-09-12T00:00:00Z
|
||||
|
||||
[[quotes]]
|
||||
name = "Execute"
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{{ $file := .Get "file" }}
|
||||
{{ $.Scratch.Set "codeLang" "" }}
|
||||
{{ $codeLang := "" }}
|
||||
{{ $suffix := findRE "(\\.[^.]+)$" $file 1 }}
|
||||
{{ with $suffix }}
|
||||
{{ $.Scratch.Set "codeLang" (index . 0 | strings.TrimPrefix ".") }}
|
||||
{{ $codeLang = (index . 0 | strings.TrimPrefix ".") }}
|
||||
{{ end }}
|
||||
{{ with .Get "codeLang" }}{{ $.Scratch.Set "codeLang" . }}{{ end }}
|
||||
{{ if eq (.Scratch.Get "codeLang") "html"}}
|
||||
{{ $.Scratch.Set "codeLang" "go-html-template" }}
|
||||
{{ with .Get "codeLang" }}{{ $codeLang = . }}{{ end }}
|
||||
{{ if eq $codeLang "html"}}
|
||||
{{ $codeLang = "go-html-template" }}
|
||||
{{ end }}
|
||||
<div class="code relative" id="{{ $file | urlize}}">
|
||||
{{- with $file -}}
|
||||
|
@ -19,7 +19,7 @@
|
|||
{{/* Functionality located within filesaver.js The copy here is located in the css with .copy class so it can be replaced with JS on success */}}
|
||||
{{end}}
|
||||
<div class="code-copy-content nt3" {{with .Get "download"}}id="{{.}}"{{end}}>
|
||||
{{ if .Get "nocode" }}{{ $.Inner }}{{ else }}{{ with $.Scratch.Get "codeLang" }}{{- highlight $.Inner . "" | -}}{{ else }}<pre><code>{{- .Inner | string -}}</code></pre>{{ end }}{{ end }}
|
||||
{{ if .Get "nocode" }}{{ $.Inner }}{{ else }}{{ with $codeLang }}{{- highlight $.Inner . "" | -}}{{ else }}<pre><code>{{- .Inner | string -}}</code></pre>{{ end }}{{ end }}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
[build]
|
||||
publish = "public"
|
||||
command = "hugo"
|
||||
command = "hugo --minify"
|
||||
|
||||
[context.production.environment]
|
||||
HUGO_VERSION = "0.46"
|
||||
HUGO_VERSION = "0.48"
|
||||
HUGO_ENV = "production"
|
||||
HUGO_ENABLEGITINFO = "true"
|
||||
|
||||
|
@ -11,20 +11,20 @@ HUGO_ENABLEGITINFO = "true"
|
|||
command = "hugo --enableGitInfo"
|
||||
|
||||
[context.split1.environment]
|
||||
HUGO_VERSION = "0.46"
|
||||
HUGO_VERSION = "0.48"
|
||||
HUGO_ENV = "production"
|
||||
|
||||
[context.deploy-preview]
|
||||
command = "hugo --buildFuture -b $DEPLOY_PRIME_URL"
|
||||
|
||||
[context.deploy-preview.environment]
|
||||
HUGO_VERSION = "0.46"
|
||||
HUGO_VERSION = "0.48"
|
||||
|
||||
[context.branch-deploy]
|
||||
command = "hugo -b $DEPLOY_PRIME_URL"
|
||||
|
||||
[context.branch-deploy.environment]
|
||||
HUGO_VERSION = "0.46"
|
||||
HUGO_VERSION = "0.48"
|
||||
|
||||
[context.next.environment]
|
||||
HUGO_ENABLEGITINFO = "true"
|
||||
|
|
2
docs/resources/.gitattributes
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.* linguist-generated=true
|
||||
*.* -diff -merge
|
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 66 KiB |
After Width: | Height: | Size: 114 KiB |
After Width: | Height: | Size: 54 KiB |
After Width: | Height: | Size: 39 KiB |
|
@ -2,5 +2,5 @@
|
|||
<a href="{{ .Permalink }}" class="hide-child link primary-color">
|
||||
<span class="nl3 child">{{ partial "svg/link-permalink.svg" (dict "size" "14px") }}</span>
|
||||
“{{ .Title }}”
|
||||
</a> was last updated: {{ .Lastmod.Format "January 2, 2006" }}{{ with .GitInfo }}: <a class="hide-child link primary-color" href="{{$.Site.Params.ghrepo}}/commit/{{ .Hash }}">{{ .Subject }} ({{ .AbbreviatedHash }})</a>{{end }}
|
||||
</a> was last updated: {{ .Lastmod.Format "January 2, 2006" }}{{ with .GitInfo }}: <a class="hide-child link primary-color" href="{{$.Site.Params.ghrepo}}commit/{{ .Hash }}">{{ .Subject }} ({{ .AbbreviatedHash }})</a>{{end }}
|
||||
</h6>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{{if .Prev }}
|
||||
<a href="{{ .Prev.Permalink }}" class="db-l f4 f3-ns link primary-color hover-black fw8">
|
||||
<a href="{{ .Prev.Permalink }}" class="db-l f4 f3-ns link primary-color hover-black fw8 mr4">
|
||||
<span class="v-mid dib">{{ partial "svg/ic_chevron_left_black_24px.svg" (dict "size" "30px") }}</span> {{ .Prev.Title }}
|
||||
</a>
|
||||
{{end}}
|
||||
|
@ -13,13 +13,13 @@
|
|||
|
||||
<script>
|
||||
document.body.onkeyup = function(e){
|
||||
|
||||
{{ if .Prev }}
|
||||
if (!(e.ctrlKey || e.shiftKey || e.altKey || e.metaKey)) {
|
||||
{{- if .Prev }}
|
||||
if (e.keyCode == '37') { window.location = '{{ .Prev.Permalink }}'; }
|
||||
{{ end }}
|
||||
{{ if .Next }}
|
||||
if (e.keyCode == '39') { window.location = '{{.Next.Permalink }}'; }
|
||||
{{ end }}
|
||||
{{- end }}
|
||||
{{- if .Next }}
|
||||
if (e.keyCode == '39') { window.location = '{{ .Next.Permalink }}'; }
|
||||
{{- end }}
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<div class="pb3 pt4 w-100 w-50-ns">
|
||||
|
||||
<div class="b f3 light-gray mb3 nested-links tc">
|
||||
By the <a href="https://github.com/gohugoio/hugo/contributors" class="link">Hugo Authors</a><br />
|
||||
By the <a href="https://github.com/gohugoio/hugo/graphs/contributors" class="link">Hugo Authors</a><br />
|
||||
</div>
|
||||
|
||||
<div class="center w4">
|
||||
|
|