commands: Add version time to "hugo config mounts"
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 27 Jun 2021 16:00:20 +0000 (18:00 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 27 Jun 2021 16:00:20 +0000 (18:00 +0200)
commands/config.go
modules/module.go

index 56692651cc6a0c14c7732985fce6bcddd54d8742..2b2920cdd92473d56b1d83ebae8d9d8326d55250 100644 (file)
@@ -21,6 +21,7 @@ import (
        "regexp"
        "sort"
        "strings"
+       "time"
 
        "github.com/gohugoio/hugo/common/maps"
 
@@ -146,6 +147,7 @@ func (m *modMounts) MarshalJSON() ([]byte, error) {
                return json.Marshal(&struct {
                        Path        string                 `json:"path"`
                        Version     string                 `json:"version"`
+                       Time        *time.Time             `json:"time"`
                        Owner       string                 `json:"owner"`
                        Dir         string                 `json:"dir"`
                        Meta        map[string]interface{} `json:"meta"`
@@ -155,6 +157,7 @@ func (m *modMounts) MarshalJSON() ([]byte, error) {
                }{
                        Path:        m.m.Path(),
                        Version:     m.m.Version(),
+                       Time:        m.m.Time(),
                        Owner:       ownerPath,
                        Dir:         m.m.Dir(),
                        Meta:        config.Params,
@@ -166,12 +169,14 @@ func (m *modMounts) MarshalJSON() ([]byte, error) {
        return json.Marshal(&struct {
                Path    string     `json:"path"`
                Version string     `json:"version"`
+               Time    *time.Time `json:"time"`
                Owner   string     `json:"owner"`
                Dir     string     `json:"dir"`
                Mounts  []modMount `json:"mounts"`
        }{
                Path:    m.m.Path(),
                Version: m.m.Version(),
+               Time:    m.m.Time(),
                Owner:   ownerPath,
                Dir:     m.m.Dir(),
                Mounts:  mounts,
index c3343c820d83408d690b251d91e91ee4532d7049..a6feaab736b86366a23d426ae86e2a35ad3fd62b 100644 (file)
@@ -17,6 +17,8 @@
 package modules
 
 import (
+       "time"
+
        "github.com/gohugoio/hugo/config"
 )
 
@@ -65,6 +67,9 @@ type Module interface {
        // The module version.
        Version() string
 
+       // Time version was created.
+       Time() *time.Time
+
        // Whether this module's dir is a watch candidate.
        Watch() bool
 }
@@ -154,6 +159,14 @@ func (m *moduleAdapter) Version() string {
        return m.gomod.Version
 }
 
+func (m *moduleAdapter) Time() *time.Time {
+       if !m.IsGoMod() || m.gomod.Time == nil {
+               return nil
+       }
+
+       return m.gomod.Time
+}
+
 func (m *moduleAdapter) Watch() bool {
        if m.Owner() == nil {
                // Main project