diff options
author | Bjørn Erik Pedersen <[email protected]> | 2017-03-22 09:54:56 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2017-03-27 15:43:56 +0200 |
commit | c7dbee2321af2f0d61bdc976829681f3799582a9 (patch) | |
tree | fe92dc2115586b210c6efc34fbffcda7a6a4f341 /hugolib/site_output_test.go | |
parent | 29d3778ba10f806cc2e252c4eec0f3798905c9a6 (diff) | |
download | hugo-c7dbee2321af2f0d61bdc976829681f3799582a9.tar.gz hugo-c7dbee2321af2f0d61bdc976829681f3799582a9.zip |
hugolib, output: Add Rel to the output format
To make it super-easy to create rel-links.
Diffstat (limited to 'hugolib/site_output_test.go')
-rw-r--r-- | hugolib/site_output_test.go | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/hugolib/site_output_test.go b/hugolib/site_output_test.go index 12746e88b..85b3291fe 100644 --- a/hugolib/site_output_test.go +++ b/hugolib/site_output_test.go @@ -15,12 +15,14 @@ package hugolib import ( "reflect" + "strings" "testing" "github.com/stretchr/testify/require" "fmt" + "github.com/spf13/hugo/helpers" "github.com/spf13/hugo/output" "github.com/spf13/viper" ) @@ -47,9 +49,19 @@ func TestDefaultOutputDefinitions(t *testing.T) { } } -func TestSiteWithJSONHomepage(t *testing.T) { +func TestSiteWithPageOutputs(t *testing.T) { + for _, outputs := range [][]string{{"html", "json"}, {"json"}} { + t.Run(fmt.Sprintf("%v", outputs), func(t *testing.T) { + doTestSiteWithPageOutputs(t, outputs) + }) + } +} + +func doTestSiteWithPageOutputs(t *testing.T, outputs []string) { t.Parallel() + outputsStr := strings.Replace(fmt.Sprintf("%q", outputs), " ", ", ", -1) + siteConfig := ` baseURL = "http://example.com/blog" @@ -65,19 +77,26 @@ category = "categories" pageTemplate := `--- title: "%s" -outputs: ["html", "json"] +outputs: %s --- # Doc ` th, h := newTestSitesFromConfig(t, siteConfig, - "layouts/_default/list.json", "List JSON|{{ .Title }}|{{ .Content }}", + "layouts/_default/list.json", `List JSON|{{ .Title }}|{{ .Content }}|Alt formats: {{ len .AlternativeOutputFormats -}}| +{{- range .AlternativeOutputFormats -}} +Alt Output: {{ .Name -}}| +{{- end -}}| +{{- range .OutputFormats -}} +Output/Rel: {{ .Name -}}/{{ .Rel }}| +{{- end -}} +`, ) require.Len(t, h.Sites, 1) fs := th.Fs - writeSource(t, fs, "content/_index.md", fmt.Sprintf(pageTemplate, "JSON Home")) + writeSource(t, fs, "content/_index.md", fmt.Sprintf(pageTemplate, "JSON Home", outputsStr)) err := h.Build(BuildCfg{}) @@ -88,17 +107,38 @@ outputs: ["html", "json"] require.NotNil(t, home) - require.Len(t, home.outputFormats, 2) + lenOut := len(outputs) + + require.Len(t, home.outputFormats, lenOut) // TODO(bep) output assert template/text + // There is currently always a JSON output to make it simpler ... + altFormats := lenOut - 1 + hasHTML := helpers.InStringArray(outputs, "html") + th.assertFileContent("public/index.json", + "List JSON", + fmt.Sprintf("Alt formats: %d", altFormats), + ) - th.assertFileContent("public/index.json", "List JSON") + if hasHTML { + th.assertFileContent("public/index.json", + "Alt Output: HTML", + "Output/Rel: JSON/alternate|", + "Output/Rel: HTML/canonical|", + ) + } else { + th.assertFileContent("public/index.json", + "Output/Rel: JSON/canonical|", + ) + } of := home.OutputFormats() - require.Len(t, of, 2) + require.Len(t, of, lenOut) require.Nil(t, of.Get("Hugo")) require.NotNil(t, of.Get("json")) json := of.Get("JSON") + _, err = home.AlternativeOutputFormats() + require.Error(t, err) require.NotNil(t, json) require.Equal(t, "/blog/index.json", json.RelPermalink()) require.Equal(t, "http://example.com/blog/index.json", json.Permalink()) |