From 22683a3b669c06c49457c816475213fcef3e789c Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Tue, 19 Apr 2016 11:40:15 +1000 Subject: [PATCH] Make alias redirect output URL's relative Closes #2093 --- hugolib/site.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hugolib/site.go b/hugolib/site.go index 14643fe0a..7537fe8fd 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -2095,7 +2095,19 @@ func (s *Site) writeDestPage(path string, publisher target.Publisher, reader io. } func (s *Site) writeDestAlias(path string, permalink string) (err error) { - jww.DEBUG.Println("creating alias:", path) + if viper.GetBool("RelativeURLs") { + // convert `permalink` into URI relative to location of `path` + baseURL := helpers.SanitizeURLKeepTrailingSlash(viper.GetString("BaseURL")) + if strings.HasPrefix(permalink, baseURL) { + permalink = "/" + strings.TrimPrefix(permalink, baseURL) + } + permalink, err = helpers.GetRelativePath(permalink, path) + if err != nil { + jww.ERROR.Println("Failed to make a RelativeURL alias:", path, "redirecting to", permalink) + } + permalink = filepath.ToSlash(permalink) + } + jww.DEBUG.Println("creating alias:", path, "redirecting to", permalink) return s.aliasTarget().Publish(path, permalink) }