Clean up code block (First round)

Also create the first draft of NumFmt function.
This commit is contained in:
Ryan Watters 2017-04-30 15:25:54 -05:00
parent b6dc570cb4
commit abe797c958
6 changed files with 177 additions and 128 deletions

View File

@ -15,9 +15,10 @@ weight: 55 #rem
draft: true draft: true
aliases: [/content/archetypes/] aliases: [/content/archetypes/]
toc: true toc: true
comments: Before this page is published, need to also update both site- and page-level variables documentation.
--- ---
<!-- Before this page is published, need to also update both site- and page-level variables documentation. -->
Larger sites often have multiple content authors. Hugo provides standardized author profiles to organize relationships between content and content creators for sites operating under a distributed authorship model. Larger sites often have multiple content authors. Hugo provides standardized author profiles to organize relationships between content and content creators for sites operating under a distributed authorship model.

View File

@ -108,7 +108,7 @@ There are a few predefined variables that Hugo is aware of. See [Page Variables]
: the meta keywords for the content. : the meta keywords for the content.
`layout` `layout`
: the layout Hugo should select from the [lookup order][] when rendering the content. : the layout Hugo should select from the [lookup order][lookup] when rendering the content.
`lastmod` `lastmod`
: the datetime at which the content was last modified. : the datetime at which the content was last modified.
@ -164,7 +164,7 @@ Field names are always normalized to lowercase; e.g., `camelCase: true` is avail
## Ordering Content Through Front Matter ## Ordering Content Through Front Matter
You can assign content-specific `weight` in the front matter of your content. These values are especially useful for [ordering][ordering] in list views. You can use `weight` for ordering of content and the convention of [`<TAXONOMY>_weight`][taxweight] for ordering content within a taxonomy. See [Ordering and Grouping Hugo Lists][] to see how `weight` can be used to organize your content in list views. You can assign content-specific `weight` in the front matter of your content. These values are especially useful for [ordering][ordering] in list views. You can use `weight` for ordering of content and the convention of [`<TAXONOMY>_weight`][taxweight] for ordering content within a taxonomy. See [Ordering and Grouping Hugo Lists][lists] to see how `weight` can be used to organize your content in list views.
## Overriding Global Blackfriday Configuration ## Overriding Global Blackfriday Configuration
@ -172,9 +172,9 @@ It's possible to set some options for Markdown rendering in a content's front ma
## Front Matter Format Specs ## Front Matter Format Specs
* [TOML Spec][TOML Spec] * [TOML Spec][toml]
* [YAML Spec][YAML Spec] * [YAML Spec][yaml]
* [JSON Spec][JSON Spec] * [JSON Spec][json]
[variables]: /variables/ [variables]: /variables/
[aliases]: /content-management/urls/#aliases/ [aliases]: /content-management/urls/#aliases/
@ -184,7 +184,8 @@ It's possible to set some options for Markdown rendering in a content's front ma
[content type]: /content-management/types/ [content type]: /content-management/types/
[contentorg]: /content-management/organization/ [contentorg]: /content-management/organization/
[json]: /documents/ecma-404-json-spec.pdf "Specification for JSON, JavaScript Object Notation" [json]: /documents/ecma-404-json-spec.pdf "Specification for JSON, JavaScript Object Notation"
[lookup]: /content-management/l [lists]: /templates/lists/#ordering-content
[lookup]: /templates/lookup-order/
[ordering]: /templates/lists/ "Hugo provides multiple ways to sort and order your content in list templates" [ordering]: /templates/lists/ "Hugo provides multiple ways to sort and order your content in list templates"
[pagevars]: /variables/page/ [pagevars]: /variables/page/
[section]: /content-management/sections/ [section]: /content-management/sections/

View File

@ -0,0 +1,41 @@
---
title: numfmt
linktitle: NumFmt
description: Formats a number with a given precision using the requested `decimal`, `grouping`, and `negative` characters.
godocref:
workson: []
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
categories: [functions]
tags: []
toc: false
ns: "lang"
signature: ["NumFmt <decimal> <grouping> <negative> <precision> <number>"]
workson: []
hugoversion:
relatedfuncs: []
deprecated: false
draft: true
aliases: []
comments:
---
`NumFmt` formats a number with a given precision using the requested `decimal`,
`grouping`, and `negative` characters.
Numbers greater than or equal to 5 are rounded up. For example, if precision is set to `0`, `1.5` becomes `2`, and `1.4` becomes `1`.
```
{{ lang.NumFmt "," "." "-" 2 12345.6789 }} → 12.345,68
{{ lang.NumFmt "." "" "-" 6 -12345.6789 }} → -12345.678900
{{ lang.NumFmt "." "," "-" 0 -12345.6789 }} → -12,346
{{ -98765.4321 | lang.NumFmt "." "," "-" 2 }} → -98,765.43
```

