From 4bae8b04aadd72d298bf2dd1bb1430806bf2869c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 29 Dec 2018 10:14:37 +0100 Subject: Revert " Fix handling of taxonomy terms containing slashes" See #4090 See #5571 This reverts commit fff132537b4094221f4f099e2251f3cda613060f. --- hugolib/hugo_sites.go | 2 +- hugolib/page_paths.go | 8 +------- hugolib/page_paths_test.go | 7 ------- hugolib/page_taxonomy_test.go | 10 ++++------ hugolib/permalinks.go | 30 +++++++----------------------- hugolib/taxonomy_test.go | 43 +++++++++++++++++++++++++++++++++++++------ 6 files changed, 50 insertions(+), 50 deletions(-) (limited to 'hugolib') diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go index e44390e4b..6a4893473 100644 --- a/hugolib/hugo_sites.go +++ b/hugolib/hugo_sites.go @@ -567,7 +567,7 @@ func (h *HugoSites) createMissingPages() error { origKey := key if s.Info.preserveTaxonomyNames { - key = s.PathSpec.MakeSegment(key) + key = s.PathSpec.MakePathSanitized(key) } for _, p := range taxonomyPages { // Some people may have /authors/MaxMustermann etc. as paths. diff --git a/hugolib/page_paths.go b/hugolib/page_paths.go index a24789bf9..9de7b0764 100644 --- a/hugolib/page_paths.go +++ b/hugolib/page_paths.go @@ -197,13 +197,7 @@ func createTargetPath(d targetPathDescriptor) string { if d.ExpandedPermalink != "" { pagePath = filepath.Join(pagePath, d.ExpandedPermalink) } else { - pagePath = "" - for i, section := range d.Sections { - if i > 0 { - pagePath += helpers.FilePathSeparator - } - pagePath += d.PathSpec.MakeSegment(section) - } + pagePath = filepath.Join(d.Sections...) } needsBase = false } diff --git a/hugolib/page_paths_test.go b/hugolib/page_paths_test.go index 9e8d4ecb7..8f8df6ec1 100644 --- a/hugolib/page_paths_test.go +++ b/hugolib/page_paths_test.go @@ -151,13 +151,6 @@ func TestPageTargetPath(t *testing.T) { BaseName: "mypage", Addends: "c/d/e", Type: output.HTMLFormat}, "/a/b/mypage/c/d/e/index.html"}, - { - "Unclean Taxonomy Term", targetPathDescriptor{ - Kind: KindTaxonomy, - BaseName: "_index", - Sections: []string{"tags", "x/y"}, - Type: output.HTMLFormat, - Addends: "page/3"}, "/tags/x-y/page/3/index.html"}, } for i, test := range tests { diff --git a/hugolib/page_taxonomy_test.go b/hugolib/page_taxonomy_test.go index df6e0e857..ed1d2565d 100644 --- a/hugolib/page_taxonomy_test.go +++ b/hugolib/page_taxonomy_test.go @@ -20,7 +20,7 @@ import ( ) var pageYamlWithTaxonomiesA = `--- -tags: ['a', 'B', 'c', 'x/y'] +tags: ['a', 'B', 'c'] categories: 'd' --- YAML frontmatter with tags and categories taxonomy.` @@ -30,7 +30,6 @@ tags: - "a" - "B" - "c" - - "x/y" categories: 'd' --- YAML frontmatter with tags and categories taxonomy.` @@ -46,14 +45,13 @@ var pageJSONWithTaxonomies = `{ "tags": [ "a", "b", - "c", - "x/y" + "c" ] } JSON Front Matter with tags and categories` var pageTomlWithTaxonomies = `+++ -tags = [ "a", "B", "c", "x/y" ] +tags = [ "a", "B", "c" ] categories = "d" +++ TOML Front Matter with tags and categories` @@ -77,7 +75,7 @@ func TestParseTaxonomies(t *testing.T) { param := p.getParamToLower("tags") if params, ok := param.([]string); ok { - expected := []string{"a", "b", "c", "x/y"} + expected := []string{"a", "b", "c"} if !reflect.DeepEqual(params, expected) { t.Errorf("Expected %s: got: %s", expected, params) } diff --git a/hugolib/permalinks.go b/hugolib/permalinks.go index f306f494d..55dcd7db6 100644 --- a/hugolib/permalinks.go +++ b/hugolib/permalinks.go @@ -152,13 +152,9 @@ func pageToPermalinkDate(p *Page, dateField string) (string, error) { // pageToPermalinkTitle returns the URL-safe form of the title func pageToPermalinkTitle(p *Page, _ string) (string, error) { - if p.Kind == KindTaxonomy { - // Taxonomies are allowed to have '/' characters, so don't normalize - // them with MakeSegment. - return p.s.PathSpec.MakePathSanitized(p.title), nil - } - - return p.s.PathSpec.MakeSegment(p.title), nil + // Page contains Node which has Title + // (also contains URLPath which has Slug, sometimes) + return p.s.PathSpec.URLize(p.title), nil } // pageToPermalinkFilename returns the URL-safe form of the filename @@ -170,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 @@ -185,30 +181,18 @@ 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.s.PathSpec.URLize(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/taxonomy_test.go b/hugolib/taxonomy_test.go index ec55dc428..6ea397173 100644 --- a/hugolib/taxonomy_test.go +++ b/hugolib/taxonomy_test.go @@ -45,9 +45,8 @@ func TestByCountOrderOfTaxonomies(t *testing.T) { st = append(st, t.Name) } - expect := []string{"a", "b", "c", "x/y"} - if !reflect.DeepEqual(st, expect) { - t.Fatalf("ordered taxonomies do not match %v. Got: %s", expect, st) + if !reflect.DeepEqual(st, []string{"a", "b", "c"}) { + t.Fatalf("ordered taxonomies do not match [a, b, c]. Got: %s", st) } } @@ -69,10 +68,8 @@ func doTestTaxonomiesWithAndWithoutContentFile(t *testing.T, preserveTaxonomyNam baseURL = "http://example.com/blog" preserveTaxonomyNames = %t uglyURLs = %t - paginate = 1 defaultContentLanguage = "en" - [Taxonomies] tag = "tags" category = "categories" @@ -80,7 +77,6 @@ other = "others" empty = "empties" permalinked = "permalinkeds" subcats = "subcats" - [permalinks] permalinkeds = "/perma/:slug/" subcats = "/subcats/:slug/" @@ -243,3 +239,38 @@ subcats: th.assertFileContent(pathFunc("public/empties/index.html"), "Terms List", "Empties") } + +// https://github.com/gohugoio/hugo/issues/5513 +func TestTaxonomyPathSeparation(t *testing.T) { + t.Parallel() + + config := ` +baseURL = "https://example.com" +[taxonomies] +"news/tag" = "news/tags" +"news/category" = "news/categories" +` + + pageContent := ` ++++ +title = "foo" +"news/categories" = ["a", "b", "c"] ++++ +Content. +` + + b := newTestSitesBuilder(t) + b.WithConfigFile("toml", config) + b.WithContent("page.md", pageContent) + b.WithContent("news/categories/b/_index.md", ` +--- +title: "This is B" +--- +`) + + b.CreateSites().Build(BuildCfg{}) + + b.AssertFileContent("public/news/categories/index.html", "Taxonomy Term Page 1|News/Categories|Hello|https://example.com/news/categories/|") + b.AssertFileContent("public/news/categories/a/index.html", "Taxonomy List Page 1|A|Hello|https://example.com/news/categories/a/|") + b.AssertFileContent("public/news/categories/b/index.html", "Taxonomy List Page 1|This is B|Hello|https://example.com/news/categories/b/|") +} -- cgit v1.2.3