summaryrefslogtreecommitdiffstats
path: root/hugolib/alias_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-03-24 11:25:25 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-03-27 15:43:56 +0200
commit87188496fbb68c39567ec3ee3a55a9305a13e48b (patch)
treeb70e4c3ce41c4d97fe70ce8cb06c4ee0e819084c /hugolib/alias_test.go
parent0c4701f0effbf651891979b925073f6fc5d26a82 (diff)
downloadhugo-87188496fbb68c39567ec3ee3a55a9305a13e48b.tar.gz
hugo-87188496fbb68c39567ec3ee3a55a9305a13e48b.zip
hugolib, output: Handle aliases for all HTML formats
Diffstat (limited to 'hugolib/alias_test.go')
-rw-r--r--hugolib/alias_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/hugolib/alias_test.go b/hugolib/alias_test.go
index f5e6d8d1f..68ec8f07f 100644
--- a/hugolib/alias_test.go
+++ b/hugolib/alias_test.go
@@ -29,6 +29,14 @@ aliases: ["foo/bar/"]
For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.
`
+const pageWithAliasMultipleOutputs = `---
+title: Has Alias for HTML and AMP
+aliases: ["foo/bar/"]
+outputs: ["HTML", "AMP", "JSON"]
+---
+For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.
+`
+
const basicTemplate = "<html><body>{{.Content}}</body></html>"
const aliasTemplate = "<html><body>ALIASTEMPLATE</body></html>"
@@ -51,6 +59,32 @@ func TestAlias(t *testing.T) {
th.assertFileContent(filepath.Join("public", "foo", "bar", "index.html"), "<meta http-equiv=\"refresh\" content=\"0; ")
}
+func TestAliasMultipleOutputFormats(t *testing.T) {
+ t.Parallel()
+
+ var (
+ cfg, fs = newTestCfg()
+ th = testHelper{cfg, fs, t}
+ )
+
+ writeSource(t, fs, filepath.Join("content", "page.md"), pageWithAliasMultipleOutputs)
+ writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), basicTemplate)
+ writeSource(t, fs, filepath.Join("layouts", "_default", "single.amp.html"), basicTemplate)
+ writeSource(t, fs, filepath.Join("layouts", "_default", "single.json"), basicTemplate)
+
+ buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
+
+ // the real pages
+ th.assertFileContent(filepath.Join("public", "page", "index.html"), "For some moments the old man")
+ th.assertFileContent(filepath.Join("public", "amp", "page", "index.html"), "For some moments the old man")
+ th.assertFileContent(filepath.Join("public", "page", "index.json"), "For some moments the old man")
+
+ // the alias redirectors
+ th.assertFileContent(filepath.Join("public", "foo", "bar", "index.html"), "<meta http-equiv=\"refresh\" content=\"0; ")
+ th.assertFileContent(filepath.Join("public", "foo", "bar", "amp", "index.html"), "<meta http-equiv=\"refresh\" content=\"0; ")
+ require.False(t, destinationExists(th.Fs, filepath.Join("public", "foo", "bar", "index.json")))
+}
+
func TestAliasTemplate(t *testing.T) {
t.Parallel()