View File

@ -1,22 +0,0 @@
---
title: numformat
linktitle: numFormat
description:
godocref:
workson: []
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
categories: [functions]
tags: []
toc: false
ns:
signature: []
workson: []
hugoversion:
relatedfuncs: []
deprecated: false
draft: true
aliases: []
---

View File

@ -285,7 +285,7 @@ The following shows how to define a variable independent of the context.
{{% code file="tags-range-with-page-variable.html" %}} {{% code file="tags-range-with-page-variable.html" %}}
```html ```html
{{ $title := .Site.Title }} {{ $title := .Site.Title }}
<ul class="tags"> <ul>
{{ range .Params.tags }} {{ range .Params.tags }}
<li> <li>
<a href="/tags/{{ . | urlize }}">{{ . }}</a> <a href="/tags/{{ . | urlize }}">{{ . }}</a>
@ -306,7 +306,7 @@ Notice how once we have entered the loop (i.e. `range`), the value of `{{ . }}`
{{% code file="range-through-tags-w-global.html" %}} {{% code file="range-through-tags-w-global.html" %}}
```hbs ```hbs
<ul class="tags"> <ul>
{{ range .Params.tags }} {{ range .Params.tags }}
<li> <li>
<a href="/tags/{{ . | urlize }}">{{ . }}</a> <a href="/tags/{{ . | urlize }}">{{ . }}</a>
@ -383,15 +383,15 @@ notoc: true
--- ---
``` ```
Here is the corresponding code inside the `toc.html` [partial template][partials]: Here is an example of corresponding code that could be used inside a `toc.html` [partial template][partials]:
{{% code file="layouts/partials/toc.html" download="toc.html" %}} {{% code file="layouts/partials/toc.html" download="toc.html" %}}
```html ```html
{{ if not .Params.notoc }} {{ if not .Params.notoc }}
<aside id="toc"> <aside>
<header class="toc-header"> <header>
<a href="#{{.Title | urlize}}"> <a href="#{{.Title | urlize}}">
<h3 class="{{.Section}}">{{.Title}}</h3> <h3>{{.Title}}</h3>
</a> </a>
</header> </header>
{{.TableOfContents}} {{.TableOfContents}}
@ -412,9 +412,9 @@ For instance, you might declare the following:
{{% code file="config.yaml" %}} {{% code file="config.yaml" %}}
```yaml ```yaml
params: params:
CopyrightHTML: "Copyright &#xA9; 2013 John Doe. All Rights Reserved." copyrighthtml: "Copyright &#xA9; 2017 John Doe. All Rights Reserved."
TwitterUser: "spf13" twitteruser: "spf13"
SidebarRecentLimit: 5 sidebarrecentlimit: 5
``` ```
{{% /code %}} {{% /code %}}
@ -430,22 +430,25 @@ An alternative way of writing the "`if`" and then referencing the same value is
{{% code file="layouts/partials/twitter.html" %}} {{% code file="layouts/partials/twitter.html" %}}
```html ```html
{{with .Site.Params.TwitterUser}}<span class="twitter"> {{with .Site.Params.twitteruser}}
<a href="https://twitter.com/{{.}}" rel="author"> <div>
<img src="/images/twitter.png" width="48" height="48" title="Twitter: {{.}}" <a href="https://twitter.com/{{.}}" rel="author">
alt="Twitter"></a> <img src="/images/twitter.png" width="48" height="48" title="Twitter: {{.}}" alt="Twitter"></a>
</span>{{end}} </div>
{{end}}
``` ```
{{% /code %}} {{% /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. 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.
```html ```html
<nav class="recent"> <nav>
<h1>Recent Posts</h1> <h1>Recent Posts</h1>
<ul>{{range first .Site.Params.SidebarRecentLimit .Site.Pages}} <ul>
{{- range first .Site.Params.SidebarRecentLimit .Site.Pages -}}
<li><a href="{{.RelPermalink}}">{{.Title}}</a></li> <li><a href="{{.RelPermalink}}">{{.Title}}</a></li>
{{end}}</ul> {{- end -}}
</ul>
</nav> </nav>
``` ```
@ -459,10 +462,12 @@ Go allows you to do more than what's shown here. Using Hugo's [`where` function]
<ul class="upcoming-events"> <ul class="upcoming-events">
{{ range where .Data.Pages.ByDate "Section" "events" }} {{ range where .Data.Pages.ByDate "Section" "events" }}
{{ if ge .Date.Unix .Now.Unix }} {{ if ge .Date.Unix .Now.Unix }}
<li><span class="event-type">{{ .Type | title }} —</span> <li>
{{ .Title }} <!-- add span for event type -->
on <span class="event-date"> <span>{{ .Type | title }} —</span>
{{ .Date.Format "2 January at 3:04pm" }}</span> {{ .Title }} on
<!-- add span for event date -->
<span>{{ .Date.Format "2 January at 3:04pm" }}</span>
at {{ .Params.place }} at {{ .Params.place }}
</li> </li>
{{ end }} {{ end }}

View File

@ -98,14 +98,16 @@ You can now access this `_index.md`'s' content in your list template:
{{% code file="layouts/_default/list.html" download="list.html" %}} {{% code file="layouts/_default/list.html" download="list.html" %}}
```html ```html
{{ define "main" }} {{ define "main" }}
<main class="main"> <main>
<article> <article>
<header> <header>
<h1>{{.Title}}</h1> <h1>{{.Title}}</h1>
</header> </header>
<!-- "{{.Content}}" pulls from the markdown content of the corresponding _inde.xmd -->
{{.Content}} {{.Content}}
</article> </article>
<ul class="section-contents"> <ul>
<!-- Ranges through content/post/*.md -->
{{ range .Data.Pages }} {{ range .Data.Pages }}
<li> <li>
<a href="{{.Permalink}}">{{.Date.Format "2006-01-02"}} | {{.Title}}</a <a href="{{.Permalink}}">{{.Date.Format "2006-01-02"}} | {{.Title}}</a
@ -121,8 +123,8 @@ This above will output the following HTML:
{{% code file="yoursite.com/post/index.html" copy="false" %}} {{% code file="yoursite.com/post/index.html" copy="false" %}}
```html ```html
<!--all your baseof.html code--> <!--top of your baseof code-->
<main class="main"> <main>
<article> <article>
<header> <header>
<h1>My Golang Journey</h1> <h1>My Golang Journey</h1>
@ -130,12 +132,12 @@ This above will output the following HTML:
<p>I decided to start learning Golang in March 2017.</p> <p>I decided to start learning Golang in March 2017.</p>
<p>Follow my journey through this new blog.</p> <p>Follow my journey through this new blog.</p>
</article> </article>
<ul class="section-contents"> <ul>
<li><a href="/post/post-01/">Post 1</a></li> <li><a href="/post/post-01/">Post 1</a></li>
<li><a href="/post/post-02/">Post 2</a></li> <li><a href="/post/post-02/">Post 2</a></li>
</ul> </ul>
</main> </main>
<!--all your other baseof.html code--> <!--bottom of your baseof-->
``` ```
{{% /code %}} {{% /code %}}
@ -147,19 +149,20 @@ Using this same `layouts/_default/list.html` template and applying it to the the
{{% code file="yoursite.com/quote/index.html" copy="false" %}} {{% code file="yoursite.com/quote/index.html" copy="false" %}}
```html ```html
<!--baseof.html code--> <!--baseof-->
<main class="main"> <main>
<article> <article>
<header> <header>
<!-- Hugo assumes that .Title is the name of the section since there is no _index.md content file from which to pull a "title:" field -->
<h1>Quotes</h1> <h1>Quotes</h1>
</header> </header>
</article> </article>
<ul class="section-contents"> <ul>
<li><a href="https://yoursite.com/quote/quotes-01/">Quote 1</a></li> <li><a href="https://yoursite.com/quote/quotes-01/">Quote 1</a></li>
<li><a href="https://yoursite.com/quote/quotes-02/">Quote 2</a></li> <li><a href="https://yoursite.com/quote/quotes-02/">Quote 2</a></li>
</ul> </ul>
</main> </main>
<!--baseof.html code--> <!--baseof-->
``` ```
{{% /code %}} {{% /code %}}
@ -171,23 +174,23 @@ The default behavior of Hugo is to pluralize list titles; hence the inflection o
### Section Template ### Section Template
This list template is used for [spf13.com](http://spf13.com/). It makes use of [partial templates][partials]. All examples use a [view](/templates/views/) called either "li" or "summary." This list template has been modified slightly from a template originally used in [spf13.com](http://spf13.com/). It makes use of [partial templates][partials] for the chrome of the rendered page rather than using a [base template][base] The examples that follow also use the [content view templates][views] `li.html` or `summary.html`.
{{% code file="layouts/section/post.html" %}} {{% code file="layouts/section/post.html" %}}
```html ```html
{{ partial "header.html" . }} {{ partial "header.html" . }}
{{ partial "subheader.html" . }} {{ partial "subheader.html" . }}
<main>
<section id="main">
<div> <div>
<h1 id="title">{{ .Title }}</h1> <h1>{{ .Title }}</h1>
<ul id="list"> <ul>
<!-- Renders the li.html content view for each content/post/*.md -->
{{ range .Data.Pages }} {{ range .Data.Pages }}
{{ .Render "li"}} {{ .Render "li"}}
{{ end }} {{ end }}
</ul> </ul>
</div> </div>
</section> </main>
{{ partial "footer.html" . }} {{ partial "footer.html" . }}
``` ```
{{% /code %}} {{% /code %}}
@ -197,30 +200,28 @@ This list template is used for [spf13.com](http://spf13.com/). It makes use of [
{{% code file="layouts/_default/taxonomies.html" download="taxonomies.html" %}} {{% code file="layouts/_default/taxonomies.html" download="taxonomies.html" %}}
```html ```html
{{ define "main" }} {{ define "main" }}
<section id="main"> <main>
<div> <div>
<h1 id="title">{{ .Title }}</h1> <h1>{{ .Title }}</h1>
<!-- ranges through each of the content files associated with a particular taxonomy term and renders the summary.html content view -->
{{ range .Data.Pages }} {{ range .Data.Pages }}
{{ .Render "summary"}} {{ .Render "summary"}}
{{ end }} {{ end }}
</div> </div>
</section> </main>
{{ end }} {{ end }}
``` ```
{{% /code %}} {{% /code %}}
## Ordering Content ## Ordering Content
Hugo lists render the content based on metadata provided in the [front matter](/content-management/front-matter/).. Hugo lists render the content based on metadata you provide in [front matter][]. In addition to sane defaults, Hugo also ships with multiple methods to make quick work of ordering content inside list templates:
Here are a variety of different ways you can order the content items in ### Default List Ordering: Weight > Date
your list templates:
### Default: Weight > Date {{% code file="layouts/partials/default-order.html" %}}
{{% code file="layouts/partials/order-default.html" %}}
```html ```html
<ul class="pages"> <ul>
{{ range .Data.Pages }} {{ range .Data.Pages }}
<li> <li>
<h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1> <h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
@ -235,12 +236,14 @@ your list templates:
{{% code file="layouts/partials/by-weight.html" %}} {{% code file="layouts/partials/by-weight.html" %}}
```html ```html
{{ range .Data.Pages.ByWeight }} <ul>
<li> {{ range .Data.Pages.ByWeight }}
<a href="{{ .Permalink }}">{{ .Title }}</a> <li>
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div> <h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
</li> <time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
{{ end }} </li>
{{ end }}
</ul>
``` ```
{{% /code %}} {{% /code %}}
@ -248,12 +251,15 @@ your list templates:
{{% code file="layouts/partials/by-date.html" %}} {{% code file="layouts/partials/by-date.html" %}}
```html ```html
{{ range .Data.Pages.ByDate }} <ul>
<li> <!-- orders content according to the "date" field in front matter -->
<a href="{{ .Permalink }}">{{ .Title }}</a> {{ range .Data.Pages.ByDate }}
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div> <li>
</li> <h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
{{ end }} <time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
``` ```
{{% /code %}} {{% /code %}}
@ -261,12 +267,15 @@ your list templates:
{{% code file="layouts/partials/by-publish-date.html" %}} {{% code file="layouts/partials/by-publish-date.html" %}}
```html ```html
{{ range .Data.Pages.ByPublishDate }} <ul>
<li> <!-- orders content according to the "publishdate" field in front matter -->
<a href="{{ .Permalink }}">{{ .Title }}</a> {{ range .Data.Pages.ByPublishDate }}
<div class="meta">{{ .PublishDate.Format "Mon, Jan 2, 2006" }}</div> <li>
</li> <h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
{{ end }} <time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
``` ```
{{% /code %}} {{% /code %}}
@ -274,12 +283,14 @@ your list templates:
{{% code file="layouts/partials/by-expiry-date.html" %}} {{% code file="layouts/partials/by-expiry-date.html" %}}
```html ```html
{{ range .Data.Pages.ByExpiryDate }} <ul>
<li> {{ range .Data.Pages.ByExpiryDate }}
<a href="{{ .Permalink }}">{{ .Title }}</a> <li>
<div class="meta">{{ .ExpiryDate.Format "Mon, Jan 2, 2006" }}</div> <h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
</li> <time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
{{ end }} </li>
{{ end }}
</ul>
``` ```
{{% /code %}} {{% /code %}}
@ -287,12 +298,15 @@ your list templates:
{{% code file="layouts/partials/by-last-mod.html" %}} {{% code file="layouts/partials/by-last-mod.html" %}}
```html ```html
{{ range .Data.Pages.ByLastmod }} <ul>
<li> <!-- orders content according to the "lastmod" field in front matter -->
<a href="{{ .Permalink }}">{{ .Title }}</a> {{ range .Data.Pages.ByLastmod }}
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div> <li>
</li> <h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
{{ end }} <time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
``` ```
{{% /code %}} {{% /code %}}
@ -300,26 +314,31 @@ your list templates:
{{% code file="layouts/partials/by-length.html" %}} {{% code file="layouts/partials/by-length.html" %}}
```html ```html
{{ range .Data.Pages.ByLength }} <ul>
<li> <!-- orders content according to content length in ascending order (i.e., the shortest content will be listed first) -->
<a href="{{ .Permalink }}">{{ .Title }}</a> {{ range .Data.Pages.ByLength }}
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div> <li>
</li> <h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
{{ end }} <time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
``` ```
{{% /code %}} {{% /code %}}
### By Title ### By Title
{{% code file="layouts/partials/by-title.html" %}} {{% code file="layouts/partials/by-title.html" %}}
```html ```html
{{ range .Data.Pages.ByTitle }} <ul>
<li> <!-- ranges through content in ascending order according to the "title" field set in front matter -->
<a href="{{ .Permalink }}">{{ .Title }}</a> {{ range .Data.Pages.ByTitle }}
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div> <li>
</li> <h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
{{ end }} <time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
``` ```
{{% /code %}} {{% /code %}}
@ -327,12 +346,15 @@ your list templates:
{{% code file="layouts/partials/by-link-title.html" %}} {{% code file="layouts/partials/by-link-title.html" %}}
```html ```html
{{ range .Data.Pages.ByLinkTitle }} <ul>
<li> <!-- ranges through content in ascending order according to the "linktitle" field in front matter. If a "linktitle" field is not set, the range will start with content that only has a "title" field and use that value for .LinkTitle -->
<a href="{{ .Permalink }}">{{ .LinkTitle }}</a> {{ range .Data.Pages.ByLinkTitle }}
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div> <li>
</li> <h1><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></h1>
{{ end }} <time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
``` ```
{{% /code %}} {{% /code %}}
@ -340,10 +362,9 @@ your list templates:
Order based on the specified front matter parameter. Content that does not have the specified front matter field will use the site's `.Site.Params` default. If the parameter is not found at all in some entries, those entries will appear together at the end of the ordering. Order based on the specified front matter parameter. Content that does not have the specified front matter field will use the site's `.Site.Params` default. If the parameter is not found at all in some entries, those entries will appear together at the end of the ordering.
The below example sorts a list of posts by their rating.
{{% code file="layouts/partials/by-rating.html" %}} {{% code file="layouts/partials/by-rating.html" %}}
```html ```html
<!-- Ranges through a list of content according to the "rating" field set in front matter -->
{{ range (.Data.Pages.ByParam "rating") }} {{ range (.Data.Pages.ByParam "rating") }}
<!-- ... --> <!-- ... -->
{{ end }} {{ end }}
@ -355,6 +376,7 @@ also get it:
{{% code file="layouts/partials/by-nested-param.html" %}} {{% code file="layouts/partials/by-nested-param.html" %}}
```html ```html
{{ range (.Data.Pages.ByParam "author.last_name") }} {{ range (.Data.Pages.ByParam "author.last_name") }}
<!-- ... --> <!-- ... -->
{{ end }} {{ end }}
@ -569,10 +591,11 @@ Using `first` and `where` together can be very powerful:
``` ```
{{% /code %}} {{% /code %}}
[base]: /templates/base/
[bepsays]: http://bepsays.com/en/2016/12/19/hugo-018/ [bepsays]: http://bepsays.com/en/2016/12/19/hugo-018/
[directorystructure]: /getting-started/directory-structure/ [directorystructure]: /getting-started/directory-structure/
[`Format` function]: /functions/format/ [`Format` function]: /functions/format/
[front matter]: /content-management/front-matter/
[homepage]: /templates/homepage/ [homepage]: /templates/homepage/
[homepage]: /templates/homepage/ [homepage]: /templates/homepage/
[limitkeyword]: https://www.techonthenet.com/sql/select_limit.php [limitkeyword]: https://www.techonthenet.com/sql/select_limit.php