mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-29 15:10:35 +03:00
Merge commit '9d68f695e7
'
This commit is contained in:
commit
b6a30283f0
47 changed files with 294 additions and 87 deletions
|
@ -25,4 +25,4 @@ See [Installing Hugo][installpygments] for more information on Pygments or [Synt
|
|||
|
||||
[highlight]: /content-management/shortcodes/#highlight
|
||||
[installpygments]: /getting-started/installing/#installing-pygments-optional
|
||||
[syntax]: /tools/syntax-highlighting/
|
||||
[syntax]: /content-management/syntax-highlighting/
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
title: Math
|
||||
description: Hugo provides six mathematical operators in templates.
|
||||
description: Hugo provides nine mathematical operators in templates.
|
||||
godocref:
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
|
@ -20,14 +20,14 @@ draft: false
|
|||
aliases: []
|
||||
---
|
||||
|
||||
There are 6 basic mathematical operators that can be used in Hugo templates:
|
||||
|
||||
| Function | Description | Example |
|
||||
| -------- | ------------------------ | ----------------------------- |
|
||||
| `add` | Adds two integers. | `{{add 1 2}}` → 3 |
|
||||
| `div` | Divides two integers. | `{{div 6 3}}` → 2 |
|
||||
| `mod` | Modulus of two integers. | `{{mod 15 3}}` → 0 |
|
||||
| `modBool`| Boolean of modulus of two integers. Evaluates to `true` if = 0. | `{{modBool 15 3}}` → true |
|
||||
| `mul` | Multiplies two integers. | `{{mul 2 3}}` → 6 |
|
||||
| `sub` | Subtracts two integers. | `{{sub 3 2}}` → 1 |
|
||||
|
||||
| Function | Description | Example |
|
||||
|----------------|-------------------------------------------------------------------------------|----------------------------------|
|
||||
| `add` | Adds two integers. | `{{add 1 2}}` → 3 |
|
||||
| `div` | Divides two integers. | `{{div 6 3}}` → 2 |
|
||||
| `mod` | Modulus of two integers. | `{{mod 15 3}}` → 0 |
|
||||
| `modBool` | Boolean of modulus of two integers. Evaluates to `true` if result equals 0. | `{{modBool 15 3}}` → true |
|
||||
| `mul` | Multiplies two integers. | `{{mul 2 3}}` → 6 |
|
||||
| `sub` | Subtracts two integers. | `{{sub 3 2}}` → 1 |
|
||||
| `math.Ceil` | Returns the least integer value greater than or equal to the given number. | `{{math.Ceil 2.1}}` → 3 |
|
||||
| `math.Floor` | Returns the greatest integer value less than or equal to the given number. | `{{math.Floor 1.9}}` → 1 |
|
||||
| `math.Round` | Returns the nearest integer, rounding half away from zero. | `{{math.Round 1.5}}` → 2 |
|
||||
|
|
26
docs/content/functions/print.md
Normal file
26
docs/content/functions/print.md
Normal file
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
title: print
|
||||
linktitle: print
|
||||
description: Prints the default representation of the given argument using the standard `fmt.Print` function.
|
||||
godocref: https://golang.org/pkg/fmt/
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [strings]
|
||||
signature: ["print INPUT"]
|
||||
workson: []
|
||||
hugoversion:
|
||||
relatedfuncs: []
|
||||
deprecated: false
|
||||
---
|
||||
|
||||
See [the go doc](https://golang.org/pkg/fmt/) for additional information.
|
||||
|
||||
```
|
||||
{{ print "foo" }} → "foo"
|
||||
{{ print (slice 1 2 3) }} → [1 2 3]
|
||||
```
|
25
docs/content/functions/println.md
Normal file
25
docs/content/functions/println.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
title: println
|
||||
linktitle: println
|
||||
description: Prints the default representation of the given argument using the standard `fmt.Print` function and enforces a linebreak.
|
||||
godocref: https://golang.org/pkg/fmt/
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [strings]
|
||||
signature: ["println INPUT"]
|
||||
workson: []
|
||||
hugoversion:
|
||||
relatedfuncs: []
|
||||
deprecated: false
|
||||
---
|
||||
|
||||
See [the go doc](https://golang.org/pkg/fmt/) for additional information. `\n` denotes the linebreak but isn't printed in the templates as seen below:
|
||||
|
||||
```
|
||||
{{ println "foo" }} → "foo\n"
|
||||
```
|
28
docs/content/functions/strings.TrimLeft.md
Normal file
28
docs/content/functions/strings.TrimLeft.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
title: strings.TrimLeft
|
||||
description: Returns a slice of a given string with all leading characters contained in the cutset removed.
|
||||
godocref:
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [strings]
|
||||
signature: ["strings.TrimLeft CUTSET STRING"]
|
||||
workson: []
|
||||
hugoversion:
|
||||
relatedfuncs: [strings.TrimRight]
|
||||
deprecated: false
|
||||
aliases: []
|
||||
---
|
||||
|
||||
Given the string `"abba"`, leading `"a"`'s can be removed a follows:
|
||||
|
||||
{{ strings.TrimLeft "abba" "a" }} → "bba"
|
||||
|
||||
Numbers can be handled as well:
|
||||
|
||||
{{ strings.TrimLeft 1221 "12" }} → ""
|
||||
|
25
docs/content/functions/strings.TrimPrefix.md
Normal file
25
docs/content/functions/strings.TrimPrefix.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
title: strings.TrimPrefix
|
||||
description: Returns a given string s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.
|
||||
godocref:
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [strings]
|
||||
signature: ["strings.TrimPrefix PREFIX STRING"]
|
||||
workson: []
|
||||
hugoversion:
|
||||
relatedfuncs: [strings.TrimSuffix]
|
||||
deprecated: false
|
||||
aliases: []
|
||||
---
|
||||
|
||||
Given the string `"aabbaa"`, the specified prefix is only removed if `"aabbaa"` starts with it:
|
||||
|
||||
{{ strings.TrimPrefix "a" "aabbaa" }} → "abbaa"
|
||||
{{ strings.TrimPrefix "aa" "aabbaa" }} → "bbaa"
|
||||
{{ strings.TrimPrefix "aaa" "aabbaa" }} → "aabbaa"
|
28
docs/content/functions/strings.TrimRight.md
Normal file
28
docs/content/functions/strings.TrimRight.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
title: strings.TrimRight
|
||||
description: Returns a slice of a given string with all trailing characters contained in the cutset removed.
|
||||
godocref:
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [strings]
|
||||
signature: ["strings.TrimRight CUTSET STRING"]
|
||||
workson: []
|
||||
hugoversion:
|
||||
relatedfuncs: [strings.TrimRight]
|
||||
deprecated: false
|
||||
aliases: []
|
||||
---
|
||||
|
||||
Given the string `"abba"`, trailing `"a"`'s can be removed a follows:
|
||||
|
||||
{{ strings.TrimRight "abba" "a" }} → "abb"
|
||||
|
||||
Numbers can be handled as well:
|
||||
|
||||
{{ strings.TrimRight 1221 "12" }} → ""
|
||||
|
25
docs/content/functions/strings.TrimSuffix.md
Normal file
25
docs/content/functions/strings.TrimSuffix.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
title: strings.TrimSuffix
|
||||
description: Returns a given string s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.
|
||||
godocref:
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [strings]
|
||||
signature: ["strings.TrimSuffix SUFFIX STRING"]
|
||||
workson: []
|
||||
hugoversion:
|
||||
relatedfuncs: [strings.TrimPrefix]
|
||||
deprecated: false
|
||||
aliases: []
|
||||
---
|
||||
|
||||
Given the string `"aabbaa"`, the specified suffix is only removed if `"aabbaa"` ends with it:
|
||||
|
||||
{{ strings.TrimSuffix "a" "aabbaa" }} → "aabba"
|
||||
{{ strings.TrimSuffix "aa" "aabbaa" }} → "aabb"
|
||||
{{ strings.TrimSuffix "aaa" "aabbaa" }} → "aabbaa"
|
32
docs/content/functions/urls.Parse.md
Normal file
32
docs/content/functions/urls.Parse.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
---
|
||||
title: urls.Parse
|
||||
description: Parse parses a given url, which may be relative or absolute, into a URL structure.
|
||||
godocref: https://godoc.org/net/url#URL
|
||||
date: 2017-09-25
|
||||
publishdate: 2017-09-25
|
||||
lastmod: 2017-09-25
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [urls]
|
||||
signature: ["urls.Parse URL"]
|
||||
workson: []
|
||||
hugoversion:
|
||||
deprecated: false
|
||||
aliases: []
|
||||
---
|
||||
|
||||
`urls.Parse` takes a url as input
|
||||
|
||||
|
||||
```
|
||||
{{ $url := urls.Parse "http://www.gohugo.io" }}
|
||||
```
|
||||
|
||||
and returns a [URL](https://godoc.org/net/url#URL) structure. The struct fields are accessed via the `.` notation:
|
||||
|
||||
```
|
||||
{{ $url.Scheme }} → "http"
|
||||
{{ $url.Host }} → "www.gohugo.io"
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue