summaryrefslogtreecommitdiffstats
path: root/create/content_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-06-18 19:06:28 +0200
committerGitHub <noreply@github.com>2017-06-18 19:06:28 +0200
commit422057f60709696bbbd1c38c9ead2bf114d47e31 (patch)
tree2d2a40f403559b226b826c49a82bb2993313c2c9 /create/content_test.go
parent4aa1239070bb9d4324d3582f3e809b702a59d3ac (diff)
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
Diffstat (limited to 'create/content_test.go')
-rw-r--r--create/content_test.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/create/content_test.go b/create/content_test.go
index 8eaaf7bf5..aa7ed3fcf 100644
--- a/create/content_test.go
+++ b/create/content_test.go
@@ -45,9 +45,9 @@ func TestNewContent(t *testing.T) {
}{
{"post", "post/sample-1.md", []string{`title = "Post Arch title"`, `test = "test1"`, "date = \"2015-01-12T19:20:04-07:00\""}},
{"emptydate", "post/sample-ed.md", []string{`title = "Empty Date Arch title"`, `test = "test1"`}},
- {"stump", "stump/sample-2.md", []string{`title = "sample 2"`}}, // no archetype file
- {"", "sample-3.md", []string{`title = "sample 3"`}}, // no archetype
- {"product", "product/sample-4.md", []string{`title = "sample 4"`}}, // empty archetype front matter
+ {"stump", "stump/sample-2.md", []string{`title = "Sample 2"`}}, // no archetype file
+ {"", "sample-3.md", []string{`title = "Sample 3"`}}, // no archetype
+ {"product", "product/sample-4.md", []string{`title = "SAMPLE-4"`}}, // empty archetype front matter
}
for _, c := range cases {
@@ -108,8 +108,10 @@ func initFs(fs *hugofs.Fs) error {
content: "+++\ndate = \"2015-01-12T19:20:04-07:00\"\ntitle = \"Post Arch title\"\ntest = \"test1\"\n+++\n",
},
{
- path: filepath.Join("archetypes", "product.md"),
- content: "+++\n+++\n",
+ path: filepath.Join("archetypes", "product.md"),
+ content: `+++
+title = "{{ .BaseFileName | upper }}"
++++`,
},
{
path: filepath.Join("archetypes", "emptydate.md"),