fix date formats in frotmatter. close #28

This commit is contained in:
Henrique Dias 2016-02-07 15:07:45 +00:00
parent f0175875b3
commit 427989d639
3 changed files with 6 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
"strings"
"github.com/hacdias/caddy-hugo/utils"
"github.com/spf13/cast"
"github.com/spf13/hugo/parser"
)
@ -136,11 +137,14 @@ func handleFlatValues(content interface{}, parent *frontmatter, name string) *fr
c.Type = "string"
}
c.Content = content
switch strings.ToLower(name) {
case "description":
c.HTMLType = "textarea"
case "date", "publishdate":
c.HTMLType = "datetime"
c.Content = cast.ToTime(content)
default:
c.HTMLType = "text"
}
@ -159,6 +163,5 @@ func handleFlatValues(content interface{}, parent *frontmatter, name string) *fr
log.Panic("Parent type not allowed in handleFlatValues.")
}
c.Content = content
return c
}

View File

@ -28,7 +28,7 @@
{{ if eq $value.HTMLType "textarea" }}
<textarea class="scroll" name="{{ $value.Name }}:{{ $value.Type }}" id="{{ $value.Name }}" data-parent-type="{{ $value.Parent.Type }}">{{ $value.Content }}</textarea>
{{ else if eq $value.HTMLType "datetime" }}
<input name="{{ $value.Name }}:{{ $value.Type }}" id="{{ $value.Name }}" value="{{ $value.Content }}" type="text" data-parent-type="{{ $value.Parent.Type }}"></input>
<input name="{{ $value.Name }}:{{ $value.Type }}" id="{{ $value.Name }}" value="{{ $value.Content.Format "2006-01-02T15:04:05" }}" type="datetime-local" data-parent-type="{{ $value.Parent.Type }}"></input>
{{ else }}
<input name="{{ $value.Name }}:{{ $value.Type }}" id="{{ $value.Name }}" value="{{ $value.Content }}" type="{{ $value.HTMLType }}" data-parent-type="{{ $value.Parent.Type }}"></input>
{{ end }}

View File

@ -89,6 +89,7 @@ func Dict(values ...interface{}) (map[string]interface{}, error) {
}
dict[key] = values[i+1]
}
return dict, nil
}