From 2e954d8551088455472ce50318c0000623a945e6 Mon Sep 17 00:00:00 2001 From: tummychow Date: Wed, 26 Mar 2014 08:03:11 -0400 Subject: [PATCH] Fix permalinks to subdomains If you don't have access to the root domain of your site (eg a GitHub project page) and you try to generate custom permalinks, they must begin with a slash. Go's URL resolution library sees the leading slash and thinks "this URL starts at the root", just like a filesystem - so it discards your subdomain and maps all custom permalinks from the root of your site. Fine if you control the root domain, not so useful if you don't. Removing the check for a leading slash fixes this problem. You can now specify custom permalinks that do not start with a slash, and they will map safely regardless of what subdomain you upload the generated site under. Tests have been updated for this commit so that they continue to function. --- hugolib/permalinks.go | 3 --- hugolib/permalinks_test.go | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/hugolib/permalinks.go b/hugolib/permalinks.go index 155b1b813..f6c2ec80d 100644 --- a/hugolib/permalinks.go +++ b/hugolib/permalinks.go @@ -26,9 +26,6 @@ var knownPermalinkAttributes map[string]PageToPermaAttribute // validate determines if a PathPattern is well-formed func (pp PathPattern) validate() bool { - if pp[0] != '/' { - return false - } fragments := strings.Split(string(pp[1:]), "/") var bail = false for i := range fragments { diff --git a/hugolib/permalinks_test.go b/hugolib/permalinks_test.go index 019b23c2f..f1439d987 100644 --- a/hugolib/permalinks_test.go +++ b/hugolib/permalinks_test.go @@ -14,9 +14,8 @@ var testdataPermalinks = []struct { }{ {"/:year/:month/:title/", true, "/2012/04/spf13-vim-3.0-release-and-new-website/"}, {"/:title", true, "/spf13-vim-3.0-release-and-new-website"}, - {":title", false, ""}, + {":title", true, "spf13-vim-3.0-release-and-new-website"}, {"/blog/:year/:yearday/:title", true, "/blog/2012/97/spf13-vim-3.0-release-and-new-website"}, - {":fred", false, ""}, {"/blog/:fred", false, ""}, {"/:year//:title", false, ""}, {