Skip to content

Commit

Permalink
Reimplement archetypes
Browse files Browse the repository at this point in the history
The old implementation had some issues, mostly related to the context (e.g. name, file paths) passed to the template.

This new implementation is using the exact same code path for evaluating the pages as in a regular build.

This also makes it more robust and easier to reason about in a multilingual setup.

Now, if you are explicit about the target path, Hugo will now always pick the correct mount and language:

```bash
hugo new content/en/posts/my-first-post.md
```

Fixes gohugoio#9032
Fixes gohugoio#7589
Fixes gohugoio#9043
Fixes gohugoio#9046
Fixes gohugoio#9047
bep committed Oct 16, 2021

Verified

This commit was signed with the committer’s verified signature.
mikz Michal Cichra
1 parent d7331aa commit c84a190
Showing 19 changed files with 857 additions and 446 deletions.
2 changes: 1 addition & 1 deletion commands/hugo.go
Original file line number Diff line number Diff line change
@@ -870,7 +870,7 @@ func (c *commandeer) newWatcher(pollIntervalStr string, dirList ...string) (*wat
livereload.ForceRefresh()
}
case err := <-watcher.Errors():
if err != nil {
if err != nil && !os.IsNotExist(err) {
c.logger.Errorln("Error while watching:", err)
}
}
12 changes: 1 addition & 11 deletions commands/new.go
Original file line number Diff line number Diff line change
@@ -80,17 +80,7 @@ func (n *newCmd) newContent(cmd *cobra.Command, args []string) error {
return newUserError("path needs to be provided")
}

createPath := args[0]

var kind string

createPath, kind = newContentPathSection(c.hugo(), createPath)

if n.contentType != "" {
kind = n.contentType
}

return create.NewContent(c.hugo(), kind, createPath)
return create.NewContent(c.hugo(), n.contentType, args[0])
}

func mkdir(x ...string) {
2 changes: 1 addition & 1 deletion commands/new_site.go
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ func (n *newSiteCmd) doNewSite(fs *hugofs.Fs, basepath string, force bool) error

// Create a default archetype file.
helpers.SafeWriteToDisk(filepath.Join(archeTypePath, "default.md"),
strings.NewReader(create.ArchetypeTemplateTemplate), fs.Source)
strings.NewReader(create.DefaultArchetypeTemplateTemplate), fs.Source)

jww.FEEDBACK.Printf("Congratulations! Your new Hugo site is created in %s.\n\n", basepath)
jww.FEEDBACK.Println(nextStepsText())
Loading

0 comments on commit c84a190

Please sign in to comment.