summaryrefslogtreecommitdiffhomepage
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2018-09-18 09:27:49 +0200
committerBjørn Erik Pedersen <[email protected]>2018-09-18 09:27:49 +0200
commit058cc6c2c3f72bdc4a703380a6d9cb39afe3dd2f (patch)
tree9eb69209ba38e674455f1657829c3e5538317f5a /hugolib
parent4b82f74848836efbcf453c0122bd35555ee7517d (diff)
downloadhugo-058cc6c2c3f72bdc4a703380a6d9cb39afe3dd2f.tar.gz
hugo-058cc6c2c3f72bdc4a703380a6d9cb39afe3dd2f.zip
Revert "hugolib: Normalize permalink path segments"
This reverts commit 06976ebb8778e08fea89dbd9fcb875f6c8d650d4. Fixes #5223
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/permalinks.go20
-rw-r--r--hugolib/permalinks_test.go40
2 files changed, 30 insertions, 30 deletions
diff --git a/hugolib/permalinks.go b/hugolib/permalinks.go
index 69dc3eca7..7640db6c1 100644
--- a/hugolib/permalinks.go
+++ b/hugolib/permalinks.go
@@ -154,7 +154,7 @@ func pageToPermalinkDate(p *Page, dateField string) (string, error) {
func pageToPermalinkTitle(p *Page, _ string) (string, error) {
// Page contains Node which has Title
// (also contains URLPath which has Slug, sometimes)
- return p.s.PathSpec.MakeSegment(p.title), nil
+ return p.s.PathSpec.URLize(p.title), nil
}
// pageToPermalinkFilename returns the URL-safe form of the filename
@@ -166,7 +166,7 @@ func pageToPermalinkFilename(p *Page, _ string) (string, error) {
_, name = filepath.Split(dir)
}
- return p.s.PathSpec.MakeSegment(name), nil
+ return p.s.PathSpec.URLize(name), nil
}
// if the page has a slug, return the slug, else return the title
@@ -181,30 +181,20 @@ func pageToPermalinkSlugElseTitle(p *Page, a string) (string, error) {
if strings.HasSuffix(p.Slug, "-") {
p.Slug = p.Slug[0 : len(p.Slug)-1]
}
- return p.s.PathSpec.MakeSegment(p.Slug), nil
+ return p.s.PathSpec.URLize(p.Slug), nil
}
return pageToPermalinkTitle(p, a)
}
func pageToPermalinkSection(p *Page, _ string) (string, error) {
// Page contains Node contains URLPath which has Section
- return p.s.PathSpec.MakeSegment(p.Section()), nil
+ return p.Section(), nil
}
func pageToPermalinkSections(p *Page, _ string) (string, error) {
// TODO(bep) we have some superflous URLize in this file, but let's
// deal with that later.
-
- cs := p.CurrentSection()
- if cs == nil {
- return "", errors.New("\":sections\" attribute requires parent page but is nil")
- }
-
- sections := make([]string, len(cs.sections))
- for i := range cs.sections {
- sections[i] = p.s.PathSpec.MakeSegment(cs.sections[i])
- }
- return path.Join(sections...), nil
+ return path.Join(p.CurrentSection().sections...), nil
}
func init() {
diff --git a/hugolib/permalinks_test.go b/hugolib/permalinks_test.go
index f9ff8e708..7a4bf78c2 100644
--- a/hugolib/permalinks_test.go
+++ b/hugolib/permalinks_test.go
@@ -19,26 +19,36 @@ import (
)
// testdataPermalinks is used by a couple of tests; the expandsTo content is
-// subject to the data in simplePageJSON.
+// subject to the data in SIMPLE_PAGE_JSON.
var testdataPermalinks = []struct {
spec string
valid bool
expandsTo string
}{
- {":title", true, "spf13-vim-3.0-release-and-new-website"},
+ //{"/: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", 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"},
{"/:year-:month-:title", true, "/2012-04-spf13-vim-3.0-release-and-new-website"},
-
- {"/:year/:yearday/:month/:monthname/:day/:weekday/:weekdayname/", true, "/2012/97/04/April/06/5/Friday/"}, // Dates
- {"/:section/", true, "/blue/"}, // Section
- {"/:title/", true, "/spf13-vim-3.0-release-and-new-website/"}, // Title
- {"/:slug/", true, "/spf13-vim-3-0-release-and-new-website/"}, // Slug
- {"/:filename/", true, "/test-page/"}, // Filename
- // TODO(moorereason): need test scaffolding for this.
- //{"/:sections/", false, "/blue/"}, // Sections
-
- // Failures
- {"/blog/:fred", false, ""},
- {"/:year//:title", false, ""},
+ {"/blog/:year-:month-:title", true, "/blog/2012-04-spf13-vim-3.0-release-and-new-website"},
+ {"/blog-:year-:month-:title", true, "/blog-2012-04-spf13-vim-3.0-release-and-new-website"},
+ //{"/blog/:fred", false, ""},
+ //{"/:year//:title", false, ""},
+ //{
+ //"/:section/:year/:month/:day/:weekdayname/:yearday/:title",
+ //true,
+ //"/blue/2012/04/06/Friday/97/spf13-vim-3.0-release-and-new-website",
+ //},
+ //{
+ //"/:weekday/:weekdayname/:month/:monthname",
+ //true,
+ //"/5/Friday/04/April",
+ //},
+ //{
+ //"/:slug/:title",
+ //true,
+ //"/spf13-vim-3-0-release-and-new-website/spf13-vim-3.0-release-and-new-website",
+ //},
}
func TestPermalinkValidation(t *testing.T) {
@@ -65,7 +75,7 @@ func TestPermalinkExpansion(t *testing.T) {
page, err := s.NewPageFrom(strings.NewReader(simplePageJSON), "blue/test-page.md")
if err != nil {
- t.Fatalf("failed before we began, could not parse simplePageJSON: %s", err)
+ t.Fatalf("failed before we began, could not parse SIMPLE_PAGE_JSON: %s", err)
}
for _, item := range testdataPermalinks {
if !item.valid {