mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
Updating Convert to handle dates properly for yaml and json
Fix bug with YAML & JSON with handling dates with 'new' and 'convert'
This commit is contained in:
@@ -16,7 +16,9 @@ package commands
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/hugo/hugolib"
|
||||
"github.com/spf13/hugo/parser"
|
||||
@@ -114,6 +116,18 @@ func convertContents(mark rune) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// better handling of dates in formats that don't have support for them
|
||||
if mark == parser.FormatToLeadRune("json") || mark == parser.FormatToLeadRune("yaml") {
|
||||
newmetadata := cast.ToStringMap(metadata)
|
||||
for k, v := range newmetadata {
|
||||
switch vv := v.(type) {
|
||||
case time.Time:
|
||||
newmetadata[k] = vv.Format(time.RFC3339)
|
||||
}
|
||||
}
|
||||
metadata = newmetadata
|
||||
}
|
||||
|
||||
page.Dir = file.Dir
|
||||
page.SetSourceContent(psr.Content())
|
||||
page.SetSourceMetaData(metadata, mark)
|
||||
|
Reference in New Issue
Block a user