]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
common/hcontext: Replace with external package
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 21 Aug 2025 19:58:43 +0000 (21:58 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 22 Aug 2025 07:13:46 +0000 (09:13 +0200)
common/hcontext/context.go [deleted file]
common/hugo/hugo.go
go.mod
go.sum
hugolib/page__content.go
resources/resource_factories/create/create.go
tpl/template.go

diff --git a/common/hcontext/context.go b/common/hcontext/context.go
deleted file mode 100644 (file)
index 9524ef2..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2024 The Hugo Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package hcontext
-
-import "context"
-
-// ContextDispatcher is a generic interface for setting and getting values from a context.
-type ContextDispatcher[T any] interface {
-       Set(ctx context.Context, value T) context.Context
-       Get(ctx context.Context) T
-}
-
-// NewContextDispatcher creates a new ContextDispatcher with the given key.
-func NewContextDispatcher[T any, R comparable](key R) ContextDispatcher[T] {
-       return keyInContext[T, R]{
-               id: key,
-       }
-}
-
-type keyInContext[T any, R comparable] struct {
-       zero T
-       id   R
-}
-
-func (f keyInContext[T, R]) Get(ctx context.Context) T {
-       v := ctx.Value(f.id)
-       if v == nil {
-               return f.zero
-       }
-       return v.(T)
-}
-
-func (f keyInContext[T, R]) Set(ctx context.Context, value T) context.Context {
-       return context.WithValue(ctx, f.id, value)
-}
index 764a86a9759b7d9e42bc8d45736df7cff6463864..38f78bc35195ee3d85b98a4ae4a7047923b49a5d 100644 (file)
@@ -28,12 +28,13 @@ import (
        "github.com/bep/logg"
 
        "github.com/bep/godartsass/v2"
-       "github.com/gohugoio/hugo/common/hcontext"
+
        "github.com/gohugoio/hugo/common/hexec"
        "github.com/gohugoio/hugo/common/loggers"
        "github.com/gohugoio/hugo/common/maps"
        "github.com/gohugoio/hugo/hugofs/files"
 
+       "github.com/bep/helpers/contexthelpers"
        "github.com/spf13/afero"
 
        iofs "io/fs"
@@ -145,7 +146,7 @@ const (
        contextKeyMarkupScope contextKey = iota
 )
 
-var markupScope = hcontext.NewContextDispatcher[string](contextKeyMarkupScope)
+var markupScope = contexthelpers.NewContextDispatcher[string](contextKeyMarkupScope)
 
 type Context struct{}
 
diff --git a/go.mod b/go.mod
index 449c40ec40463bdd1c0299630c095b58487adebe..f133774fa223faa4f663147aad43003a76a711e6 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -14,7 +14,7 @@ require (
        github.com/bep/golibsass v1.2.0
        github.com/bep/goportabletext v0.1.0
        github.com/bep/gowebp v0.3.0
-       github.com/bep/helpers v0.5.0
+       github.com/bep/helpers v0.6.0
        github.com/bep/imagemeta v0.12.0
        github.com/bep/lazycache v0.8.0
        github.com/bep/logg v0.4.0
diff --git a/go.sum b/go.sum
index 21c3d554af9af610e156bcee2a34d5b53fc1bf61..b98375fc1d6f0ceb1fe82b91ff74858aaceb0fd5 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -157,6 +157,8 @@ github.com/bep/gowebp v0.3.0 h1:MhmMrcf88pUY7/PsEhMgEP0T6fDUnRTMpN8OclDrbrY=
 github.com/bep/gowebp v0.3.0/go.mod h1:ZhFodwdiFp8ehGJpF4LdPl6unxZm9lLFjxD3z2h2AgI=
 github.com/bep/helpers v0.5.0 h1:rneezhnG7GzLFlsEWO/EnleaBRuluBDGFimalO6Y50o=
 github.com/bep/helpers v0.5.0/go.mod h1:dSqCzIvHbzsk5YOesp1M7sKAq5xUcvANsRoKdawxH4Q=
+github.com/bep/helpers v0.6.0 h1:qtqMCK8XPFNM9hp5Ztu9piPjxNNkk8PIyUVjg6v8Bsw=
+github.com/bep/helpers v0.6.0/go.mod h1:IOZlgx5PM/R/2wgyCatfsgg5qQ6rNZJNDpWGXqDR044=
 github.com/bep/imagemeta v0.12.0 h1:ARf+igs5B7pf079LrqRnwzQ/wEB8Q9v4NSDRZO1/F5k=
 github.com/bep/imagemeta v0.12.0/go.mod h1:23AF6O+4fUi9avjiydpKLStUNtJr5hJB4rarG18JpN8=
 github.com/bep/lazycache v0.8.0 h1:lE5frnRjxaOFbkPZ1YL6nijzOPPz6zeXasJq8WpG4L8=
index 20abb788418b38ef3d03aa87c9ba3eeedcaf2549..4b78a1ed003b12cf0eb792fa1cb13561170d95f0 100644 (file)
@@ -26,8 +26,9 @@ import (
 
        maps0 "maps"
 
+       "github.com/bep/helpers/contexthelpers"
        "github.com/bep/logg"
-       "github.com/gohugoio/hugo/common/hcontext"
+
        "github.com/gohugoio/hugo/common/herrors"
        "github.com/gohugoio/hugo/common/hugio"
        "github.com/gohugoio/hugo/common/hugo"
@@ -673,7 +674,7 @@ const (
        contextKeyContentCallback contextKey = iota
 )
 
-var setGetContentCallbackInContext = hcontext.NewContextDispatcher[func(*pageContentOutput, contentTableOfContents)](contextKeyContentCallback)
+var setGetContentCallbackInContext = contexthelpers.NewContextDispatcher[func(*pageContentOutput, contentTableOfContents)](contextKeyContentCallback)
 
 func (c *cachedContentScope) contentToC(ctx context.Context) (contentTableOfContents, error) {
        cp := c.pco
index 2aecb5a93266e4319b0caeee9a027d0b52aaf795..14b17a10552de22cf6a9a1f786630cda08b40150 100644 (file)
@@ -23,6 +23,8 @@ import (
        "strings"
        "time"
 
+       "github.com/bep/helpers/contexthelpers"
+
        "github.com/bep/logg"
        "github.com/gohugoio/httpcache"
        hhttpcache "github.com/gohugoio/hugo/cache/httpcache"
@@ -34,7 +36,7 @@ import (
        "github.com/gohugoio/hugo/cache/dynacache"
        "github.com/gohugoio/hugo/cache/filecache"
        "github.com/gohugoio/hugo/common/hashing"
-       "github.com/gohugoio/hugo/common/hcontext"
+
        "github.com/gohugoio/hugo/common/hugio"
        "github.com/gohugoio/hugo/common/tasks"
        "github.com/gohugoio/hugo/resources"
@@ -48,7 +50,7 @@ type Client struct {
        httpClient           *http.Client
        httpCacheConfig      hhttpcache.ConfigCompiled
        cacheGetResource     *filecache.Cache
-       resourceIDDispatcher hcontext.ContextDispatcher[string]
+       resourceIDDispatcher contexthelpers.ContextDispatcher[string]
 
        // Set when watching.
        remoteResourceChecker *tasks.RunEvery
@@ -64,7 +66,7 @@ const (
 // New creates a new Client with the given specification.
 func New(rs *resources.Spec) *Client {
        fileCache := rs.FileCaches.GetResourceCache()
-       resourceIDDispatcher := hcontext.NewContextDispatcher[string](contextKeyResourceID)
+       resourceIDDispatcher := contexthelpers.NewContextDispatcher[string](contextKeyResourceID)
        httpCacheConfig := rs.Cfg.GetConfigSection("httpCacheCompiled").(hhttpcache.ConfigCompiled)
        var remoteResourceChecker *tasks.RunEvery
        if rs.Cfg.Watching() && !httpCacheConfig.IsPollingDisabled() {
index fde8b4bcc8524957687d25a58e7640f7ad295199..bf76e99f587d52b2bf435ad5383bc65e1498014e 100644 (file)
@@ -21,8 +21,9 @@ import (
        "sync"
        "unicode"
 
+       "github.com/bep/helpers/contexthelpers"
        bp "github.com/gohugoio/hugo/bufferpool"
-       "github.com/gohugoio/hugo/common/hcontext"
+
        "github.com/gohugoio/hugo/identity"
        "github.com/gohugoio/hugo/langs"
 
@@ -56,18 +57,18 @@ const (
 
 // Context manages values passed in the context to templates.
 var Context = struct {
-       DependencyManagerScopedProvider    hcontext.ContextDispatcher[identity.DependencyManagerScopedProvider]
+       DependencyManagerScopedProvider    contexthelpers.ContextDispatcher[identity.DependencyManagerScopedProvider]
        GetDependencyManagerInCurrentScope func(context.Context) identity.Manager
-       DependencyScope                    hcontext.ContextDispatcher[int]
-       Page                               hcontext.ContextDispatcher[page]
-       IsInGoldmark                       hcontext.ContextDispatcher[bool]
-       CurrentTemplate                    hcontext.ContextDispatcher[*CurrentTemplateInfo]
+       DependencyScope                    contexthelpers.ContextDispatcher[int]
+       Page                               contexthelpers.ContextDispatcher[page]
+       IsInGoldmark                       contexthelpers.ContextDispatcher[bool]
+       CurrentTemplate                    contexthelpers.ContextDispatcher[*CurrentTemplateInfo]
 }{
-       DependencyManagerScopedProvider: hcontext.NewContextDispatcher[identity.DependencyManagerScopedProvider](contextKeyDependencyManagerScopedProvider),
-       DependencyScope:                 hcontext.NewContextDispatcher[int](contextKeyDependencyScope),
-       Page:                            hcontext.NewContextDispatcher[page](contextKeyPage),
-       IsInGoldmark:                    hcontext.NewContextDispatcher[bool](contextKeyIsInGoldmark),
-       CurrentTemplate:                 hcontext.NewContextDispatcher[*CurrentTemplateInfo](cntextKeyCurrentTemplateInfo),
+       DependencyManagerScopedProvider: contexthelpers.NewContextDispatcher[identity.DependencyManagerScopedProvider](contextKeyDependencyManagerScopedProvider),
+       DependencyScope:                 contexthelpers.NewContextDispatcher[int](contextKeyDependencyScope),
+       Page:                            contexthelpers.NewContextDispatcher[page](contextKeyPage),
+       IsInGoldmark:                    contexthelpers.NewContextDispatcher[bool](contextKeyIsInGoldmark),
+       CurrentTemplate:                 contexthelpers.NewContextDispatcher[*CurrentTemplateInfo](cntextKeyCurrentTemplateInfo),
 }
 
 func init() {