Update Hugo docs with the initialisms suggested by golint

In particular:

 * .Url → .URL (for node, menu and paginator)
 * .Site.BaseUrl → .Site.BaseURL
 * getJson → getJSON
 * getCsv → getCSV
 * safeHtml → safeHTML
 * safeCss → safeCSS
 * safeUrl → safeURL

Continued effort in fixing #959.
This commit is contained in:
Anthony Fok 2015-03-18 00:44:12 -06:00 committed by bep
parent 8b8fb417ae
commit b3bd71fec9
14 changed files with 87 additions and 87 deletions

View file

@ -67,7 +67,7 @@ This isn't in the front matter, but is the actual name of the file minus the
extension. This will be the name of the file in the destination.
### slug
Defined in the front matter, the slug can take the place of the filename for the
Defined in the front matter, the `slug` can take the place of the filename for the
destination.
### filepath
@ -75,18 +75,18 @@ The actual path to the file on disk. Destination will create the destination
with the same path. Includes [section](/content/sections/).
### section
section can be provided in the front matter overriding the section derived from
`section` can be provided in the front matter overriding the section derived from
the source content location on disk. See [section](/content/sections/).
### path
path can be provided in the front matter. This will replace the actual
`path` can be provided in the front matter. This will replace the actual
path to the file on disk. Destination will create the destination with the same
path. Includes [section](/content/sections/).
### url
A complete URL can be provided. This will override all the above as it pertains
to the end destination. This must be the path from the baseurl (starting with a "/").
When a url is provided, it will be used exactly. Using url will ignore the
to the end destination. This must be the path from the baseURL (starting with a "/").
When a `url` is provided, it will be used exactly. Using `url` will ignore the
`--uglyUrls` setting.
@ -116,27 +116,27 @@ When a url is provided, it will be used exactly. Using url will ignore the
http://spf13.com/projects/hugo
baseUrl section slug
baseURL section slug
⊢-----^--------⊣ ⊢--^---⊣ ⊢-^⊣
http://spf13.com/projects/hugo
baseUrl section slug
baseURL section slug
⊢-----^--------⊣ ⊢--^--⊣ ⊢--^--⊣
http://spf13.com/extras/indexes/example
baseUrl path slug
baseURL path slug
⊢-----^--------⊣ ⊢------^-----⊣ ⊢--^--⊣
http://spf13.com/extras/indexes/example
baseUrl url
baseURL url
⊢-----^--------⊣ ⊢-----^-----⊣
http://spf13.com/projects/hugo
baseUrl url
baseURL url
⊢-----^--------⊣ ⊢--------^-----------⊣
http://spf13.com/extras/indexes/example

View file

