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 #9032
Fixes #7589
Fixes #9043
Fixes #9046
Fixes #9047
  • Loading branch information
bep committed Oct 16, 2021
1 parent 168a3aa commit 9185e11
Show file tree
Hide file tree
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
Expand Up @@ -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)
}
}
Expand Down
12 changes: 1 addition & 11 deletions commands/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion commands/new_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Loading

0 comments on commit 9185e11

Please sign in to comment.