commands/new: Improve theme creation

- Update the skeleton structure to match the new template system.
- Add a --format flag to the `hugo new theme` command to control the
  format of the site configuration and default archetype files.
- Remove theme.toml. This file's presence can be confusing for new
  users, and the README in the themes repository already has an example.
- Remove the LICENSE and README files from the skeleton. These files
  are not needed for a theme to work, and they can be added later by
  the user if desired.

Closes #13489
Closes #13544
This commit is contained in:
Joe Mooring 2025-03-30 12:31:12 -07:00 committed by Bjørn Erik Pedersen
parent e6e18e9122
commit 24ac6a9de9
22 changed files with 123 additions and 136 deletions

View file

@ -144,7 +144,7 @@ according to your needs.`,
createpath := paths.AbsPathify(conf.configs.Base.WorkingDir, filepath.Join(conf.configs.Base.ThemesDir, args[0]))
r.Println("Creating new theme in", createpath)
err = skeletons.CreateTheme(createpath, sourceFs)
err = skeletons.CreateTheme(createpath, sourceFs, format)
if err != nil {
return err
}
@ -152,7 +152,14 @@ according to your needs.`,
return nil
},
withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.ValidArgsFunction = cobra.NoFileCompletions
cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return []string{}, cobra.ShellCompDirectiveNoFileComp
}
return []string{}, cobra.ShellCompDirectiveNoFileComp | cobra.ShellCompDirectiveFilterDirs
}
cmd.Flags().StringVar(&format, "format", "toml", "preferred file format (toml, yaml or json)")
_ = cmd.RegisterFlagCompletionFunc("format", cobra.FixedCompletions([]string{"toml", "yaml", "json"}, cobra.ShellCompDirectiveNoFileComp))
},
},
},