diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-09-19 08:48:17 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-09-23 20:27:23 +0300 |
commit | 2650fa772b40846d9965f8c5f169286411f3beb2 (patch) | |
tree | 26d209ebea23611c146d851cb12827e793eaf6d5 /create/content_template_handler.go | |
parent | ef525b15d4584886b52428bd7a35de835ab07a48 (diff) |
Add directory based archetypes
Given this content:
```bash
archetypes
├── default.md
└── post-bundle
├── bio.md
├── images
│ └── featured.jpg
└── index.md
```
```bash
hugo new --kind post-bundle post/my-post
```
Will create a new folder in `/content/post/my-post` with the same set of files as in the `post-bundle` archetypes folder.
This commit also improves the archetype language detection, so, if you use template code in your content files, the `.Site` you get is for the correct language. This also means that it is now possible to translate strings defined in the `i18n` bundles, e.g. `{{ i18n "hello" }}`.
Fixes #4535
Diffstat (limited to 'create/content_template_handler.go')
-rw-r--r-- | create/content_template_handler.go | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/create/content_template_handler.go b/create/content_template_handler.go index 02598d4d3..458b7285c 100644 --- a/create/content_template_handler.go +++ b/create/content_template_handler.go @@ -80,7 +80,7 @@ var ( "%}x}", "%}}") ) -func executeArcheTypeAsTemplate(s *hugolib.Site, kind, targetPath, archetypeFilename string) ([]byte, error) { +func executeArcheTypeAsTemplate(s *hugolib.Site, name, kind, targetPath, archetypeFilename string) ([]byte, error) { var ( archetypeContent []byte @@ -88,20 +88,16 @@ func executeArcheTypeAsTemplate(s *hugolib.Site, kind, targetPath, archetypeFile err error ) - ps, err := helpers.NewPathSpec(s.Deps.Fs, s.Deps.Cfg) - if err != nil { - return nil, err - } - sp := source.NewSourceSpec(ps, ps.Fs.Source) - - f := sp.NewFileInfo("", targetPath, false, nil) + f := s.SourceSpec.NewFileInfo("", targetPath, false, nil) - name := f.TranslationBaseName() + if name == "" { + name = f.TranslationBaseName() - if name == "index" || name == "_index" { - // Page bundles; the directory name will hopefully have a better name. - dir := strings.TrimSuffix(f.Dir(), helpers.FilePathSeparator) - _, name = filepath.Split(dir) + if name == "index" || name == "_index" { + // Page bundles; the directory name will hopefully have a better name. + dir := strings.TrimSuffix(f.Dir(), helpers.FilePathSeparator) + _, name = filepath.Split(dir) + } } data := ArchetypeFileData{ |