create: Use archetype template as-is as a Go template

This commit removes the fragile front matter decoding, and takes the provided archetype file as-is and processes it as a template.

This also means that we no longer will attempt to fill in default values for `title` and `date`.

The upside is that it is now easy to create these values in a dynamic way:

```toml
+++
title = {{ .BaseFileName | title }}
date = {{ .Date }}
draft = true
+++
```

You can currently use all of Hugo's template funcs, but the data context is currently very shallow:

* `.Type` gives the archetype kind provided
* `.Name` gives the target file name without extension.
* `.Path` gives the target file name
* `.Date` gives the current time as RFC3339 formatted string

The above  will probably be extended in #1629.

Fixes #452
Updates #1629
This commit is contained in:
Bjørn Erik Pedersen
2017-06-18 19:06:28 +02:00
committed by GitHub
parent 4aa1239070
commit 422057f607
5 changed files with 116 additions and 100 deletions

View File

@@ -42,7 +42,6 @@ var (
func init() {
newSiteCmd.Flags().StringVarP(&configFormat, "format", "f", "toml", "config & frontmatter format")
newSiteCmd.Flags().Bool("force", false, "init inside non-empty directory")
newCmd.Flags().StringVarP(&configFormat, "format", "f", "toml", "frontmatter format")
newCmd.Flags().StringVarP(&contentType, "kind", "k", "", "content type to create")
newCmd.PersistentFlags().StringVarP(&source, "source", "s", "", "filesystem path to read files relative from")
newCmd.PersistentFlags().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{})
@@ -98,10 +97,6 @@ func NewContent(cmd *cobra.Command, args []string) error {
return err
}
if cmd.Flags().Changed("format") {
c.Set("metaDataFormat", configFormat)
}
if cmd.Flags().Changed("editor") {
c.Set("newContentEditor", contentEditor)
}