mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-22 21:42:50 +02:00
output: Fix permalink in sitemap etc. when multiple permalinkable output formats
In Hugo 0.55.0 we made AMP `permalinkable`. We also render the output formats in their natural sort order, meaning `AMP` will be rendered before `HTML`. References in the sitemap would then point to the AMP version, and this is normally not what you'd want. This commit fixes that by making `HTML` by default sort before the others. If this is not you want, you can set `weight` on the output format configuration. Fixes #5910
This commit is contained in:
@@ -15,6 +15,7 @@ package output
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/gohugoio/hugo/media"
|
||||
@@ -225,3 +226,25 @@ func TestDecodeFormats(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSort(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
assert.Equal("HTML", DefaultFormats[0].Name)
|
||||
assert.Equal("AMP", DefaultFormats[1].Name)
|
||||
|
||||
json := JSONFormat
|
||||
json.Weight = 1
|
||||
|
||||
formats := Formats{
|
||||
AMPFormat,
|
||||
HTMLFormat,
|
||||
json,
|
||||
}
|
||||
|
||||
sort.Sort(formats)
|
||||
|
||||
assert.Equal("JSON", formats[0].Name)
|
||||
assert.Equal("HTML", formats[1].Name)
|
||||
assert.Equal("AMP", formats[2].Name)
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user