mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Make string sorting (e.g. ByTitle, ByLinkTitle and ByParam) language aware
Fixes #2180
This commit is contained in:
@@ -70,3 +70,69 @@ date: "2020-02-01"
|
||||
b.AssertFileContent("public/en/index.html", "0|February, 2020|Pages(1)1|January, 2020|Pages(1)")
|
||||
b.AssertFileContent("public/fr/index.html", "0|février, 2020|Pages(1)1|janvier, 2020|Pages(1)")
|
||||
}
|
||||
|
||||
func TestPagesSortCollation(t *testing.T) {
|
||||
|
||||
files := `
|
||||
-- config.toml --
|
||||
defaultContentLanguage = 'en'
|
||||
defaultContentLanguageInSubdir = true
|
||||
[languages]
|
||||
[languages.en]
|
||||
title = 'My blog'
|
||||
weight = 1
|
||||
[languages.fr]
|
||||
title = 'Mon blogue'
|
||||
weight = 2
|
||||
[languages.nn]
|
||||
title = 'Bloggen min'
|
||||
weight = 3
|
||||
-- content/p1.md --
|
||||
---
|
||||
title: "zulu"
|
||||
date: "2020-01-01"
|
||||
param1: "xylophone"
|
||||
tags: ["xylophone", "éclair", "zulu", "emma"]
|
||||
---
|
||||
-- content/p2.md --
|
||||
---
|
||||
title: "émotion"
|
||||
date: "2020-01-01"
|
||||
param1: "violin"
|
||||
---
|
||||
-- content/p3.md --
|
||||
---
|
||||
title: "alpha"
|
||||
date: "2020-01-01"
|
||||
param1: "éclair"
|
||||
---
|
||||
-- layouts/index.html --
|
||||
ByTitle: {{ range site.RegularPages.ByTitle }}{{ .Title }}|{{ end }}
|
||||
ByLinkTitle: {{ range site.RegularPages.ByLinkTitle }}{{ .Title }}|{{ end }}
|
||||
ByParam: {{ range site.RegularPages.ByParam "param1" }}{{ .Params.param1 }}|{{ end }}
|
||||
Tags Alphabetical: {{ range site.Taxonomies.tags.Alphabetical }}{{ .Term }}|{{ end }}
|
||||
GroupBy: {{ range site.RegularPages.GroupBy "Title" }}{{ .Key }}|{{ end }}
|
||||
{{ with (site.GetPage "p1").Params.tags }}
|
||||
Sort: {{ sort . }}
|
||||
ByWeight: {{ range site.RegularPages.ByWeight }}{{ .Title }}|{{ end }}
|
||||
{{ end }}
|
||||
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: true,
|
||||
}).Build()
|
||||
|
||||
b.AssertFileContent("public/en/index.html", `
|
||||
ByTitle: alpha|émotion|zulu|
|
||||
ByLinkTitle: alpha|émotion|zulu|
|
||||
ByParam: éclair|violin|xylophone
|
||||
Tags Alphabetical: éclair|emma|xylophone|zulu|
|
||||
GroupBy: alpha|émotion|zulu|
|
||||
Sort: [éclair emma xylophone zulu]
|
||||
ByWeight: alpha|émotion|zulu|
|
||||
`)
|
||||
}
|
||||
|
Reference in New Issue
Block a user