-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.go
61 lines (50 loc) · 1.23 KB
/
module.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package valueobject
import (
"github.com/gohugonet/hugoverse/internal/domain/config"
"github.com/mitchellh/mapstructure"
"path/filepath"
)
type ModuleConfig struct {
// File system mounts.
Mounts []Mount
// Module imports.
Imports []Import
}
// DecodeModuleConfig creates a modules Config from a given Hugo configuration.
func DecodeModuleConfig(cfg config.Provider) (ModuleConfig, error) {
return decodeConfig(cfg)
}
func decodeConfig(cfg config.Provider) (ModuleConfig, error) {
c := DefaultModuleConfig
if cfg == nil {
return c, nil
}
moduleSet := cfg.IsSet("module")
if moduleSet {
m := cfg.GetStringMap("module")
if err := mapstructure.WeakDecode(m, &c); err != nil {
return c, err
}
for i, mnt := range c.Mounts {
mnt.Source = filepath.Clean(mnt.Source)
mnt.Target = filepath.Clean(mnt.Target)
c.Mounts[i] = mnt
}
}
// Module support only
//themeSet := cfg.IsSet("theme")
//if themeSet {
// sd := cfg.Get("theme")
// imports := types.ToStringSlicePreserveString(sd)
// for _, imp := range imports {
// c.Imports = append(c.Imports, Import{
// Path: imp,
// })
// }
//}
return c, nil
}
var DefaultModuleConfig = ModuleConfig{
Mounts: make([]Mount, 0),
Imports: make([]Import, 0),
}