mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
08e1ea5c70
1ad3c75ad theme: Run ncu -u to update dependencies (#3311) 2942d3753 content: Update version refs e298fdfaf content: Remove ref to old version c1fc876ea content: Improve taxonomic weight example d706a013d content: Document additional functions 5751c37cc content: Standardize string function signatures d65e6fae7 misc: Add data/docs.yaml to ignorePaths in cspell config ba1f98a32 content: Improve collections.First/Last string examples d7b5a2efd content: Improve collections.First/Last examples e94e49db2 content: Add Smart Hugo to editor plugins af204597a content: Clarify config description 9d1cb33cd content: Fix typo dded23962 content: Clarify note on rare use case for PageRef method 8af9e3be4 content: Update the Homebrew installation description be56390b3 content: Clarify command description fa228e9f0 content: Clarify AsciiDoc extensions setting description 3a23a4af2 docs: Add best practices for manual summary marker placement 050d7c75e misc: Fix cspell configuration 74642b18d content: Miscellaneous edits 75a2c8425 content: Add missing reference definitions6303f27e1content: Improve description of the SITE.Home method4dfbd647fRevert the minimal analytics changes (#3265)c369e534dtheme: Move tracking to turbo:load88b451022theme: Move tracking to turbo:render7040dc5eeMove to minimalanalytics for GA tracking4e8a523fbcontent: Update KaTeX link attributes to v0.16.25 (phase 2)21046b942content: Update KaTeX link attributes to v0.16.25 (phase 1)b8df9d941theme: Use Path for the glossary link destinationacd6c2954theme: Use page Path when generating Markdown links543f78340content: Fix formattingaef89d192content: Correct page collection quick-reference data08645236acontent: Use RSS output format in shortcode lookup example58654c106content: Fix archetype lookup order9f79bacc4content: Describe valid uses of the nil keyword41f139d14theme: Remove the root view transition6ab407bb9content: Improve links on lang.Translate page91e724065content: Add missing fragments to links in the module mounts description2f6b4a58ccontent: Clarify ByCount sort order8594590b2Update netlify.toml811574060content: Update version referencesa12bcf7ddcontent: Update version references23ca199edUpdate netlify.toml5d3da2351content: Update version references1617ee75bmisc: Update Netlify config to build with v0.152.06467bda93content: Remove outdated new-in badges4b3ef4bd5content: Improve description of default mount behavior5a861f500content: Revise partials.IncludeCached description and signature2ad9d705acontent: Correct the partials.IncludeCached signature9f611b879Update netlify.tomlca21f5fbdcontent: Add warning about automatic summaries2065faddecontent: Update commit message guidelinesa0784f261content: Remove outdated new-in badgesce5a249f2content: Remove Codeberg Pages documentation3424b95f2content: Update CLI docs27fd350a6content: Change KaTeX version references to 0.16.23ba8c5fd3bcontent: Change MathJax version reference from v3 to v4c83465222content: Fix broken linkc6cde1074content: Update version references467277939content: Fix typoe424b6b19content: Document new features in v0.151.0a46898f79Update netlify.tomlf8407c3b5content: Enhance content view template details974175690content: Optionally disable whitespace trimming in fenced code blocks25bffc4c4Update netlify.toml98e9ef5f0theme: Move initColorScheme() to heada1566495btheme: Preload fonts (#3209)c0271d266content: Add missing word in deploy-with-rsync.md47099c4facontent: Remove outdated new-in badges439b5c18bcontent: Fix collections.D seed exampled2486ba67content: Update description of IsNode method4de8815e9content: Update description of the cascade front matter field0801e9b3fcontent: Fix broken link9bbbfb59dcontent: Update Netlify hosting guide and version refs4f444fb53misc: Update docs.yamla7a9a7563Update module.mda7909fe37Update netlify.toml47a2c2038content: Update collections.D page to remove casting noteecca5ef48content: Update summaryLength description with default value310e11195content: Change alias examplebd6b53b5dcontent: Update minify config documentation21bb0bb66Update netlify.toml68912f1a3content: Update version reference28a47a50fcontent: Fix missing link to latest release under Prebuilt Binaries8eac2a120theme: Revise inline code span styling2e71b6d0aAdjust sponsord93340a78content: Update documentation guide9f6213ebecontent: Fix glob pattern-alternatives syntax in cascade.md1f61fd6becontent: Add seed examples to collections.D65385a5d0content: Fix Cloudflare deploy not_found_handling value4f70df235content: Fix typofc216f2d9content: Fix broken linke98b340f2Update cascade.mde316dbf93content: Update version referencesf8e863e97misc: Remove textlint config file3b9c3e2a1content: Miscellaneous updates related to v0.149.03ccc439fcUpdate netlify.toml07f5140e8Merge branch 'tempv0.149.0'17f8d33d8content: Add format option to transform.Unmarshala6a971596content: Document the collections.D function66eee712bcontent: Update front matter configuration example863945e13content: Update fmt.Println example1d9a92bc7theme: Don't exclude current section from related content1386d8ed2Update introduction.md0ac89b015content: Replace inline URLs with autolinks54fad1e01content: Fix typoe09f6b0c5content: Wrap calls to eturl shortcode in angle brackets23efd9766Merge commit 'bfa74537929f409fca841540b971125b7678963a'e98754e72resources/page: Add :sectionslug and :sectionslugs permalink tokens git-subtree-dir: docs git-subtree-split: 1ad3c75ad0e997d66598c1453db9989fde7d9680
2.4 KiB
2.4 KiB
title, description, categories, keywords, params
| title | description | categories | keywords | params | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| resources.FromString | Returns a resource created from a string. |
|
The resources.FromString function returns a resource created from a string, caching the result using the target path as its cache key.
Hugo publishes the resource to the target path when you call its Publish, Permalink, or RelPermalink methods.
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:
{
"build_date": "2025-07-08T13:12:19-07:00",
"hugo_version": "0.152.2",
"last_modified": "2025-07-07T22:09:13-07:00"
}
Place this in your baseof.html template:
{{ if .IsHome }}
{{ $rfc3339 := "2006-01-02T15:04:05Z07:00" }}
{{ $m := dict
"hugo_version" hugo.Version
"build_date" (now.Format $rfc3339)
"last_modified" (site.Lastmod.Format $rfc3339)
}}
{{ $json := jsonify $m }}
{{ $r := resources.FromString "site.json" $json }}
{{ $r.Publish }}
{{ end }}
The example above:
- Creates a map with the relevant key-value pairs using the
dictfunction - Encodes the map as a JSON string using the
jsonifyfunction - Creates a resource from the JSON string using the
resources.FromStringfunction - Publishes the file to the root of the
publicdirectory using the resource's.Publishmethod
Combine resources.FromString with resources.ExecuteAsTemplate if your string contains template actions. Rewriting the example above:
{{ if .IsHome }}
{{ $string := `
{{ $rfc3339 := "2006-01-02T15:04:05Z07:00" }}
{{ $m := dict
"hugo_version" hugo.Version
"build_date" (now.Format $rfc3339)
"last_modified" (site.Lastmod.Format $rfc3339)
}}
{{ $json := jsonify $m }}
`
}}
{{ $r := resources.FromString "" $string }}
{{ $r = $r | resources.ExecuteAsTemplate "site.json" . }}
{{ $r.Publish }}
{{ end }}