create/skeletons: Honor --format flag when creating default archetype

Closes #12666
This commit is contained in:
Joe Mooring 2024-10-12 12:11:08 -07:00 committed by Bjørn Erik Pedersen
parent 5bb22b6b4e
commit 57151a5e91
2 changed files with 21 additions and 5 deletions

View file

@ -1,5 +0,0 @@
+++
title = '{{ replace .File.ContentBaseName "-" " " | title }}'
date = {{ .Date }}
draft = true
+++

View file

@ -76,6 +76,11 @@ func CreateSite(createpath string, sourceFs afero.Fs, force bool, format string)
return err return err
} }
err = newSiteCreateArchetype(sourceFs, createpath, format)
if err != nil {
return err
}
return copyFiles(createpath, sourceFs, siteFs) return copyFiles(createpath, sourceFs, siteFs)
} }
@ -109,3 +114,19 @@ func newSiteCreateConfig(fs afero.Fs, createpath string, format string) (err err
return helpers.WriteToDisk(filepath.Join(createpath, "hugo."+format), &buf, fs) return helpers.WriteToDisk(filepath.Join(createpath, "hugo."+format), &buf, fs)
} }
func newSiteCreateArchetype(fs afero.Fs, createpath string, format string) (err error) {
in := map[string]any{
"title": "{{ replace .File.ContentBaseName \"-\" \" \" | title }}",
"date": "{{ .Date }}",
"draft": true,
}
var buf bytes.Buffer
err = parser.InterfaceToConfig(in, metadecoders.FormatFromString(format), &buf)
if err != nil {
return err
}
return helpers.WriteToDisk(filepath.Join(createpath, "archetypes", "default.md"), &buf, fs)
}