diff --git a/content/en/about/features.md b/content/en/about/features.md index 9c8fac4f4..11f9f65b7 100644 --- a/content/en/about/features.md +++ b/content/en/about/features.md @@ -51,13 +51,11 @@ toc: true * Integrated [Disqus][] comment support * Integrated [Google Analytics][] support * Automatic [RSS][] creation -* Support for [Go][], [Amber], and [Ace][] HTML templates +* Support for [Go][] HTML templates * [Syntax highlighting][] powered by [Chroma][] -[Ace]: /templates/alternatives/ [aliases]: /content-management/urls/#aliases -[Amber]: https://github.com/eknkc/amber [Chroma]: https://github.com/alecthomas/chroma [content summaries]: /content-management/summaries/ [content types]: /content-management/types/ diff --git a/content/en/content-management/cross-references.md b/content/en/content-management/cross-references.md index 21a73b861..9570a8fa4 100644 --- a/content/en/content-management/cross-references.md +++ b/content/en/content-management/cross-references.md @@ -15,31 +15,39 @@ aliases: [/extras/crossreferences/] toc: true --- - -The `ref` and `relref` shortcode resolves the absolute or relative permalink given a path to a document. +The `ref` and `relref` shortcodes display the absolute and relative permalinks to a document, respectively. ## Use `ref` and `relref` ```go-html-template +{{}} +{{}} {{}} -{{}} {{}} +{{}} {{}} {{}} +{{}} {{}} {{}} -{{}} +{{}} ``` -The single parameter to `ref` is a string with a content `documentname` (e.g., `about.md`) with or without an appended in-document `anchor` (`#who`) without spaces. Hugo is flexible in how we search for documents, so the file suffix may be omitted. +To generate a hyperlink using `ref` or `relref` in markdown: -**Paths without a leading `/` will first be tried resolved relative to the current page.** +```md +[About]({{}} "About Us") +``` -You will get an error if your document could not be uniquely resolved. The error behaviour can be configured, see below. +The `ref` and `relref` shortcodes require a single parameter: the path to a content document, with or without a file extension, with or without an anchor. + +**Paths without a leading `/` are first resolved relative to the current page, then to the remainder of the site. + +Hugo emits an error or warning if a document cannot be uniquely resolved. The error behavior is configurable; see below. ### Link to another language version -Link to another language version of a document, you need to use this syntax: +To link to another language version of a document, use this syntax: ```go-html-template {{}} @@ -47,45 +55,66 @@ Link to another language version of a document, you need to use this syntax: ### Get another Output Format -To link to a given Output Format of a document, you can use this syntax: +To link to another Output Format of a document, use this syntax: ```go-html-template {{}} ``` -### Anchors +### Heading IDs -When an `anchor` is provided by itself, the current page’s unique identifier will be appended; when an `anchor` is provided appended to `documentname`, the found page's unique identifier will be appended: +When using Markdown document types, Hugo generates element IDs for every heading on a page. For example: -```go-html-template -{{}} => #anchors:9decaf7 +```md +## Reference ``` -The above examples render as follows for this very page as well as a reference to the "Content" heading in the Hugo docs features pageyoursite +produces this HTML: -```go-html-template -{{}} => #who:9decaf7 -{{}} => /blog/post/#who:badcafe +```html +

Reference

``` -More information about document unique identifiers and headings can be found [below]({{< ref "#hugo-heading-anchors" >}}). - -## Hugo Heading Anchors - -When using Markdown document types, Hugo generates heading anchors automatically. The generated anchor for this section is `hugo-heading-anchors`. Because the heading anchors are generated automatically, Hugo takes some effort to ensure that heading anchors are unique both inside a document and across the entire site. - -Ensuring heading uniqueness across the site is accomplished with a unique identifier for each document based on its path. Unless a document is renamed or moved between sections *in the filesystem*, the unique identifier for the document will not change: `blog/post.md` will always have a unique identifier of `81df004c333b392d34a49fd3a91ba720`. - -`ref` and `relref` were added so you can make these reference links without having to know the document’s unique identifier. (The links in document tables of contents are automatically up-to-date with this value.) +Get the permalink to a heading by appending the ID to the path when using the `ref` or `relref` shortcodes: +```md +{{}} +{{}} ``` -{{}} -/content-management/cross-references/#hugo-heading-anchors:77cd9ea530577debf4ce0f28c8dca242 + +Generate a custom heading ID by including an attribute. For example: + +```md +## Reference A {#foo} +## Reference B {id="bar"} +``` + +produces this HTML: + +```html +

Reference A

+

Reference B

+``` + +Hugo will generate unique element IDs if the same heading appears more than once on a page. For example: + +```md +## Reference +## Reference +## Reference +``` + +produces this HTML: + +```html +

Reference

+

Reference

+

Reference

``` ## Ref and RelRef Configuration -The behaviour can, since Hugo 0.45, be configured in `config.toml`: +The behavior can, since Hugo 0.45, be configured in `config.toml`: refLinksErrorLevel ("ERROR") : When using `ref` or `relref` to resolve page links and a link cannot resolved, it will be logged with this log level. Valid values are `ERROR` (default) or `WARNING`. Any `ERROR` will fail the build (`exit -1`). diff --git a/content/en/content-management/multilingual.md b/content/en/content-management/multilingual.md index ccf794b2e..224f38d7a 100644 --- a/content/en/content-management/multilingual.md +++ b/content/en/content-management/multilingual.md @@ -316,44 +316,83 @@ See https://github.com/gohugoio/hugo/issues/3564 {{% /note %}} +### Query basic translation + From within your templates, use the `i18n` function like this: ``` {{ i18n "home" }} ``` -This uses a definition like this one in `i18n/en-US.toml`: +The function will search for the `"home"` id from `i18n/en-US.toml` file: ``` [home] other = "Home" ``` -Often you will want to use to the page variables in the translations strings. To do that, pass on the "." context when calling `i18n`: +The result will be + +``` +Home +``` + +### Query a flexible translation with variables + +Often you will want to use to the page variables in the translations strings. To do that, pass on the `.` context when calling `i18n`: ``` {{ i18n "wordCount" . }} ``` -This uses a definition like this one in `i18n/en-US.toml`: +The function will pass the `.` context to the `"wordCount"` id in `i18n/en-US.toml` file: ``` [wordCount] other = "This article has {{ .WordCount }} words." ``` -An example of singular and plural form: + +Assume `.WordCount` in the context has value is 101. The result will be: + +``` +This article has 101 words. +``` + +### Query a singular/plural translation + +In other to meet singular/plural requirement, you must pass a dictionary (map) data with a numeric `.Count` property to the `i18n` function. The below example uses `.ReadingTime` variable which has a built-in `.Count` property. + +``` +{{ i18n "readingTime" .ReadingTime }} +``` + +The function will read `.Count` from `.ReadingTime` and evaluate where the number is singular (`one`) or plural (`other`). After that, it will pass to `readingTime` id in `i18n/en-US.toml` file: ``` [readingTime] one = "One minute to read" other = "{{.Count}} minutes to read" ``` -And then in the template: + +Assume `.ReadingTime.Count` in the context has value is 525600. The result will be: ``` -{{ i18n "readingTime" .ReadingTime }} +525600 minutes to read ``` +If `.ReadingTime.Count` in the context has value is 1. The result is: + +``` +One minutes to read +``` + +In case you need to pass a custom data: (`"(dict Count" 25)` is minimum requirment) + +``` +{{ i18n "readingTime" (dict "Count" 25 "FirstArgument" true "SecondArgument" false "Etc" "so on, so far") }} +``` + + ## Customize Dates At the time of this writing, Go does not yet have support for internationalized locales for dates, but if you do some work, you can simulate it. For example, if you want to use French month names, you can add a data file like ``data/mois.yaml`` with this content: diff --git a/content/en/functions/ref.md b/content/en/functions/ref.md index feac06c97..0ec249c61 100644 --- a/content/en/functions/ref.md +++ b/content/en/functions/ref.md @@ -1,17 +1,17 @@ --- title: ref linktitle: ref -description: Looks up a content page by logical name. +description: Returns the absolute permalink to a page. godocref: date: 2017-02-01 publishdate: 2017-02-01 -lastmod: 2019-12-28 +lastmod: 2020-09-05 categories: [functions] menu: docs: parent: "functions" keywords: [cross references, anchors] -signature: ["ref . CONTENT"] +signature: ["ref . PAGE"] workson: [] hugoversion: relatedfuncs: [relref] @@ -19,22 +19,33 @@ deprecated: false aliases: [] --- -`ref` and `relref` look up a content page by logical name (`ref`) or relative path (`relref`) to return the permalink: +This function takes two parameters: -``` +- The context of the page from which to resolve relative paths, typically the current page (`.`) +- The path to a page, with or without a file extension, with or without an anchor. A path without a leading `/` is first resolved relative to the given context, then to the remainder of the site. + +```go-html-template +{{ ref . "about" }} +{{ ref . "about#anchor" }} {{ ref . "about.md" }} +{{ ref . "about.md#anchor" }} +{{ ref . "#anchor" }} +{{ ref . "/blog/my-post" }} +{{ ref . "/blog/my-post.md" }} ``` -{{% note "Usage Note" %}} -`ref` looks up Hugo "Regular Pages" only. It can't be used for the homepage, section pages, etc. -{{% /note %}} +To return the absolute permalink to another language version of a page: -It is also possible to pass additional arguments to link to another language or an alternative output format. Therefore, pass a map of arguments instead of just the path. - -``` -{{ ref . (dict "path" "about.md" "lang" "ja" "outputFormat" "rss") }} +```go-html-template +{{ ref . (dict "path" "about.md" "lang" "fr") }} ``` -These functions are used in two of Hugo's built-in shortcodes. You can see basic usage examples of both `ref` and `relref` in the [shortcode documentation](/content-management/shortcodes/#ref-and-relref). +To return the absolute permalink to another Output Format of a page: -For an extensive explanation of how to leverage `ref` and `relref` for content management, see [Cross References](/content-management/cross-references/). +```go-html-template +{{ ref . (dict "path" "about.md" "outputFormat" "rss") }} +``` + +Hugo emits an error or warning if the page cannot be uniquely resolved. The error behavior is configurable; see [Ref and RelRef Configuration](/content-management/cross-references/#ref-and-relref-configuration). + +This function is used by Hugo's built-in [`ref`](/content-management/shortcodes/#ref-and-relref) shortcode. For a detailed explanation of how to leverage this shortcode for content management, see [Links and Cross References](/content-management/cross-references/). diff --git a/content/en/functions/relref.md b/content/en/functions/relref.md index fe5699053..18f65f1f8 100644 --- a/content/en/functions/relref.md +++ b/content/en/functions/relref.md @@ -1,17 +1,17 @@ --- title: relref -# linktitle: relref -description: Looks up a content page by relative path. +linktitle: relref +description: Returns the relative permalink to a page. godocref: date: 2017-02-01 publishdate: 2017-02-01 -lastmod: 2019-12-28 +lastmod: 2020-09-05 categories: [functions] menu: docs: parent: "functions" keywords: [cross references, anchors] -signature: ["relref . CONTENT"] +signature: ["relref . PAGE"] workson: [] hugoversion: relatedfuncs: [ref] @@ -19,22 +19,40 @@ deprecated: false aliases: [] --- -`ref` and `relref` look up a content page by logical name (`ref`) or relative path (`relref`) to return the permalink: +This function takes two parameters: -``` +- The context of the page from which to resolve relative paths, typically the current page (`.`) +- The path to a page, with or without a file extension, with or without an anchor. A path without a leading `/` is first resolved relative to the given context, then to the remainder of the site. + +```go-html-template +{{ relref . "about" }} +{{ relref . "about#anchor" }} {{ relref . "about.md" }} +{{ relref . "about.md#anchor" }} +{{ relref . "#anchor" }} +{{ relref . "/blog/my-post" }} +{{ relref . "/blog/my-post.md" }} ``` -{{% note "Usage Note" %}} -`relref` looks up Hugo "Regular Pages" only. It can't be used for the homepage, section pages, etc. -{{% /note %}} +The permalink returned is relative to the protocol+host portion of the baseURL specified in the site configuration. For example: -It is also possible to pass additional arguments to link to another language or an alternative output format. Therefore, pass a map of arguments instead of just the path. +Code|baseURL|Permalink +:--|:--|:-- +`{{ relref . "/about" }}`|`http://example.org/`|`/about/` +`{{ relref . "/about" }}`|`http://example.org/x/`|`/x/about/` -``` -{{ relref . (dict "path" "about.md" "lang" "ja" "outputFormat" "rss") }} +To return the relative permalink to another language version of a page: + +```go-html-template +{{ relref . (dict "path" "about.md" "lang" "fr") }} ``` -These functions are used in two of Hugo's built-in shortcodes. You can see basic usage examples of both `ref` and `relref` in the [shortcode documentation](/content-management/shortcodes/#ref-and-relref). +To return the relative permalink to another Output Format of a page: -For an extensive explanation of how to leverage `ref` and `relref` for content management, see [Cross References](/content-management/cross-references/). +```go-html-template +{{ relref . (dict "path" "about.md" "outputFormat" "rss") }} +``` + +Hugo emits an error or warning if the page cannot be uniquely resolved. The error behavior is configurable; see [Ref and RelRef Configuration](/content-management/cross-references/#ref-and-relref-configuration). + +This function is used by Hugo's built-in [`relref`](/content-management/shortcodes/#ref-and-relref) shortcode. For a detailed explanation of how to leverage this shortcode for content management, see [Links and Cross References](/content-management/cross-references/). diff --git a/content/en/functions/urlize.md b/content/en/functions/urlize.md index 0fd7c2295..0742dd029 100644 --- a/content/en/functions/urlize.md +++ b/content/en/functions/urlize.md @@ -53,8 +53,8 @@ The preceding partial would then output to the rendered page as follows, assumin {{< output file="/blog/greatest-city/index.html" >}}
-

The World's Greatest City

-
Chicago IL
+

The World's Greatest City

+
Chicago IL