]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Use the page path and not the backing filename as the last resort in the default...
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 26 Feb 2025 11:16:58 +0000 (12:16 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 26 Feb 2025 12:06:26 +0000 (13:06 +0100)
This should:

1. Fix some (rare) tiebreaker issues when sorting pages from multiple content adapters.
2. Improve the sorting for pages without a backing file.

common/paths/pathparser_test.go
hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
resources/page/pages_sort.go

index e8fee96e15287491f72cab3e0af2e1139381ad83..584b1a78aac3f0386717fe5f7537afdae001da51 100644 (file)
@@ -165,6 +165,7 @@ func TestParse(t *testing.T) {
                                c.Assert(p.Identifiers(), qt.DeepEquals, []string{"txt", "no"})
                                c.Assert(p.Base(), qt.Equals, "/a/b.a.b.txt")
                                c.Assert(p.BaseNoLeadingSlash(), qt.Equals, "a/b.a.b.txt")
+                               c.Assert(p.Path(), qt.Equals, "/a/b.a.b.no.txt")
                                c.Assert(p.PathNoLang(), qt.Equals, "/a/b.a.b.txt")
                                c.Assert(p.Ext(), qt.Equals, "txt")
                                c.Assert(p.PathNoIdentifier(), qt.Equals, "/a/b.a.b")
@@ -220,6 +221,7 @@ func TestParse(t *testing.T) {
                                c.Assert(p.NameNoExt(), qt.Equals, "index.no")
                                c.Assert(p.NameNoIdentifier(), qt.Equals, "index")
                                c.Assert(p.NameNoLang(), qt.Equals, "index.md")
+                               c.Assert(p.Path(), qt.Equals, "/a/b/index.no.md")
                                c.Assert(p.PathNoLang(), qt.Equals, "/a/b/index.md")
                                c.Assert(p.Section(), qt.Equals, "a")
                        },
index b674ef0b6cd81e0f1531a476d194c9f0cf6b6212..c00a95bc1fdfe26111b9a5ff093f710588a49aea 100644 (file)
@@ -382,6 +382,28 @@ Single: {{ .Title }}|{{ .Content }}|
        }
 }
 
+func TestPagesFromGoTmplDefaultPageSort(t *testing.T) {
+       t.Parallel()
+       files := `
+-- hugo.toml --
+defaultContentLanguage = "en"
+-- layouts/index.html --
+{{ range site.RegularPages }}{{ .RelPermalink }}|{{ end}}
+-- content/_content.gotmpl --
+{{ $.AddPage  (dict "kind" "page" "path" "docs/_p22" "title" "A" ) }}
+{{ $.AddPage  (dict "kind" "page" "path" "docs/p12" "title" "A" ) }}
+{{ $.AddPage  (dict "kind" "page" "path" "docs/_p12" "title" "A" ) }}
+-- content/docs/_content.gotmpl --
+{{ $.AddPage  (dict "kind" "page" "path" "_p21" "title" "A" ) }}
+{{ $.AddPage  (dict "kind" "page" "path" "p11" "title" "A" ) }}
+{{ $.AddPage  (dict "kind" "page" "path" "_p11" "title" "A" ) }}
+`
+
+       b := hugolib.Test(t, files)
+
+       b.AssertFileContent("public/index.html", "/docs/_p11/|/docs/_p12/|/docs/_p21/|/docs/_p22/|/docs/p11/|/docs/p12/|")
+}
+
 func TestPagesFromGoTmplEnableAllLanguages(t *testing.T) {
        t.Parallel()
 
index 3f487570246729f14cebeee8b5a9fa35adeb2796..e77bb7e7c4080233739401303d55ebd60ea8d5c2 100644 (file)
@@ -90,14 +90,14 @@ var (
                if w01 != w02 && w01 != -1 && w02 != -1 {
                        return w01 < w02
                }
+
                if p1.Weight() == p2.Weight() {
                        if p1.Date().Unix() == p2.Date().Unix() {
                                c := collatorStringCompare(func(p Page) string { return p.LinkTitle() }, p1, p2)
                                if c == 0 {
-                                       if p1.File() == nil || p2.File() == nil {
-                                               return p1.File() == nil
-                                       }
-                                       return compare.LessStrings(p1.File().Filename(), p2.File().Filename())
+                                       // This is the full normalized path, which will contain extension and any language code preserved,
+                                       // which is what we want for sorting.
+                                       return compare.LessStrings(p1.PathInfo().Path(), p2.PathInfo().Path())
                                }
                                return c < 0
                        }