mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 06:00:25 +03:00
Implement XML data support
Example: ``` {{ with resources.Get "https://example.com/rss.xml" | transform.Unmarshal }} {{ range .channel.item }} <strong>{{ .title | plainify | htmlUnescape }}</strong><br /> <p>{{ .description | plainify | htmlUnescape }}</p> {{ $link := .link | plainify | htmlUnescape }} <a href="{{ $link }}">{{ $link }}</a><br /> <hr> {{ end }} {{ end }} ``` Closes #4470
This commit is contained in:
parent
58adbeef88
commit
0eaaa8fee3
12 changed files with 167 additions and 12 deletions
|
@ -591,9 +591,9 @@ func TestResourceChains(t *testing.T) {
|
|||
|
||||
case "/mydata/xml1.xml":
|
||||
w.Write([]byte(`
|
||||
<hello>
|
||||
<world>Hugo Rocks!</<world>
|
||||
</hello>`))
|
||||
<hello>
|
||||
<world>Hugo Rocks!</<world>
|
||||
</hello>`))
|
||||
return
|
||||
|
||||
case "/mydata/svg1.svg":
|
||||
|
@ -872,16 +872,19 @@ Publish 2: {{ $cssPublish2.Permalink }}
|
|||
{{ $toml := "slogan = \"Hugo Rocks!\"" | resources.FromString "slogan.toml" | transform.Unmarshal }}
|
||||
{{ $csv1 := "\"Hugo Rocks\",\"Hugo is Fast!\"" | resources.FromString "slogans.csv" | transform.Unmarshal }}
|
||||
{{ $csv2 := "a;b;c" | transform.Unmarshal (dict "delimiter" ";") }}
|
||||
{{ $xml := "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note><to>You</to><from>Me</from><heading>Reminder</heading><body>Do not forget XML</body></note>" | transform.Unmarshal }}
|
||||
|
||||
Slogan: {{ $toml.slogan }}
|
||||
CSV1: {{ $csv1 }} {{ len (index $csv1 0) }}
|
||||
CSV2: {{ $csv2 }}
|
||||
XML: {{ $xml.body }}
|
||||
`)
|
||||
}, func(b *sitesBuilder) {
|
||||
b.AssertFileContent("public/index.html",
|
||||
`Slogan: Hugo Rocks!`,
|
||||
`[[Hugo Rocks Hugo is Fast!]] 2`,
|
||||
`CSV2: [[a b c]]`,
|
||||
`XML: Do not forget XML`,
|
||||
)
|
||||
}},
|
||||
{"resources.Get", func() bool { return true }, func(b *sitesBuilder) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue