mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-09 14:55:48 -04:00
Replace blockquotes with admonitions where appropriate (#2043)
This commit is contained in:
parent
98226fe61e
commit
48bec0335a
@ -15,7 +15,7 @@ aliases: [/content/multilingual/,/tutorials/create-a-multilingual-site/]
|
||||
|
||||
You should define the available languages in a `languages` section in your site configuration.
|
||||
|
||||
> Also See [Hugo Multilingual Part 1: Content translation]
|
||||
Also See [Hugo Multilingual Part 1: Content translation].
|
||||
|
||||
## Configure Languages
|
||||
|
||||
@ -97,7 +97,9 @@ From **Hugo 0.31** we support multiple languages in a multihost configuration. S
|
||||
|
||||
This means that you can now configure a `baseURL` per `language`:
|
||||
|
||||
> If a `baseURL` is set on the `language` level, then all languages must have one and they must all be different.
|
||||
{{% note %}}
|
||||
If a `baseURL` is set on the `language` level, then all languages must have one and they must all be different.
|
||||
{{% /note %}}
|
||||
|
||||
Example:
|
||||
|
||||
|
@ -122,7 +122,9 @@ You set up the working copy of the repository locally on your computer. Your loc
|
||||
|
||||
We assume that you've set up your `GOPATH` (see the section above if you're unsure about this). You should now copy the Hugo repository down to your computer. You'll hear this called "clone the repo". GitHub's [help pages](https://help.github.com/articles/cloning-a-repository/) give us a short explanation:
|
||||
|
||||
> When you create a repository on GitHub, it exists as a remote repository. You can create a local clone of your repository on your computer and sync between the two locations.
|
||||
{{% note %}}
|
||||
When you create a repository on GitHub, it exists as a remote repository. You can create a local clone of your repository on your computer and sync between the two locations.
|
||||
{{% /note %}}
|
||||
|
||||
We're going to clone the [master Hugo repository](https://github.com/gohugoio/hugo). That seems counter-intuitive, since you won't have commit rights on it. But it's required for the Go workflow. You'll work on a copy of the master and push your changes to your own repository on GitHub.
|
||||
|
||||
@ -134,8 +136,7 @@ cd $HOME/src
|
||||
git clone https://github.com/gohugoio/hugo.git
|
||||
```
|
||||
|
||||
> Since Hugo 0.48, Hugo uses the Go Modules support built into Go 1.11 to build.
|
||||
> The easiest is to clone Hugo in a directory outside of GOPATH
|
||||
Since Hugo 0.48, Hugo uses the Go Modules support built into Go 1.11 to build. The easiest is to clone Hugo in a directory outside of GOPATH
|
||||
|
||||
And then, install dependencies of Hugo by running the following in the cloned directory:
|
||||
|
||||
@ -154,7 +155,9 @@ go install github.com/magefile/mage@latest
|
||||
|
||||
If you're not familiar with this term, GitHub's [help pages](https://help.github.com/articles/fork-a-repo/) provide again a simple explanation:
|
||||
|
||||
> A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.
|
||||
{{% note %}}
|
||||
A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.
|
||||
{{% /note %}}
|
||||
|
||||
#### Fork by hand
|
||||
|
||||
|
@ -1,54 +1,44 @@
|
||||
---
|
||||
title: len
|
||||
description: Returns the length of a variable according to its type.
|
||||
description: Returns the length of a string, slice, map, or collection.
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
keywords: []
|
||||
keywords: [length]
|
||||
signature: ["len INPUT"]
|
||||
relatedfuncs: []
|
||||
---
|
||||
|
||||
`len` is a built-in function in Go that returns the length of a variable according to its type. From the Go documentation:
|
||||
With a string:
|
||||
|
||||
> Array: the number of elements in v.
|
||||
>
|
||||
> Pointer to array: the number of elements in *v (even if v is nil).
|
||||
>
|
||||
> Slice, or map: the number of elements in v; if v is nil, len(v) is zero.
|
||||
>
|
||||
> String: the number of bytes in v.
|
||||
>
|
||||
> Channel: the number of elements queued (unread) in the channel buffer; if v is nil, len(v) is zero.
|
||||
```go-html-template
|
||||
{{ "ab" | len }} → 2
|
||||
{{ "" | len }} → 0
|
||||
```
|
||||
|
||||
`len` is also considered a [fundamental function for Hugo templating].
|
||||
With a slice:
|
||||
|
||||
## `len` Example 1: Longer Headings
|
||||
```go-html-template
|
||||
{{ slice "a" "b" | len }} → 2
|
||||
{{ slice | len }} → 0
|
||||
```
|
||||
|
||||
You may want to append a class to a heading according to the length of the string therein. The following templating checks to see if the title's length is greater than 80 characters and, if so, adds a `long-title` class to the `<h1>`:
|
||||
With a map:
|
||||
|
||||
{{< code file="check-title-length.html" >}}
|
||||
<header>
|
||||
<h1{{ if gt (len .Title) 80 }} class="long-title"{{ end }}>{{ .Title }}</h1>
|
||||
</header>
|
||||
{{< /code >}}
|
||||
```go-html-template
|
||||
{{ dict "a" 1 "b" 2 | len }} → 2
|
||||
{{ dict | len }} → 0
|
||||
```
|
||||
|
||||
## `len` Example 2: Counting Pages with `where`
|
||||
With a collection:
|
||||
|
||||
The following templating uses [`where`] in conjunction with `len` to
|
||||
figure out the total number of content pages in a `posts` [section]:
|
||||
```go-html-template
|
||||
{{ site.RegularPages | len }} → 42
|
||||
```
|
||||
|
||||
{{< code file="how-many-posts.html" >}}
|
||||
{{ $posts := (where .Site.RegularPages "Section" "==" "posts") }}
|
||||
{{ $postCount := len $posts }}
|
||||
{{< /code >}}
|
||||
You may also determine the number of pages in a collection with:
|
||||
|
||||
Note the use of `.RegularPages`, a [site variable] that counts all regular content pages but not the `_index.md` pages used to add front matter and content to [list templates].
|
||||
|
||||
|
||||
[fundamental function for Hugo templating]: /templates/introduction/
|
||||
[list templates]: /templates/lists/
|
||||
[section]: /content-management/sections/
|
||||
[site variable]: /variables/site/
|
||||
[`where`]: /functions/where/
|
||||
```go-html-template
|
||||
{{ site.RegularPages.Len }} → 42
|
||||
```
|
||||
|
@ -36,5 +36,4 @@ If you need to pass additional parameters to create unique variants, you can pas
|
||||
|
||||
Note that the variant parameters are not made available to the underlying partial template. They are only use to create a unique cache key. Since Hugo `0.61.0` you can use any object as cache key(s), not just strings.
|
||||
|
||||
|
||||
> See also [The Full Partial Series Part 1: Caching!](https://regisphilibert.com/blog/2019/12/hugo-partial-series-part-1-caching-with-partialcached/)
|
||||
See also [The Full Partial Series Part 1: Caching!](https://regisphilibert.com/blog/2019/12/hugo-partial-series-part-1-caching-with-partialcached/).
|
||||
|
Loading…
x
Reference in New Issue
Block a user