From 87188496fbb68c39567ec3ee3a55a9305a13e48b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 24 Mar 2017 11:25:25 +0100 Subject: [PATCH] hugolib, output: Handle aliases for all HTML formats --- hugolib/alias.go | 12 ------------ hugolib/alias_test.go | 34 ++++++++++++++++++++++++++++++++++ hugolib/page_output.go | 16 ++++++++++------ hugolib/site_render.go | 20 ++++++++++++++++---- output/outputFormat.go | 6 ++++++ output/outputFormat_test.go | 11 +++++++++++ 6 files changed, 77 insertions(+), 22 deletions(-) diff --git a/hugolib/alias.go b/hugolib/alias.go index 7120e6086..d5eb35777 100644 --- a/hugolib/alias.go +++ b/hugolib/alias.go @@ -88,18 +88,6 @@ func (s *Site) publishDestAlias(allowRoot bool, path, permalink string, p *Page) isXHTML := strings.HasSuffix(path, ".xhtml") - if s.Info.relativeURLs { - // convert `permalink` into URI relative to location of `path` - baseURL := helpers.SanitizeURLKeepTrailingSlash(s.Cfg.GetString("baseURL")) - if strings.HasPrefix(permalink, baseURL) { - permalink = "/" + strings.TrimPrefix(permalink, baseURL) - } - permalink, err = helpers.GetRelativePath(permalink, path) - if err != nil { - s.Log.ERROR.Println("Failed to make a RelativeURL alias:", path, "redirecting to", permalink) - } - permalink = filepath.ToSlash(permalink) - } s.Log.DEBUG.Println("creating alias:", path, "redirecting to", permalink) targetPath, err := handler.targetPathAlias(path) 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 = "{{.Content}}" const aliasTemplate = "ALIASTEMPLATE" @@ -51,6 +59,32 @@ func TestAlias(t *testing.T) { th.assertFileContent(filepath.Join("public", "foo", "bar", "index.html"), "