mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-31 22:41:53 +02:00
hugolib: Refactor/-work the permalink/target path logic
This is a pretty fundamental change in Hugo, but absolutely needed if we should have any hope of getting "multiple outputs" done. This commit's goal is to say: * Every file target path is created by `createTargetPath`, i.e. one function for all. * That function takes every page and site parameter into account, to avoid fragile string parsing to uglify etc. later on. * The path creation logic has full test coverage. * All permalinks, paginator URLs etc. are then built on top of that same logic. Fixes #1252 Fixes #2110 Closes #2374 Fixes #1885 Fixes #3102 Fixes #3179 Fixes #1641 Fixes #1989
This commit is contained in:
@@ -27,6 +27,7 @@ var (
|
||||
Name: "AMP",
|
||||
MediaType: media.HTMLType,
|
||||
BaseName: "index",
|
||||
Path: "amp",
|
||||
}
|
||||
|
||||
CSSType = Type{
|
||||
@@ -43,7 +44,7 @@ var (
|
||||
|
||||
JSONType = Type{
|
||||
Name: "JSON",
|
||||
MediaType: media.HTMLType,
|
||||
MediaType: media.JSONType,
|
||||
BaseName: "index",
|
||||
IsPlainText: true,
|
||||
}
|
||||
@@ -52,6 +53,7 @@ var (
|
||||
Name: "RSS",
|
||||
MediaType: media.RSSType,
|
||||
BaseName: "index",
|
||||
NoUgly: true,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -112,3 +114,7 @@ func GetTypes(keys ...string) (Types, error) {
|
||||
|
||||
return types, nil
|
||||
}
|
||||
|
||||
func (t Type) BaseFilename() string {
|
||||
return t.BaseName + "." + t.MediaType.Suffix
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ func TestDefaultTypes(t *testing.T) {
|
||||
require.Equal(t, media.RSSType, RSSType.MediaType)
|
||||
require.Empty(t, RSSType.Path)
|
||||
require.False(t, RSSType.IsPlainText)
|
||||
require.True(t, RSSType.NoUgly)
|
||||
}
|
||||
|
||||
func TestGetType(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user