mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-26 13:40:38 +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
|
@ -82,6 +82,25 @@ title: Test Metadata
|
|||
"title": "Test Metadata"
|
||||
}
|
||||
`
|
||||
xmlExample := `<root>
|
||||
<resources>
|
||||
<params>
|
||||
<byline>picasso</byline>
|
||||
</params>
|
||||
<src>**image-4.png</src>
|
||||
<title>The Fourth Image!</title>
|
||||
</resources>
|
||||
<resources>
|
||||
<name>my-cool-image-:counter</name>
|
||||
<params>
|
||||
<byline>bep</byline>
|
||||
</params>
|
||||
<src>**.png</src>
|
||||
<title>TOML: The Image #:counter</title>
|
||||
</resources>
|
||||
<title>Test Metadata</title>
|
||||
</root>
|
||||
`
|
||||
|
||||
variants := []struct {
|
||||
format string
|
||||
|
@ -93,6 +112,7 @@ title: Test Metadata
|
|||
{"TOML", tomlExample},
|
||||
{"Toml", tomlExample},
|
||||
{" TOML ", tomlExample},
|
||||
{"XML", xmlExample},
|
||||
}
|
||||
|
||||
for _, v1 := range variants {
|
||||
|
|
|
@ -111,6 +111,9 @@ func TestUnmarshal(t *testing.T) {
|
|||
{testContentResource{key: "r1", content: `slogan = "Hugo Rocks!"`, mime: media.TOMLType}, nil, func(m map[string]interface{}) {
|
||||
assertSlogan(m)
|
||||
}},
|
||||
{testContentResource{key: "r1", content: `<root><slogan>Hugo Rocks!</slogan></root>"`, mime: media.XMLType}, nil, func(m map[string]interface{}) {
|
||||
assertSlogan(m)
|
||||
}},
|
||||
{testContentResource{key: "r1", content: `1997,Ford,E350,"ac, abs, moon",3000.00
|
||||
1999,Chevy,"Venture ""Extended Edition""","",4900.00`, mime: media.CSVType}, nil, func(r [][]string) {
|
||||
c.Assert(len(r), qt.Equals, 2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue