diff options
author | Bjørn Erik Pedersen <[email protected]> | 2020-03-20 16:34:53 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2020-03-20 20:35:57 +0100 |
commit | 7204b354a9f46778f068a4712447d6d4fefbefd8 (patch) | |
tree | a7d58d64fb9266f5c3f28251cb677b245925e728 /docshelper/docs.go | |
parent | 574c2959b8d3338764fa1db102a5e0fd6ed322d9 (diff) | |
download | hugo-7204b354a9f46778f068a4712447d6d4fefbefd8.tar.gz hugo-7204b354a9f46778f068a4712447d6d4fefbefd8.zip |
Some minify configuration adjustments
Diffstat (limited to 'docshelper/docs.go')
-rw-r--r-- | docshelper/docs.go | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/docshelper/docs.go b/docshelper/docs.go index 17e0ccd91..999e14d7d 100644 --- a/docshelper/docs.go +++ b/docshelper/docs.go @@ -15,37 +15,37 @@ // is of limited interest for the general Hugo user. package docshelper -import ( - "encoding/json" +type ( + DocProviderFunc = func() DocProvider + DocProvider map[string]map[string]interface{} ) -// DocProviders contains all DocProviders added to the system. -var DocProviders = make(map[string]DocProvider) +var docProviderFuncs []DocProviderFunc -// AddDocProvider adds or updates the DocProvider for a given name. -func AddDocProvider(name string, provider DocProvider) { - if prev, ok := DocProviders[name]; !ok { - DocProviders[name] = provider - } else { - DocProviders[name] = merge(prev, provider) - } +func AddDocProviderFunc(fn DocProviderFunc) { + docProviderFuncs = append(docProviderFuncs, fn) } -// DocProvider is used to save arbitrary JSON data -// used for the generation of the documentation. -type DocProvider func() map[string]interface{} +func GetDocProvider() DocProvider { + provider := make(DocProvider) + + for _, fn := range docProviderFuncs { + p := fn() + for k, v := range p { + if prev, found := provider[k]; !found { + provider[k] = v + } else { + merge(prev, v) + } + } + } -// MarshalJSON returns a JSON representation of the DocProvider. -func (d DocProvider) MarshalJSON() ([]byte, error) { - return json.MarshalIndent(d(), "", " ") + return provider } -func merge(a, b DocProvider) DocProvider { - next := a() - for k, v := range b() { - next[k] = v - } - return func() map[string]interface{} { - return next +// Shallow merge +func merge(dst, src map[string]interface{}) { + for k, v := range src { + dst[k] = v } } |