fix date formats in frotmatter. close #28
This commit is contained in:
		
							parent
							
								
									f0175875b3
								
							
						
					
					
						commit
						427989d639
					
				|  | @ -7,6 +7,7 @@ import ( | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	"github.com/hacdias/caddy-hugo/utils" | 	"github.com/hacdias/caddy-hugo/utils" | ||||||
|  | 	"github.com/spf13/cast" | ||||||
| 	"github.com/spf13/hugo/parser" | 	"github.com/spf13/hugo/parser" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -136,11 +137,14 @@ func handleFlatValues(content interface{}, parent *frontmatter, name string) *fr | ||||||
| 		c.Type = "string" | 		c.Type = "string" | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	c.Content = content | ||||||
|  | 
 | ||||||
| 	switch strings.ToLower(name) { | 	switch strings.ToLower(name) { | ||||||
| 	case "description": | 	case "description": | ||||||
| 		c.HTMLType = "textarea" | 		c.HTMLType = "textarea" | ||||||
| 	case "date", "publishdate": | 	case "date", "publishdate": | ||||||
| 		c.HTMLType = "datetime" | 		c.HTMLType = "datetime" | ||||||
|  | 		c.Content = cast.ToTime(content) | ||||||
| 	default: | 	default: | ||||||
| 		c.HTMLType = "text" | 		c.HTMLType = "text" | ||||||
| 	} | 	} | ||||||
|  | @ -159,6 +163,5 @@ func handleFlatValues(content interface{}, parent *frontmatter, name string) *fr | ||||||
| 		log.Panic("Parent type not allowed in handleFlatValues.") | 		log.Panic("Parent type not allowed in handleFlatValues.") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	c.Content = content |  | ||||||
| 	return c | 	return c | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -28,7 +28,7 @@ | ||||||
|   {{ if eq $value.HTMLType "textarea" }} |   {{ 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> |   <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" }} |   {{ 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 }} |   {{ else }} | ||||||
|   <input name="{{ $value.Name }}:{{ $value.Type }}" id="{{ $value.Name }}" value="{{ $value.Content }}" type="{{ $value.HTMLType }}" data-parent-type="{{ $value.Parent.Type }}"></input> |   <input name="{{ $value.Name }}:{{ $value.Type }}" id="{{ $value.Name }}" value="{{ $value.Content }}" type="{{ $value.HTMLType }}" data-parent-type="{{ $value.Parent.Type }}"></input> | ||||||
|   {{ end }} |   {{ end }} | ||||||
|  |  | ||||||
|  | @ -89,6 +89,7 @@ func Dict(values ...interface{}) (map[string]interface{}, error) { | ||||||
| 		} | 		} | ||||||
| 		dict[key] = values[i+1] | 		dict[key] = values[i+1] | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
| 	return dict, nil | 	return dict, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue