mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-08 19:59:23 +03:00
Merge commit '8b9803425e
'
This commit is contained in:
commit
af0cb57aaf
475 changed files with 7408 additions and 4720 deletions
|
@ -15,17 +15,17 @@ The `resources.FromString` function returns a resource created from a string, ca
|
|||
|
||||
Hugo publishes the resource to the target path when you call its [`Publish`], [`Permalink`], or [`RelPermalink`] methods.
|
||||
|
||||
[`publish`]: /methods/resource/publish
|
||||
[`permalink`]: /methods/resource/permalink
|
||||
[`relpermalink`]: /methods/resource/relpermalink
|
||||
[`publish`]: /methods/resource/publish/
|
||||
[`permalink`]: /methods/resource/permalink/
|
||||
[`relpermalink`]: /methods/resource/relpermalink/
|
||||
|
||||
Let's say you need to publish a file named "site.json" in the root of your public directory, containing the build date, the Hugo version used to build the site, and the date that the content was last modified. For example:
|
||||
|
||||
```json
|
||||
{
|
||||
"build_date": "2023-10-03T10:50:40-07:00",
|
||||
"hugo_version": "0.122.0",
|
||||
"last_modified": "2023-10-02T15:21:27-07:00"
|
||||
"build_date": "2024-02-19T12:27:05-08:00",
|
||||
"hugo_version": "0.126.0",
|
||||
"last_modified": "2024-02-19T12:01:42-08:00"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -37,7 +37,7 @@ Place this in your baseof.html template:
|
|||
{{ $m := dict
|
||||
"hugo_version" hugo.Version
|
||||
"build_date" (now.Format $rfc3339)
|
||||
"last_modified" (site.LastChange.Format $rfc3339)
|
||||
"last_modified" (site.Lastmod.Format $rfc3339)
|
||||
}}
|
||||
{{ $json := jsonify $m }}
|
||||
{{ $r := resources.FromString "site.json" $json }}
|
||||
|
@ -47,7 +47,7 @@ Place this in your baseof.html template:
|
|||
|
||||
The example above:
|
||||
|
||||
1. Creates a map with the relevant key/value pairs using the [`dict`] function
|
||||
1. Creates a map with the relevant key-value pairs using the [`dict`] function
|
||||
2. Encodes the map as a JSON string using the [`jsonify`] function
|
||||
3. Creates a resource from the JSON string using the `resources.FromString` function
|
||||
4. Publishes the file to the root of the public directory using the resource's `.Publish` method
|
||||
|
@ -61,7 +61,7 @@ Combine `resources.FromString` with [`resources.ExecuteAsTemplate`] if your stri
|
|||
{{ $m := dict
|
||||
"hugo_version" hugo.Version
|
||||
"build_date" (now.Format $rfc3339)
|
||||
"last_modified" (site.LastChange.Format $rfc3339)
|
||||
"last_modified" (site.Lastmod.Format $rfc3339)
|
||||
}}
|
||||
{{ $json := jsonify $m }}
|
||||
`
|
||||
|
@ -72,6 +72,6 @@ Combine `resources.FromString` with [`resources.ExecuteAsTemplate`] if your stri
|
|||
{{ end }}
|
||||
```
|
||||
|
||||
[`dict`]: /functions/collections/dictionary
|
||||
[`jsonify`]: /functions/encoding/jsonify
|
||||
[`resources.ExecuteAsTemplate`]: /functions/resources/executeastemplate
|
||||
[`dict`]: /functions/collections/dictionary/
|
||||
[`jsonify`]: /functions/encoding/jsonify/
|
||||
[`resources.ExecuteAsTemplate`]: /functions/resources/executeastemplate/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue