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
aliases: [/content/archetypes/]
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.

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.
`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`
: 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
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
@ -172,9 +172,9 @@ It's possible to set some options for Markdown rendering in a content's front ma
## Front Matter Format Specs
* [TOML Spec][TOML Spec]
* [YAML Spec][YAML Spec]
* [JSON Spec][JSON Spec]
* [TOML Spec][toml]
* [YAML Spec][yaml]
* [JSON Spec][json]
[variables]: /variables/
[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/
[contentorg]: /content-management/organization/
[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"
[pagevars]: /variables/page/
[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" %}}
```html
{{ $title := .Site.Title }}
<ul class="tags">
<ul>
{{ range .Params.tags }}
<li>
<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" %}}
```hbs
<ul class="tags">
<ul>
{{ range .Params.tags }}
<li>
<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" %}}
```html
{{ if not .Params.notoc }}
<aside id="toc">
<header class="toc-header">
<aside>
<header>
<a href="#{{.Title | urlize}}">
<h3 class="{{.Section}}">{{.Title}}</h3>
<h3>{{.Title}}</h3>
</a>
</header>
{{.TableOfContents}}
@ -412,9 +412,9 @@ For instance, you might declare the following:
{{% code file="config.yaml" %}}
```yaml
params:
CopyrightHTML: "Copyright &#xA9; 2013 John Doe. All Rights Reserved."
TwitterUser: "spf13"
SidebarRecentLimit: 5
copyrighthtml: "Copyright &#xA9; 2017 John Doe. All Rights Reserved."
twitteruser: "spf13"
sidebarrecentlimit: 5
```
{{% /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" %}}
```html
{{with .Site.Params.TwitterUser}}<span class="twitter">
<a href="https://twitter.com/{{.}}" rel="author">
<img src="/images/twitter.png" width="48" height="48" title="Twitter: {{.}}"
alt="Twitter"></a>
</span>{{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.
```html
<nav class="recent">
<nav>
<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>
{{end}}</ul>
{{- end -}}
</ul>
</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">
{{ range where .Data.Pages.ByDate "Section" "events" }}
{{ if ge .Date.Unix .Now.Unix }}
<li><span class="event-type">{{ .Type | title }} —</span>
{{ .Title }}
on <span class="event-date">
{{ .Date.Format "2 January at 3:04pm" }}</span>
<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 }}

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" %}}
```html
{{ define "main" }}
<main class="main">
<main>
<article>
<header>
<h1>{{.Title}}</h1>
</header>
<!-- "{{.Content}}" pulls from the markdown content of the corresponding _inde.xmd -->
{{.Content}}
</article>
<ul class="section-contents">
<ul>
<!-- Ranges through content/post/*.md -->
{{ range .Data.Pages }}
<li>
<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" %}}
```html
<!--all your baseof.html code-->
<main class="main">
<!--top of your baseof code-->
<main>
<article>
<header>
<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>Follow my journey through this new blog.</p>
</article>
<ul class="section-contents">
<ul>
<li><a href="/post/post-01/">Post 1</a></li>
<li><a href="/post/post-02/">Post 2</a></li>
</ul>
</main>
<!--all your other baseof.html code-->
<!--bottom of your baseof-->
```
{{% /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" %}}
```html
<!--baseof.html code-->
<main class="main">
<!--baseof-->
<main>
<article>
<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>
</header>
</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-02/">Quote 2</a></li>
</ul>
</main>
<!--baseof.html code-->
<!--baseof-->
```
{{% /code %}}
@ -171,23 +174,23 @@ The default behavior of Hugo is to pluralize list titles; hence the inflection o
### 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" %}}
```html
{{ partial "header.html" . }}
{{ partial "subheader.html" . }}
<section id="main">
<main>
<div>
<h1 id="title">{{ .Title }}</h1>
<ul id="list">
<h1>{{ .Title }}</h1>
<ul>
<!-- Renders the li.html content view for each content/post/*.md -->
{{ range .Data.Pages }}
{{ .Render "li"}}
{{ end }}
</ul>
</div>
</section>
</main>
{{ partial "footer.html" . }}
```
{{% /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" %}}
```html
{{ define "main" }}
<section id="main">
<main>
<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 }}
{{ .Render "summary"}}
{{ end }}
</div>
</section>
</main>
{{ end }}
```
{{% /code %}}
## 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
your list templates:
### Default List Ordering: Weight > Date
### Default: Weight > Date
{{% code file="layouts/partials/order-default.html" %}}
{{% code file="layouts/partials/default-order.html" %}}
```html
<ul class="pages">
<ul>
{{ range .Data.Pages }}
<li>
<h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
@ -235,12 +236,14 @@ your list templates:
{{% code file="layouts/partials/by-weight.html" %}}
```html
{{ range .Data.Pages.ByWeight }}
<li>
<a href="{{ .Permalink }}">{{ .Title }}</a>
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
</li>
{{ end }}
<ul>
{{ range .Data.Pages.ByWeight }}
<li>
<h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
<time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
```
{{% /code %}}
@ -248,12 +251,15 @@ your list templates:
{{% code file="layouts/partials/by-date.html" %}}
```html
{{ range .Data.Pages.ByDate }}
<li>
<a href="{{ .Permalink }}">{{ .Title }}</a>
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
</li>
{{ end }}
<ul>
<!-- orders content according to the "date" field in front matter -->
{{ range .Data.Pages.ByDate }}
<li>
<h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
<time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
```
{{% /code %}}
@ -261,12 +267,15 @@ your list templates:
{{% code file="layouts/partials/by-publish-date.html" %}}
```html
{{ range .Data.Pages.ByPublishDate }}
<li>
<a href="{{ .Permalink }}">{{ .Title }}</a>
<div class="meta">{{ .PublishDate.Format "Mon, Jan 2, 2006" }}</div>
</li>
{{ end }}
<ul>
<!-- orders content according to the "publishdate" field in front matter -->
{{ range .Data.Pages.ByPublishDate }}
<li>
<h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
<time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
```
{{% /code %}}
@ -274,12 +283,14 @@ your list templates:
{{% code file="layouts/partials/by-expiry-date.html" %}}
```html
{{ range .Data.Pages.ByExpiryDate }}
<li>
<a href="{{ .Permalink }}">{{ .Title }}</a>
<div class="meta">{{ .ExpiryDate.Format "Mon, Jan 2, 2006" }}</div>
</li>
{{ end }}
<ul>
{{ range .Data.Pages.ByExpiryDate }}
<li>
<h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
<time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
```
{{% /code %}}
@ -287,12 +298,15 @@ your list templates:
{{% code file="layouts/partials/by-last-mod.html" %}}
```html
{{ range .Data.Pages.ByLastmod }}
<li>
<a href="{{ .Permalink }}">{{ .Title }}</a>
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
</li>
{{ end }}
<ul>
<!-- orders content according to the "lastmod" field in front matter -->
{{ range .Data.Pages.ByLastmod }}
<li>
<h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
<time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
```
{{% /code %}}
@ -300,26 +314,31 @@ your list templates:
{{% code file="layouts/partials/by-length.html" %}}
```html
{{ range .Data.Pages.ByLength }}
<li>
<a href="{{ .Permalink }}">{{ .Title }}</a>
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
</li>
{{ end }}
<ul>
<!-- orders content according to content length in ascending order (i.e., the shortest content will be listed first) -->
{{ range .Data.Pages.ByLength }}
<li>
<h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
<time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
```
{{% /code %}}
### By Title
{{% code file="layouts/partials/by-title.html" %}}
```html
{{ range .Data.Pages.ByTitle }}
<li>
<a href="{{ .Permalink }}">{{ .Title }}</a>
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
</li>
{{ end }}
<ul>
<!-- ranges through content in ascending order according to the "title" field set in front matter -->
{{ range .Data.Pages.ByTitle }}
<li>
<h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
<time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
```
{{% /code %}}
@ -327,12 +346,15 @@ your list templates:
{{% code file="layouts/partials/by-link-title.html" %}}
```html
{{ range .Data.Pages.ByLinkTitle }}
<li>
<a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
</li>
{{ end }}
<ul>
<!-- 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 -->
{{ range .Data.Pages.ByLinkTitle }}
<li>
<h1><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></h1>
<time>{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
</li>
{{ end }}
</ul>
```
{{% /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.
The below example sorts a list of posts by their rating.
{{% code file="layouts/partials/by-rating.html" %}}
```html
<!-- Ranges through a list of content according to the "rating" field set in front matter -->
{{ range (.Data.Pages.ByParam "rating") }}
<!-- ... -->
{{ end }}
@ -355,6 +376,7 @@ also get it:
{{% code file="layouts/partials/by-nested-param.html" %}}
```html
{{ range (.Data.Pages.ByParam "author.last_name") }}
<!-- ... -->
{{ end }}
@ -569,10 +591,11 @@ Using `first` and `where` together can be very powerful:
```
{{% /code %}}
[base]: /templates/base/
[bepsays]: http://bepsays.com/en/2016/12/19/hugo-018/
[directorystructure]: /getting-started/directory-structure/
[`Format` function]: /functions/format/
[front matter]: /content-management/front-matter/
[homepage]: /templates/homepage/
[homepage]: /templates/homepage/
[limitkeyword]: https://www.techonthenet.com/sql/select_limit.php