hugolib: Handle shortcode per output format

This commit allows shortcode per output format, a typical use case would be the special AMP media tags.

Note that this will only re-render the "overridden" shortcodes and only  in pages where these are used, so performance in the normal case should not suffer.

Closes #3220
This commit is contained in:
Bjørn Erik Pedersen 2017-05-06 20:15:28 +02:00
parent e951d65771
commit af72db806f
10 changed files with 398 additions and 65 deletions

View file

@ -99,6 +99,8 @@ title: "%s"
outputs: %s
---
# Doc
{{< myShort >}}
`
mf := afero.NewMemMapFs()
@ -118,6 +120,8 @@ other = "Olboge"
"layouts/partials/GoHugo.html", `Go Hugo Partial`,
"layouts/_default/baseof.json", `START JSON:{{block "main" .}}default content{{ end }}:END JSON`,
"layouts/_default/baseof.html", `START HTML:{{block "main" .}}default content{{ end }}:END HTML`,
"layouts/shortcodes/myShort.html", `ShortHTML`,
"layouts/shortcodes/myShort.json", `ShortJSON`,
"layouts/_default/list.json", `{{ define "main" }}
List JSON|{{ .Title }}|{{ .Content }}|Alt formats: {{ len .AlternativeOutputFormats -}}|
@ -141,6 +145,7 @@ List HTML|{{.Title }}|
{{ .Site.Language.Lang }}: {{ T "elbow" -}}
Partial Hugo 1: {{ partial "GoHugo.html" . }}
Partial Hugo 2: {{ partial "GoHugo" . -}}
Content: {{ .Content }}
{{ end }}
`,
)
@ -180,6 +185,7 @@ Partial Hugo 2: {{ partial "GoHugo" . -}}
"Output/Rel: JSON/alternate|",
"Output/Rel: HTML/canonical|",
"en: Elbow",
"ShortJSON",
)
th.assertFileContent("public/index.html",
@ -187,6 +193,7 @@ Partial Hugo 2: {{ partial "GoHugo" . -}}
// parsed with html/template.
`List HTML|JSON Home|<atom:link href=http://example.com/blog/ rel="self" type="text/html&#43;html" />`,
"en: Elbow",
"ShortHTML",
)
th.assertFileContent("public/nn/index.html",
"List HTML|JSON Nynorsk Heim|",
@ -196,10 +203,12 @@ Partial Hugo 2: {{ partial "GoHugo" . -}}
"Output/Rel: JSON/canonical|",
// JSON is plain text, so no need to safeHTML this and that
`<atom:link href=http://example.com/blog/index.json rel="self" type="application/json+json" />`,
"ShortJSON",
)
th.assertFileContent("public/nn/index.json",
"List JSON|JSON Nynorsk Heim|",
"nn: Olboge",
"ShortJSON",
)
}