Remove opinionated code blocks (Third round)

Closes rdwatters/hugo-docs-concept#105
This commit is contained in:
Ryan Watters 2017-04-30 17:16:40 -05:00
parent bc9a649195
commit 71471f13ce
12 changed files with 67 additions and 43 deletions

View File

@ -15,7 +15,7 @@ workson: [menus]
hugoversion:
relatedfuncs: []
deprecated: false
draft: false
draft: true
aliases: []
needsexamples: true
---

View File

@ -15,7 +15,7 @@ hugoversion:
relatedfuncs: []
deprecated: false
toc: false
draft: false
draft: true
aliases: []
needsexamples: true
---

View File

@ -14,8 +14,9 @@ workson: [menus]
hugoversion:
relatedfuncs: []
deprecated: false
draft: false
draft: true
aliases: []
needsexample: true
---
Used in [menu templates](/templates/menu-templates/).

View File

@ -5,7 +5,7 @@ description: Returns the current local time as a [`time.Time`]
godocref: https://godoc.org/time#Time
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
lastmod: 2017-04-30
categories: [functions]
tags: [dates,time]
ns:
@ -23,7 +23,7 @@ needsexamples: true
For example, building your site on June 24, 2017 with the following templating:
```html
<div class="copyright">
<div>
<small>&copy; {{ now.Format "2006"}}</small>
</div>
```
@ -31,12 +31,12 @@ For example, building your site on June 24, 2017 with the following templating:
Which will produce the following:
```html
<div class="copyright">
<div>
<small>&copy; 2017</small>
</div>
```
The above example also uses the [`.Format` function](/functions/format), which page includes a full listing of date formatting using Golang's layout string.
The above example uses the [`.Format` function](/functions/format), which page includes a full listing of date formatting using Golang's layout string.
{{% note %}}
Older Hugo themes may use the deprecated `.Now` (uppercase). Be sure to use the lowercase `.now` in your templating.

View File

