aboutsummaryrefslogtreecommitdiffhomepage
path: root/common
diff options
context:
space:
mode:
authorn1xx1 <[email protected]>2024-08-01 12:14:29 +0200
committerGitHub <[email protected]>2024-08-01 12:14:29 +0200
commit566fe7ba12e7ecabadffa9ec76b319d04063c78b (patch)
tree227ffdfe6d1cb203f87f2930b9d892adb243805c /common
parent92573012e83bf8d71a247027d2f7f7f43a9c42b7 (diff)
downloadhugo-566fe7ba12e7ecabadffa9ec76b319d04063c78b.tar.gz
hugo-566fe7ba12e7ecabadffa9ec76b319d04063c78b.zip
resources/page: Expand parmalinks tokens in `url`
This change allows to use permalink tokens in url front matter fields. This should be useful to target more specific pages instead of using a global permalink configuration. It's expected to be used with cascade. Fixes #9714
Diffstat (limited to 'common')
-rw-r--r--common/hreflect/helpers.go5
-rw-r--r--common/maps/cache.go13
2 files changed, 11 insertions, 7 deletions
diff --git a/common/hreflect/helpers.go b/common/hreflect/helpers.go
index b5a8bacc9..5113a3886 100644
--- a/common/hreflect/helpers.go
+++ b/common/hreflect/helpers.go
@@ -268,7 +268,8 @@ func IsContextType(tp reflect.Type) bool {
return true
}
- return isContextCache.GetOrCreate(tp, func() bool {
- return tp.Implements(contextInterface)
+ isContext, _ := isContextCache.GetOrCreate(tp, func() (bool, error) {
+ return tp.Implements(contextInterface), nil
})
+ return isContext
}
diff --git a/common/maps/cache.go b/common/maps/cache.go
index 7cd7410c2..0175974b5 100644
--- a/common/maps/cache.go
+++ b/common/maps/cache.go
@@ -40,22 +40,25 @@ func (c *Cache[K, T]) Get(key K) (T, bool) {
}
// GetOrCreate gets the value for the given key if it exists, or creates it if not.
-func (c *Cache[K, T]) GetOrCreate(key K, create func() T) T {
+func (c *Cache[K, T]) GetOrCreate(key K, create func() (T, error)) (T, error) {
c.RLock()
v, found := c.m[key]
c.RUnlock()
if found {
- return v
+ return v, nil
}
c.Lock()
defer c.Unlock()
v, found = c.m[key]
if found {
- return v
+ return v, nil
+ }
+ v, err := create()
+ if err != nil {
+ return v, err
}
- v = create()
c.m[key] = v
- return v
+ return v, nil
}
// Set sets the given key to the given value.