@ -19,8 +19,8 @@ any [JSON](http://www.json.org/) or
[CSV](http://en.wikipedia.org/wiki/Comma-separated_values) file
from nearly any resource.
"Dynamic Content" currently consists of two functions, `getJson`
and `getCsv`, which are available in **all template files**.
"Dynamic Content" currently consists of two functions, `getJSON`
and `getCSV`, which are available in **all template files**.
## Implementation details
@ -28,33 +28,33 @@ and `getCsv`, which are available in **all template files**.
In any HTML template or Markdown document, call the functions like this:
{{ $dataJ := getJson "url" }}
{{ $dataC := getCsv "separator" "url" }}
{{ $dataJ := getJSON "url" }}
{{ $dataC := getCSV "separator" "url" }}
or, if you use a prefix or postfix for the URL, the functions
accept [variadic arguments](http://en.wikipedia.org/wiki/Variadic_function):
{{ $dataJ := getJson "url prefix" "arg1" "arg2" "arg n" }}
{{ $dataC := getCsv "separator" "url prefix" "arg1" "arg2" "arg n" }}
{{ $dataJ := getJSON "url prefix" "arg1" "arg2" "arg n" }}
{{ $dataC := getCSV "separator" "url prefix" "arg1" "arg2" "arg n" }}
The separator for `getCsv` must be put in the first position and can only
The separator for `getCSV` must be put in the first position and can only
be one character long.
All passed arguments will be joined to the final URL; for example:
{{ $urlPre := "https://api.github.com" }}
{{ $gistJ := getJson $urlPre "/users/GITHUB_USERNAME/gists" }}
{{ $gistJ := getJSON $urlPre "/users/GITHUB_USERNAME/gists" }}
will resolve internally to:
{{ $gistJ := getJson "https://api.github.com/users/GITHUB_USERNAME/gists" }}
{{ $gistJ := getJSON "https://api.github.com/users/GITHUB_USERNAME/gists" }}
Finally, you can range over an array. This example will output the
first 5 gists for a GitHub user:
<ul>
{{ $urlPre := "https://api.github.com" }}
{{ $gistJ := getJson $urlPre "/users/GITHUB_USERNAME/gists" }}
{{ $gistJ := getJSON $urlPre "/users/GITHUB_USERNAME/gists" }}
{{ range first 5 $gistJ }}
{{ if .public }}
<li><a href="{{ .html_url }}" target="_blank">{{ .description }}</a></li>
@ -65,7 +65,7 @@ first 5 gists for a GitHub user:
### Example for CSV files
For `getCsv`, the one-character long separator must be placed in the
For `getCSV`, the one-character long separator must be placed in the
first position followed by the URL.
<table>
@ -79,7 +79,7 @@ first position followed by the URL.
<tbody>
{{ $url := "http://a-big-corp.com/finance/employee-salaries.csv" }}
{{ $sep := "," }}
{{ range $i, $r := getCsv $sep $url }}
{{ range $i, $r := getCSV $sep $url }}
<tr>
<td>{{ index $r 0 }}</td>
<td>{{ index $r 1 }}</td>
@ -113,7 +113,7 @@ other authentication methods are not implemented.
### Loading local files
To load local files with the two functions `getJson` and `getCsv`, the
To load local files with the two functions `getJSON` and `getCSV`, the
source files must reside within Hugo's working directory. The file
extension does not matter but the content.

View file

@ -27,7 +27,7 @@ access it via `.Site.Menus.main`.
A menu entry has the following properties:
* **Url** string
* **URL** string
* **Name** string
* **Menu** string
* **Identifier** string
@ -112,15 +112,15 @@ And the equivalent example `config.yaml`:
Pre: "<i class='fa fa-heart'></i>"
Weight: -110
Identifier: "about"
Url: "/about/"
URL: "/about/"
- Name: "getting started"
Pre: "<i class='fa fa-road'></i>"
Weight: -100
Url: "/getting-started/"
URL: "/getting-started/"
---
**NOTE:** The urls must be relative to the context root. If the `BaseUrl` is `http://example.com/mysite/`, then the urls in the menu must not include the context root `mysite`.
**NOTE:** The URLs must be relative to the context root. If the `BaseURL` is `http://example.com/mysite/`, then the URLs in the menu must not include the context root `mysite`.
## Nesting
@ -164,12 +164,12 @@ The following is an example:
</a>
<ul class="sub">
{{ range .Children }}
<li{{if $currentNode.IsMenuCurrent "main" . }} class="active"{{end}}><a href="{{.Url}}"> {{ .Name }} </a> </li>
<li{{if $currentNode.IsMenuCurrent "main" . }} class="active"{{end}}><a href="{{.URL}}"> {{ .Name }} </a> </li>
{{ end }}
</ul>
{{else}}
<li>
<a class="" href="{{.Url}}">
<a class="" href="{{.URL}}">
{{ .Pre }}
<span>{{ .Name }}</span>
</a>

View file

@ -22,7 +22,7 @@ Pagination can be configured in the site configuration (e.g. `config.toml`):
Setting `Paginate` to a positive value will split the list pages for the home page, sections and taxonomies into chunks of that size. But note that the generation of the pagination pages for sections, taxonomies and home page is *lazy* --- the pages will not be created if not referenced by a `.Paginator` (see below).
`PaginatePath` is used to adapt the `Url` to the pages in the paginator (the default setting will produce urls on the form `/page/1/`.
`PaginatePath` is used to adapt the `URL` to the pages in the paginator (the default setting will produce URLs on the form `/page/1/`.
## List the pages
@ -67,7 +67,7 @@ Without the where-filter, the above is simpler:
If you want to build custom navigation, you can do so using the `.Paginator` object:
* `PageNumber`: The current page's number in the pager sequence
* `Url`: The relative Url to the current pager
* `URL`: The relative URL to the current pager
* `Pages`: The pages in the current pager
* `NumberOfElements`: The number of elements on this page
* `HasPrev`: Whether there are page(s) before the current

View file

@ -74,12 +74,12 @@ Following is a list of Hugo-defined variables that you can configure and their c
---
archetypedir: "archetype"
# hostname (and path) to the root eg. http://spf13.com/
baseurl: ""
baseURL: ""
# include content marked as draft
buildDrafts: false
# include content with datePublished in the future
buildFuture: false
canonifyUrls: false
canonifyURLs: false
# config file (default is path/config.yaml|json|toml)
config: "config.toml"
contentdir: "content"
@ -128,7 +128,7 @@ Following is a list of Hugo-defined variables that you can configure and their c
theme: ""
title: ""
# if true, use /filename.html instead of /filename/
uglyUrls: false
uglyURLs: false
# verbose output
verbose: false
# verbose logging

View file

@ -52,7 +52,7 @@ content.
<ul>
{{ range .Site.Taxonomies.series.golang }}
<li><a href="{{ .Url }}">{{ .Name }}</a></li>
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
</ul>

View file

@ -67,7 +67,7 @@ It makes use of [partial templates](/templates/partials/)
{{ partial "header.html" . }}
{{ partial "subheader.html" . }}
{{ $baseurl := .Site.BaseUrl }}
{{ $baseurl := .Site.BaseURL }}
<section id="main">
<h1 id="title">{{ .Title }}</h1>
@ -116,7 +116,7 @@ It makes use of [partial templates](/templates/partials/)
{{ partial "header.html" . }}
{{ partial "subheader.html" . }}
{{ $baseurl := .Site.BaseUrl }}
{{ $baseurl := .Site.BaseURL }}
<section id="main">
<h1 id="title">{{ .Title }}</h1>

View file

@ -262,7 +262,7 @@ Takes a string and sanitizes it for usage in URLs, converts spaces to "-".
e.g. `<a href="/tags/{{ . | urlize }}">{{ . }}</a>`
### safeHtml
### safeHTML
Declares the provided string as a "safe" HTML document fragment
so Go html/template will not filter it. It should not be used
for HTML from a third-party, or HTML with unclosed tags or comments.
@ -271,11 +271,11 @@ Example: Given a site-wide `config.toml` that contains this line:
copyright = "© 2015 Jane Doe. <a href=\"http://creativecommons.org/licenses/by/4.0/\">Some rights reserved</a>."
`{{ .Site.Copyright | safeHtml }}` would then output:
`{{ .Site.Copyright | safeHTML }}` would then output:
> © 2015 Jane Doe. <a href="http://creativecommons.org/licenses/by/4.0/">Some rights reserved</a>.
However, without the `safeHtml` function, html/template assumes
However, without the `safeHTML` function, html/template assumes
`.Site.Copyright` to be unsafe, escaping all HTML tags,
rendering the whole string as plain-text like this:
@ -284,7 +284,7 @@ rendering the whole string as plain-text like this:
</blockquote>
<!--
### safeHtmlAttr
### safeHTMLAttr
Declares the provided string as a "safe" HTML attribute
from a trusted source, for example, ` dir="ltr"`,
so Go html/template will not filter it.
@ -295,11 +295,11 @@ Example: Given a site-wide `config.toml` that contains this menu entry:
name = "IRC: #golang at freenode"
url = "irc://irc.freenode.net/#golang"
* `<a href="{{ .Url }}">` ⇒ `<a href="#ZgotmplZ">` (Bad!)
* `<a {{ printf "href=%q" .Url | safeHtmlAttr }}>` ⇒ `<a href="irc://irc.freenode.net/#golang">` (Good!)
* `<a href="{{ .URL }}">` ⇒ `<a href="#ZgotmplZ">` (Bad!)
* `<a {{ printf "href=%q" .URL | safeHTMLAttr }}>` ⇒ `<a href="irc://irc.freenode.net/#golang">` (Good!)
-->
### safeCss
### safeCSS
Declares the provided string as a known "safe" CSS string
so Go html/templates will not filter it.
"Safe" means CSS content that matches any of:
@ -311,13 +311,13 @@ so Go html/templates will not filter it.
Example: Given `style = "color: red;"` defined in the front matter of your `.md` file:
* `<p style="{{ .Params.style | safeCss }}">…</p>` ⇒ `<p style="color: red;">…</p>` (Good!)
* `<p style="{{ .Params.style | safeCSS }}">…</p>` ⇒ `<p style="color: red;">…</p>` (Good!)
* `<p style="{{ .Params.style }}">…</p>``<p style="ZgotmplZ">…</p>` (Bad!)
Note: "ZgotmplZ" is a special value that indicates that unsafe content reached a
CSS or URL context.
### safeUrl
### safeURL
Declares the provided string as a "safe" URL or URL substring (see [RFC 3986][]).
A URL like `javascript:checkThatFormNotEditedBeforeLeavingPage()` from a trusted
source should go in the page, but by default dynamic `javascript:` URLs are
@ -325,7 +325,7 @@ filtered out since they are a frequently exploited injection vector.
[RFC 3986]: http://tools.ietf.org/html/rfc3986
Without `safeUrl`, only the URI schemes `http:`, `https:` and `mailto:`
Without `safeURL`, only the URI schemes `http:`, `https:` and `mailto:`
are considered safe by Go. If any other URI schemes, e.g.&nbsp;`irc:` and
`javascript:`, are detected, the whole URL would be replaced with
`#ZgotmplZ`. This is to "defang" any potential attack in the URL,
@ -341,16 +341,16 @@ The following template:
<ul class="sidebar-menu">
{{ range .Site.Menus.main }}
<li><a href="{{ .Url }}">{{ .Name }}</a></li>
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
</ul>
would produce `<li><a href="#ZgotmplZ">IRC: #golang at freenode</a></li>`
for the `irc://…` URL.
To fix this, add ` | safeUrl` after `.Url` on the 3rd line, like this:
To fix this, add ` | safeURL` after `.URL` on the 3rd line, like this:
<li><a href="{{ .Url | safeUrl }}">{{ .Name }}</a></li>
<li><a href="{{ .URL | safeURL }}">{{ .Name }}</a></li>
With this change, we finally get `<li><a href="irc://irc.freenode.net/#golang">IRC: #golang at freenode</a></li>`
as intended.

View file

@ -236,14 +236,14 @@ Could be rewritten as
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:
{{ "<!--[if lt IE 9]>" | safeHtml }}
{{ "<!--[if lt IE 9]>" | safeHTML }}
<script src="html5shiv.js"></script>
{{ "<![endif]-->" | safeHtml }}
{{ "<![endif]-->" | safeHTML }}
Alternatively, 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, e.g.:
```
{{ `<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"><![endif]-->` | safeHtml }}
{{ `<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"><![endif]-->` | safeHTML }}
```
## Context (a.k.a. the dot)
@ -355,7 +355,7 @@ January 1st, instead of hunting through your templates.
```
{{if .Site.Params.CopyrightHTML}}<footer>
<div class="text-center">{{.Site.Params.CopyrightHTML | safeHtml}}</div>
<div class="text-center">{{.Site.Params.CopyrightHTML | safeHTML}}</div>
</footer>{{end}}
```

View file

@ -56,7 +56,7 @@ It makes use of [partial templates](/templates/partials/) and uses a similar app
{{ partial "meta.html" . }}
<base href="{{ .Site.BaseUrl }}">
<base href="{{ .Site.BaseURL }}">
<title>{{ .Site.Title }}</title>
<link rel="canonical" href="{{ .Permalink }}">
<link href="{{ .RSSlink }}" rel="alternate" type="application/rss+xml" title="{{ .Site.Title }}" />

View file

@ -60,7 +60,7 @@ This header template is used for [spf13.com](http://spf13.com/):
{{ partial "meta.html" . }}
<base href="{{ .Site.BaseUrl }}">
<base href="{{ .Site.BaseURL }}">
<title> {{ .Title }} : spf13.com </title>
<link rel="canonical" href="{{ .Permalink }}">
{{ if .RSSlink }}<link href="{{ .RSSlink }}" rel="alternate" type="application/rss+xml" title="{{ .Title }}" />{{ end }}

View file

@ -39,7 +39,7 @@ Protocol](http://www.sitemaps.org/protocol.html).
{{ range .Data.Pages }}
<url>
<loc>{{ .Permalink }}</loc>
<lastmod>{{ safeHtml ( .Date.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ with .Sitemap.ChangeFreq }}
<lastmod>{{ safeHTML ( .Date.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ with .Sitemap.ChangeFreq }}
<changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
<priority>{{ .Sitemap.Priority }}</priority>{{ end }}
</url>

View file

@ -72,7 +72,7 @@ includes taxonomies, lists and the homepage.
**.Title** The title for the content.<br>
**.Date** The date the content is published on.<br>
**.Permalink** The Permanent link for this node<br>
**.Url** The relative URL for this node.<br>
**.URL** The relative URL for this node.<br>
**.Ref(ref)** Returns the permalink for `ref`. See [cross-references]({{% ref "extras/crossreferences.md" %}}). Does not handle in-page fragments correctly.<br>
**.RelRef(ref)** Returns the relative permalink for `ref`. See [cross-references]({{% ref "extras/crossreferences.md" %}}). Does not handle in-page fragments correctly.<br>
**.RSSLink** Link to the taxonomies' RSS link.<br>
@ -86,7 +86,7 @@ includes taxonomies, lists and the homepage.
Also available is `.Site` which has the following:
**.Site.BaseUrl** The base URL for the site as defined in the site configuration file.<br>
**.Site.BaseURL** The base URL for the site as defined in the site configuration file.<br>
**.Site.Taxonomies** The [taxonomies](/taxonomies/usage/) for the entire site. Replaces the now-obsolete `.Site.Indexes` since v0.11.<br>
**.Site.LastChange** The date of the last change of the most recent content.<br>
**.Site.Pages** Array of all content ordered by Date, newest first. Replaces the now-deprecated `.Site.Recent` starting v0.13.<br>

View file

@ -16,12 +16,12 @@
</a>
<ul class="sub{{if $currentNode.HasMenuCurrent "main" . }} open{{end}}">
{{ range .Children }}
<li{{if $currentNode.IsMenuCurrent "main" . }} class="active"{{end}}><a href="{{.Url}}">{{ .Name }}</a> </li>
<li{{if $currentNode.IsMenuCurrent "main" . }} class="active"{{end}}><a href="{{.URL}}">{{ .Name }}</a> </li>
{{ end }}
</ul>
{{else}}
<li>
<a class="" href="{{.Url}}">
<a class="" href="{{.URL}}">
{{ .Pre }}
<!--<i class="icon_house_alt"></i>-->
<span>{{ .Name }}</span>