@ -5,31 +5,36 @@ description: Calls page or site variables into your template.
godocref:
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
tags: []
lastmod: 2017-04-30
tags: ["front matter"]
categories: [functions]
toc:
ns:
signature: ["Param KEY"]
workson: []
hugoversion:
relatedfuncs: []
relatedfuncs: [default]
deprecated: false
draft: false
aliases: []
wip: true
---
In Hugo, you can declare [site-wide params][sitevars] (i.e. in your [configuration][]), as well as params for [individual pages][pagevars].
A common use case is to have a general value for the site and a more specific value for some of the pages (e.g., an image).
You can use the `.Param` method to call these values into your template:
You can use the `.Param` method to call these values into your template. The following will first look for an `image` param in a specific content's [front matter][]. If not found, Hugo will look for an `image` param in your site's configuration:
```
$.Param "image"
```
{{% note %}}
The `Param` method may not consider empty strings in a content's front matter as "not found." If you are setting preconfigured front matter fields to empty strings using Hugo's archetypes, it may be best to use the [`default` function](/functions/default/) instead of `Param`. See the [related issue on GitHub](https://github.com/spf13/hugo/issues/3366).
{{% /note %}}
[configuration]: /getting-started/configuration/
[front matter]: /content-management/front-matter/
[pagevars]: /variables/page/
[sitevars]: /variables/site/

View File

@ -5,14 +5,14 @@ description: Strips any HTML and returns the plain text version of the provided
godocref:
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
lastmod: 2017-04-30
categories: [functions]
tags: [strings]
ns:
signature: ["plainify INPUT"]
workson: []
hugoversion:
relatedfuncs: [jsonify]
relatedfuncs: [jsonify,]
deprecated: false
aliases: []
---
@ -23,7 +23,7 @@ aliases: []
{{ "<b>BatMan</b>" | plainify }} → "BatMan"
```
See also the [`.PlainWords`, `.Plain`, and `.RawContent` page variables][pagevars].
See also the `.PlainWords`, `.Plain`, and `.RawContent` [page variables][pagevars].
[pagevars]: /variables/page/

View File

@ -5,7 +5,7 @@ description: Reads a file from disk relative to the current project working dire
godocref:
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
lastmod: 2017-04-30
categories: [functions]
tags: [files]
ns:
@ -21,7 +21,7 @@ aliases: []
So, if you have a file with the name `README.txt` in the root of your project with the content `Hugo Rocks!`:
```
```html
{{readFile "README.txt"}} → "Hugo Rocks!"
```

View File

@ -35,7 +35,8 @@ The following is an example of a sidebar partial that may be used in conjunction
{{% code file="layouts/partials/bad-url-sidebar-menu.html" copy="false" %}}
```html
<ul class="sidebar-menu">
<!-- This unordered list may be part of a sidebar menu -->
<ul>
{{ range .Site.Menus.main }}
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
@ -47,7 +48,8 @@ This partial would produce the following HTML output:
{{% output file="bad-url-sidebar-menu-output.html" %}}
```html
<ul class="sidebar-menu">
<!-- This unordered list may be part of a sidebar menu -->
<ul>
<li><a href="#ZgotmplZ">IRC: #golang at freenode</a></li>
</ul>
```
@ -57,7 +59,8 @@ The odd output can be remedied by adding ` | safeURL` to our `.Title` page varia
{{% code file="layouts/partials/correct-url-sidebar-menu.html" copy="false" %}}
```html
<ul class="sidebar-menu">
<!-- This unordered list may be part of a sidebar menu -->
<ul>
<li><a href="{{ .URL | safeURL }}">{{ .Name }}</a></li>
</ul>
```

View File

@ -5,14 +5,14 @@ description: Returns a random permutation of a given array or slice.
godocref:
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
lastmod: 2017-04-30
tags: [ordering]
categories: [functions]
ns:
signature: ["shuffle COLLECTION"]
workson: []
hugoversion:
relatedfuncs: []
relatedfuncs: [seq]
deprecated: false
draft: false
aliases: []
@ -23,8 +23,10 @@ needsexamples: true
{{% code file="shuffle-input.html" %}}
```html
<div class="shuffle-sequence">{{ shuffle (seq 1 5) }}</div>
<div class="shuffle-slice">{{ shuffle (slice "foo" "bar" "buzz") }}</div>
<!-- Shuffled sequence = -->
<div>{{ shuffle (seq 1 5) }}</div>
<!-- Shuffled slice = -->
<div>{{ shuffle (slice "foo" "bar" "buzz") }}</div>
```
{{% /code %}}
@ -32,8 +34,10 @@ This example would return the following:
{{% output file="shuffle-output.html" %}}
```html
<div class="shuffle-seq">2 5 3 1 4</div>
<div class="shuffle-slice">buzz foo bar</div>
<!-- Shuffled sequence = -->
<div>2 5 3 1 4</div>
<!-- Shuffled slice = -->
<div>buzz foo bar</div>
```
{{% /output %}}

View File

@ -34,16 +34,21 @@ The following might be used as a partial within a [single page template][singlet
{{% code file="layouts/partials/content-header.html" download="content-header.html" %}}
```html
<header class="content-header">
<header>
<h1>{{.Title}}</h1>
{{ with .Params.location }}
<div class="location"><a href="/locations/{{ . | urlize}}">{{.}}</a></div>
<div><a href="/locations/{{ . | urlize}}">{{.}}</a></div>
{{ end }}
<!-- Creates a list of tags for the content and links to each of their pages -->
{{ with .Params.tags }}
<ul>
{{range .}}
<li>
<a href="/tags/{{ . | urlize }}">{{ . }}</a>
</li>
{{end}}
</ul>
{{ end }}
<div class="tags">
{{range .Params.tags}}
<a href="/tags/{{ . | urlize }}" class="tag">{{ . }}</a><br>
{{end}}
</div>
</header>
```
{{% /code %}}
@ -52,14 +57,20 @@ The preceding partial would then output to the rendered page as follows, assumin
{{% output file="/blog/greatest-city/index.html" %}}
```html
<header class="content-header">
<header>
<h1>The World's Greatest City</h1>
<div class="location"><a href="/locations/chicago-il/">Chicago IL</a></div>
<div class="tags">
<a href="/tags/pizza" class="tag">pizza</a>
<a href="/tags/beer" class="tag">beer</a>
<a href="/tags/hot-dogs" class="tag">hot dogs</a>
</div>
<div><a href="/locations/chicago-il/">Chicago IL</a></div>
<ul>
<li>
<a href="/tags/pizza">pizza</a>
</li>
<li>
<a href="/tags/beer">beer</a>
</li>
<li>
<a href="/tags/hot-dogs">hot dogs</a>
</li>
</ul>
</header>
```
{{% /output %}}

View File

@ -5,7 +5,7 @@ description: Filters an array to only the elements containing a matching value f
godocref:
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
lastmod: 2017-04-30
categories: [functions]
tags: [filtering]
ns:

View File

@ -16,9 +16,9 @@ relatedfuncs: []
deprecated: false
---
An alternative way of writing the "`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.
An alternative way of writing an `if` statement 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 or unset.
The following example checks for a [user-defined site variable](/variables/site/) defined as `twitteruser` in your [site configuration](/getting-started/configuration/). If the key-value is not set, the following will render nothing:
The following example checks for a [user-defined site variable](/variables/site/) called `twitteruser`. If the key-value is not set, the following will render nothing:
{{% code file="layouts/partials/twitter.html" %}}
```html