summaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorMai-Lapyst <67418776+Mai-Lapyst@users.noreply.github.com>2023-06-26 15:31:01 +0200
committerGitHub <noreply@github.com>2023-06-26 15:31:01 +0200
commitcc14c6a52c215fc43716f7b266c4c340b3d28230 (patch)
tree0d371fe0f9421d52a42e203ade99127c2d11806d /config
parente3308a0bbc2de1cb4d7571521abeab07049ce31f (diff)
resources/page: Allow section and taxonomy pages to have a permalink configuration
Allows using permalink configuration for sections (branch bundles) and also for taxonomy pages. Extends the current permalink configuration to be able to specified per page kind while also staying backward compatible: all permalink patterns not dedicated to a certain kind, get automatically added for both normal pages and term pages. Fixes #8523
Diffstat (limited to 'config')
-rw-r--r--config/allconfig/allconfig.go2
-rw-r--r--config/allconfig/alldecoders.go43
2 files changed, 43 insertions, 2 deletions
diff --git a/config/allconfig/allconfig.go b/config/allconfig/allconfig.go
index 9079e2ce3..2dc409be7 100644
--- a/config/allconfig/allconfig.go
+++ b/config/allconfig/allconfig.go
@@ -150,7 +150,7 @@ type Config struct {
Minify minifiers.MinifyConfig `mapstructure:"-"`
// Permalink configuration.
- Permalinks map[string]string `mapstructure:"-"`
+ Permalinks map[string]map[string]string `mapstructure:"-"`
// Taxonomy configuration.
Taxonomies map[string]string `mapstructure:"-"`
diff --git a/config/allconfig/alldecoders.go b/config/allconfig/alldecoders.go
index 1c8573f3d..4d9ef4f85 100644
--- a/config/allconfig/alldecoders.go
+++ b/config/allconfig/alldecoders.go
@@ -206,7 +206,48 @@ var allDecoderSetups = map[string]decodeWeight{
"permalinks": {
key: "permalinks",
decode: func(d decodeWeight, p decodeConfig) error {
- p.c.Permalinks = maps.CleanConfigStringMapString(p.p.GetStringMapString(d.key))
+ p.c.Permalinks = make(map[string]map[string]string)
+
+ p.c.Permalinks["page"] = make(map[string]string)
+ p.c.Permalinks["section"] = make(map[string]string)
+ p.c.Permalinks["taxonomy"] = make(map[string]string)
+ p.c.Permalinks["term"] = make(map[string]string)
+
+ config := maps.CleanConfigStringMap(p.p.GetStringMap(d.key))
+ for k, v := range config {
+ switch v := v.(type) {
+ case string:
+ // [permalinks]
+ // key = '...'
+
+ // To sucessfully be backward compatible, "default" patterns need to be set for both page and term
+ p.c.Permalinks["page"][k] = v;
+ p.c.Permalinks["term"][k] = v;
+
+ case maps.Params:
+ // [permalinks.key]
+ // xyz = ???
+
+ if (k == "page") || (k == "section") || (k == "taxonomy") || (k == "term") {
+ // TODO: warn if we overwrite an already set value
+ for k2, v2 := range v {
+ switch v2 := v2.(type) {
+ case string:
+ p.c.Permalinks[k][k2] = v2
+
+ default:
+ return fmt.Errorf("permalinks configuration invalid: unknown value %q for key %q for kind %q", v2, k2, k)
+ }
+ }
+ } else {
+ return fmt.Errorf("permalinks configuration only allows per-kind configuration 'page', 'section', 'taxonomy' and 'term'; unknown kind: %q", k)
+ }
+
+ default:
+ return fmt.Errorf("permalinks configuration invalid: unknown value %q for key %q", v, k)
+ }
+ }
+
return nil
},
},