mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
7ce033a89d
commit
8a69ccbb00
16 changed files with 86 additions and 71 deletions
|
@ -111,22 +111,6 @@ type rootCommand struct {
|
||||||
environment string
|
environment string
|
||||||
|
|
||||||
// Common build flags.
|
// Common build flags.
|
||||||
*buildFlags
|
|
||||||
|
|
||||||
// TODO(bep) var vs string
|
|
||||||
logging bool
|
|
||||||
verbose bool
|
|
||||||
verboseLog bool
|
|
||||||
debug bool
|
|
||||||
quiet bool
|
|
||||||
renderToMemory bool
|
|
||||||
|
|
||||||
cfgFile string
|
|
||||||
cfgDir string
|
|
||||||
logFile string
|
|
||||||
}
|
|
||||||
|
|
||||||
type buildFlags struct {
|
|
||||||
baseURL string
|
baseURL string
|
||||||
gc bool
|
gc bool
|
||||||
poll string
|
poll string
|
||||||
|
@ -139,6 +123,18 @@ type buildFlags struct {
|
||||||
mutexprofile string
|
mutexprofile string
|
||||||
traceprofile string
|
traceprofile string
|
||||||
printm bool
|
printm bool
|
||||||
|
|
||||||
|
// TODO(bep) var vs string
|
||||||
|
logging bool
|
||||||
|
verbose bool
|
||||||
|
verboseLog bool
|
||||||
|
debug bool
|
||||||
|
quiet bool
|
||||||
|
renderToMemory bool
|
||||||
|
|
||||||
|
cfgFile string
|
||||||
|
cfgDir string
|
||||||
|
logFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rootCommand) Build(cd *simplecobra.Commandeer, bcfg hugolib.BuildCfg, cfg config.Provider) (*hugolib.HugoSites, error) {
|
func (r *rootCommand) Build(cd *simplecobra.Commandeer, bcfg hugolib.BuildCfg, cfg config.Provider) (*hugolib.HugoSites, error) {
|
||||||
|
@ -384,7 +380,7 @@ func (r *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rootCommand) Init(cd, runner *simplecobra.Commandeer) error {
|
func (r *rootCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||||
r.Out = os.Stdout
|
r.Out = os.Stdout
|
||||||
if r.quiet {
|
if r.quiet {
|
||||||
r.Out = io.Discard
|
r.Out = io.Discard
|
||||||
|
@ -463,7 +459,8 @@ func (r *rootCommand) IsTestRun() bool {
|
||||||
return os.Getenv("HUGO_TESTRUN") != ""
|
return os.Getenv("HUGO_TESTRUN") != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rootCommand) WithCobraCommand(cmd *cobra.Command) error {
|
func (r *rootCommand) Init(cd *simplecobra.Commandeer) error {
|
||||||
|
cmd := cd.CobraCommand
|
||||||
cmd.Use = "hugo [flags]"
|
cmd.Use = "hugo [flags]"
|
||||||
cmd.Short = "hugo builds your site"
|
cmd.Short = "hugo builds your site"
|
||||||
cmd.Long = `hugo is the main command, used to build your Hugo site.
|
cmd.Long = `hugo is the main command, used to build your Hugo site.
|
||||||
|
@ -503,7 +500,7 @@ Complete documentation is available at https://gohugo.io/.`
|
||||||
_ = cmd.PersistentFlags().SetAnnotation("logFile", cobra.BashCompFilenameExt, []string{})
|
_ = cmd.PersistentFlags().SetAnnotation("logFile", cobra.BashCompFilenameExt, []string{})
|
||||||
|
|
||||||
// Configure local flags
|
// Configure local flags
|
||||||
applyLocalBuildFlags(cmd, r.buildFlags)
|
applyLocalBuildFlags(cmd, r)
|
||||||
|
|
||||||
// Set bash-completion.
|
// Set bash-completion.
|
||||||
// Each flag must first be defined before using the SetAnnotation() call.
|
// Each flag must first be defined before using the SetAnnotation() call.
|
||||||
|
@ -512,7 +509,7 @@ Complete documentation is available at https://gohugo.io/.`
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyLocalBuildFlags(cmd *cobra.Command, f *buildFlags) {
|
func applyLocalBuildFlags(cmd *cobra.Command, r *rootCommand) {
|
||||||
cmd.Flags().Bool("cleanDestinationDir", false, "remove files from destination not found in static directories")
|
cmd.Flags().Bool("cleanDestinationDir", false, "remove files from destination not found in static directories")
|
||||||
cmd.Flags().BoolP("buildDrafts", "D", false, "include content marked as draft")
|
cmd.Flags().BoolP("buildDrafts", "D", false, "include content marked as draft")
|
||||||
cmd.Flags().BoolP("buildFuture", "F", false, "include content with publishdate in the future")
|
cmd.Flags().BoolP("buildFuture", "F", false, "include content with publishdate in the future")
|
||||||
|
@ -522,25 +519,25 @@ func applyLocalBuildFlags(cmd *cobra.Command, f *buildFlags) {
|
||||||
cmd.Flags().StringP("cacheDir", "", "", "filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/")
|
cmd.Flags().StringP("cacheDir", "", "", "filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/")
|
||||||
cmd.Flags().BoolP("ignoreCache", "", false, "ignores the cache directory")
|
cmd.Flags().BoolP("ignoreCache", "", false, "ignores the cache directory")
|
||||||
cmd.Flags().StringSliceP("theme", "t", []string{}, "themes to use (located in /themes/THEMENAME/)")
|
cmd.Flags().StringSliceP("theme", "t", []string{}, "themes to use (located in /themes/THEMENAME/)")
|
||||||
cmd.Flags().StringVarP(&f.baseURL, "baseURL", "b", "", "hostname (and path) to the root, e.g. https://spf13.com/")
|
cmd.Flags().StringVarP(&r.baseURL, "baseURL", "b", "", "hostname (and path) to the root, e.g. https://spf13.com/")
|
||||||
cmd.Flags().Bool("enableGitInfo", false, "add Git revision, date, author, and CODEOWNERS info to the pages")
|
cmd.Flags().Bool("enableGitInfo", false, "add Git revision, date, author, and CODEOWNERS info to the pages")
|
||||||
cmd.Flags().BoolVar(&f.gc, "gc", false, "enable to run some cleanup tasks (remove unused cache files) after the build")
|
cmd.Flags().BoolVar(&r.gc, "gc", false, "enable to run some cleanup tasks (remove unused cache files) after the build")
|
||||||
cmd.Flags().StringVar(&f.poll, "poll", "", "set this to a poll interval, e.g --poll 700ms, to use a poll based approach to watch for file system changes")
|
cmd.Flags().StringVar(&r.poll, "poll", "", "set this to a poll interval, e.g --poll 700ms, to use a poll based approach to watch for file system changes")
|
||||||
cmd.Flags().BoolVar(&f.panicOnWarning, "panicOnWarning", false, "panic on first WARNING log")
|
cmd.Flags().BoolVar(&r.panicOnWarning, "panicOnWarning", false, "panic on first WARNING log")
|
||||||
cmd.Flags().Bool("templateMetrics", false, "display metrics about template executions")
|
cmd.Flags().Bool("templateMetrics", false, "display metrics about template executions")
|
||||||
cmd.Flags().Bool("templateMetricsHints", false, "calculate some improvement hints when combined with --templateMetrics")
|
cmd.Flags().Bool("templateMetricsHints", false, "calculate some improvement hints when combined with --templateMetrics")
|
||||||
cmd.Flags().BoolVar(&f.forceSyncStatic, "forceSyncStatic", false, "copy all files when static is changed.")
|
cmd.Flags().BoolVar(&r.forceSyncStatic, "forceSyncStatic", false, "copy all files when static is changed.")
|
||||||
cmd.Flags().BoolP("noTimes", "", false, "don't sync modification time of files")
|
cmd.Flags().BoolP("noTimes", "", false, "don't sync modification time of files")
|
||||||
cmd.Flags().BoolP("noChmod", "", false, "don't sync permission mode of files")
|
cmd.Flags().BoolP("noChmod", "", false, "don't sync permission mode of files")
|
||||||
cmd.Flags().BoolP("noBuildLock", "", false, "don't create .hugo_build.lock file")
|
cmd.Flags().BoolP("noBuildLock", "", false, "don't create .hugo_build.lock file")
|
||||||
cmd.Flags().BoolP("printI18nWarnings", "", false, "print missing translations")
|
cmd.Flags().BoolP("printI18nWarnings", "", false, "print missing translations")
|
||||||
cmd.Flags().BoolP("printPathWarnings", "", false, "print warnings on duplicate target paths etc.")
|
cmd.Flags().BoolP("printPathWarnings", "", false, "print warnings on duplicate target paths etc.")
|
||||||
cmd.Flags().BoolP("printUnusedTemplates", "", false, "print warnings on unused templates.")
|
cmd.Flags().BoolP("printUnusedTemplates", "", false, "print warnings on unused templates.")
|
||||||
cmd.Flags().StringVarP(&f.cpuprofile, "profile-cpu", "", "", "write cpu profile to `file`")
|
cmd.Flags().StringVarP(&r.cpuprofile, "profile-cpu", "", "", "write cpu profile to `file`")
|
||||||
cmd.Flags().StringVarP(&f.memprofile, "profile-mem", "", "", "write memory profile to `file`")
|
cmd.Flags().StringVarP(&r.memprofile, "profile-mem", "", "", "write memory profile to `file`")
|
||||||
cmd.Flags().BoolVarP(&f.printm, "printMemoryUsage", "", false, "print memory usage to screen at intervals")
|
cmd.Flags().BoolVarP(&r.printm, "printMemoryUsage", "", false, "print memory usage to screen at intervals")
|
||||||
cmd.Flags().StringVarP(&f.mutexprofile, "profile-mutex", "", "", "write Mutex profile to `file`")
|
cmd.Flags().StringVarP(&r.mutexprofile, "profile-mutex", "", "", "write Mutex profile to `file`")
|
||||||
cmd.Flags().StringVarP(&f.traceprofile, "trace", "", "", "write trace to `file` (not useful in general)")
|
cmd.Flags().StringVarP(&r.traceprofile, "trace", "", "", "write trace to `file` (not useful in general)")
|
||||||
|
|
||||||
// Hide these for now.
|
// Hide these for now.
|
||||||
cmd.Flags().MarkHidden("profile-cpu")
|
cmd.Flags().MarkHidden("profile-cpu")
|
||||||
|
@ -591,7 +588,8 @@ func (c *simpleCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
|
||||||
return c.run(ctx, cd, c.rootCmd, args)
|
return c.run(ctx, cd, c.rootCmd, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *simpleCommand) WithCobraCommand(cmd *cobra.Command) error {
|
func (c *simpleCommand) Init(cd *simplecobra.Commandeer) error {
|
||||||
|
cmd := cd.CobraCommand
|
||||||
cmd.Short = c.short
|
cmd.Short = c.short
|
||||||
cmd.Long = c.long
|
cmd.Long = c.long
|
||||||
if c.use != "" {
|
if c.use != "" {
|
||||||
|
@ -603,7 +601,7 @@ func (c *simpleCommand) WithCobraCommand(cmd *cobra.Command) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *simpleCommand) Init(cd, runner *simplecobra.Commandeer) error {
|
func (c *simpleCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||||
c.rootCmd = cd.Root.Command.(*rootCommand)
|
c.rootCmd = cd.Root.Command.(*rootCommand)
|
||||||
if c.initc != nil {
|
if c.initc != nil {
|
||||||
return c.initc(cd)
|
return c.initc(cd)
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
// newExec wires up all of Hugo's CLI.
|
// newExec wires up all of Hugo's CLI.
|
||||||
func newExec() (*simplecobra.Exec, error) {
|
func newExec() (*simplecobra.Exec, error) {
|
||||||
rootCmd := &rootCommand{
|
rootCmd := &rootCommand{
|
||||||
buildFlags: &buildFlags{},
|
|
||||||
commands: []simplecobra.Commander{
|
commands: []simplecobra.Commander{
|
||||||
newVersionCmd(),
|
newVersionCmd(),
|
||||||
newEnvCommand(),
|
newEnvCommand(),
|
||||||
|
|
|
@ -23,7 +23,6 @@ import (
|
||||||
"github.com/gohugoio/hugo/modules"
|
"github.com/gohugoio/hugo/modules"
|
||||||
"github.com/gohugoio/hugo/parser"
|
"github.com/gohugoio/hugo/parser"
|
||||||
"github.com/gohugoio/hugo/parser/metadecoders"
|
"github.com/gohugoio/hugo/parser/metadecoders"
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// newConfigCommand creates a new config command and its subcommands.
|
// newConfigCommand creates a new config command and its subcommands.
|
||||||
|
@ -68,13 +67,14 @@ func (c *configCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configCommand) WithCobraCommand(cmd *cobra.Command) error {
|
func (c *configCommand) Init(cd *simplecobra.Commandeer) error {
|
||||||
|
cmd := cd.CobraCommand
|
||||||
cmd.Short = "Print the site configuration"
|
cmd.Short = "Print the site configuration"
|
||||||
cmd.Long = `Print the site configuration, both default and custom settings.`
|
cmd.Long = `Print the site configuration, both default and custom settings.`
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configCommand) Init(cd, runner *simplecobra.Commandeer) error {
|
func (c *configCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||||
c.r = cd.Root.Command.(*rootCommand)
|
c.r = cd.Root.Command.(*rootCommand)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -176,12 +176,13 @@ func (c *configMountsCommand) Run(ctx context.Context, cd *simplecobra.Commandee
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configMountsCommand) WithCobraCommand(cmd *cobra.Command) error {
|
func (c *configMountsCommand) Init(cd *simplecobra.Commandeer) error {
|
||||||
|
cmd := cd.CobraCommand
|
||||||
cmd.Short = "Print the configured file mounts"
|
cmd.Short = "Print the configured file mounts"
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configMountsCommand) Init(cd, runner *simplecobra.Commandeer) error {
|
func (c *configMountsCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||||
c.configCmd = cd.Parent.Command.(*configCommand)
|
c.configCmd = cd.Parent.Command.(*configCommand)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,8 @@ func (c *convertCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, ar
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *convertCommand) WithCobraCommand(cmd *cobra.Command) error {
|
func (c *convertCommand) Init(cd *simplecobra.Commandeer) error {
|
||||||
|
cmd := cd.CobraCommand
|
||||||
cmd.Short = "Convert your content to different formats"
|
cmd.Short = "Convert your content to different formats"
|
||||||
cmd.Long = `Convert your content (e.g. front matter) to different formats.
|
cmd.Long = `Convert your content (e.g. front matter) to different formats.
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ See convert's subcommands toJSON, toTOML and toYAML for more information.`
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *convertCommand) Init(cd, runner *simplecobra.Commandeer) error {
|
func (c *convertCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||||
c.r = cd.Root.Command.(*rootCommand)
|
c.r = cd.Root.Command.(*rootCommand)
|
||||||
cfg := config.New()
|
cfg := config.New()
|
||||||
cfg.Set("buildDrafts", true)
|
cfg.Set("buildDrafts", true)
|
||||||
|
|
|
@ -202,12 +202,13 @@ func (c *genCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args [
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *genCommand) WithCobraCommand(cmd *cobra.Command) error {
|
func (c *genCommand) Init(cd *simplecobra.Commandeer) error {
|
||||||
|
cmd := cd.CobraCommand
|
||||||
cmd.Short = "A collection of several useful generators."
|
cmd.Short = "A collection of several useful generators."
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *genCommand) Init(cd, runner *simplecobra.Commandeer) error {
|
func (c *genCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||||
c.rootCmd = cd.Root.Command.(*rootCommand)
|
c.rootCmd = cd.Root.Command.(*rootCommand)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,8 @@ func (c *importCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *importCommand) WithCobraCommand(cmd *cobra.Command) error {
|
func (c *importCommand) Init(cd *simplecobra.Commandeer) error {
|
||||||
|
cmd := cd.CobraCommand
|
||||||
cmd.Short = "Import your site from others."
|
cmd.Short = "Import your site from others."
|
||||||
cmd.Long = `Import your site from other web site generators like Jekyll.
|
cmd.Long = `Import your site from other web site generators like Jekyll.
|
||||||
|
|
||||||
|
@ -99,7 +100,7 @@ Import requires a subcommand, e.g. ` + "`hugo import jekyll jekyll_root_path tar
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *importCommand) Init(cd, runner *simplecobra.Commandeer) error {
|
func (c *importCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||||
c.r = cd.Root.Command.(*rootCommand)
|
c.r = cd.Root.Command.(*rootCommand)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import (
|
||||||
"github.com/gohugoio/hugo/hugolib"
|
"github.com/gohugoio/hugo/hugolib"
|
||||||
"github.com/gohugoio/hugo/resources/page"
|
"github.com/gohugoio/hugo/resources/page"
|
||||||
"github.com/gohugoio/hugo/resources/resource"
|
"github.com/gohugoio/hugo/resources/resource"
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// newListCommand creates a new list command and its subcommands.
|
// newListCommand creates a new list command and its subcommands.
|
||||||
|
@ -153,7 +152,8 @@ func (c *listCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *listCommand) WithCobraCommand(cmd *cobra.Command) error {
|
func (c *listCommand) Init(cd *simplecobra.Commandeer) error {
|
||||||
|
cmd := cd.CobraCommand
|
||||||
cmd.Short = "Listing out various types of content"
|
cmd.Short = "Listing out various types of content"
|
||||||
cmd.Long = `Listing out various types of content.
|
cmd.Long = `Listing out various types of content.
|
||||||
|
|
||||||
|
@ -162,6 +162,6 @@ List requires a subcommand, e.g. hugo list drafts`
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *listCommand) Init(cd, runner *simplecobra.Commandeer) error {
|
func (c *listCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,7 +293,8 @@ func (c *modCommands) Run(ctx context.Context, cd *simplecobra.Commandeer, args
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *modCommands) WithCobraCommand(cmd *cobra.Command) error {
|
func (c *modCommands) Init(cd *simplecobra.Commandeer) error {
|
||||||
|
cmd := cd.CobraCommand
|
||||||
cmd.Short = "Various Hugo Modules helpers."
|
cmd.Short = "Various Hugo Modules helpers."
|
||||||
cmd.Long = `Various helpers to help manage the modules in your project's dependency graph.
|
cmd.Long = `Various helpers to help manage the modules in your project's dependency graph.
|
||||||
Most operations here requires a Go version installed on your system (>= Go 1.12) and the relevant VCS client (typically Git).
|
Most operations here requires a Go version installed on your system (>= Go 1.12) and the relevant VCS client (typically Git).
|
||||||
|
@ -304,7 +305,7 @@ This is not needed if you only operate on modules inside /themes or if you have
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *modCommands) Init(cd, runner *simplecobra.Commandeer) error {
|
func (c *modCommands) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||||
c.r = cd.Root.Command.(*rootCommand)
|
c.r = cd.Root.Command.(*rootCommand)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,7 +271,8 @@ func (c *newCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args [
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *newCommand) WithCobraCommand(cmd *cobra.Command) error {
|
func (c *newCommand) Init(cd *simplecobra.Commandeer) error {
|
||||||
|
cmd := cd.CobraCommand
|
||||||
cmd.Short = "Create new content for your site"
|
cmd.Short = "Create new content for your site"
|
||||||
cmd.Long = `Create a new content file and automatically set the date and title.
|
cmd.Long = `Create a new content file and automatically set the date and title.
|
||||||
It will guess which kind of file to create based on the path provided.
|
It will guess which kind of file to create based on the path provided.
|
||||||
|
@ -284,7 +285,7 @@ Ensure you run this within the root directory of your site.`
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *newCommand) Init(cd, runner *simplecobra.Commandeer) error {
|
func (c *newCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||||
c.rootCmd = cd.Root.Command.(*rootCommand)
|
c.rootCmd = cd.Root.Command.(*rootCommand)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,6 @@ import (
|
||||||
"github.com/gohugoio/hugo/transform"
|
"github.com/gohugoio/hugo/transform"
|
||||||
"github.com/gohugoio/hugo/transform/livereloadinject"
|
"github.com/gohugoio/hugo/transform/livereloadinject"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/fsync"
|
"github.com/spf13/fsync"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"golang.org/x/sync/semaphore"
|
"golang.org/x/sync/semaphore"
|
||||||
|
@ -99,7 +98,6 @@ func newHugoBuilder(r *rootCommand, s *serverCommand, onConfigLoaded ...func(rel
|
||||||
func newServerCommand() *serverCommand {
|
func newServerCommand() *serverCommand {
|
||||||
var c *serverCommand
|
var c *serverCommand
|
||||||
c = &serverCommand{
|
c = &serverCommand{
|
||||||
buildFlags: &buildFlags{},
|
|
||||||
quit: make(chan bool),
|
quit: make(chan bool),
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
|
@ -408,10 +406,6 @@ type serverCommand struct {
|
||||||
doLiveReload bool
|
doLiveReload bool
|
||||||
|
|
||||||
// Flags.
|
// Flags.
|
||||||
|
|
||||||
// Common build flags.
|
|
||||||
*buildFlags
|
|
||||||
|
|
||||||
renderToDisk bool
|
renderToDisk bool
|
||||||
renderStaticToDisk bool
|
renderStaticToDisk bool
|
||||||
navigateToChanged bool
|
navigateToChanged bool
|
||||||
|
@ -472,7 +466,8 @@ func (c *serverCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
|
||||||
return c.serve()
|
return c.serve()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *serverCommand) WithCobraCommand(cmd *cobra.Command) error {
|
func (c *serverCommand) Init(cd *simplecobra.Commandeer) error {
|
||||||
|
cmd := cd.CobraCommand
|
||||||
cmd.Short = "A high performance webserver"
|
cmd.Short = "A high performance webserver"
|
||||||
cmd.Long = `Hugo provides its own webserver which builds and serves the site.
|
cmd.Long = `Hugo provides its own webserver which builds and serves the site.
|
||||||
While hugo server is high performance, it is a webserver with limited options.
|
While hugo server is high performance, it is a webserver with limited options.
|
||||||
|
@ -504,12 +499,13 @@ of a second, you will be able to save and see your changes nearly instantly.`
|
||||||
cmd.Flags().String("memstats", "", "log memory usage to this file")
|
cmd.Flags().String("memstats", "", "log memory usage to this file")
|
||||||
cmd.Flags().String("meminterval", "100ms", "interval to poll memory usage (requires --memstats), valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\".")
|
cmd.Flags().String("meminterval", "100ms", "interval to poll memory usage (requires --memstats), valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\".")
|
||||||
|
|
||||||
applyLocalBuildFlags(cmd, c.buildFlags)
|
r := cd.Root.Command.(*rootCommand)
|
||||||
|
applyLocalBuildFlags(cmd, r)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *serverCommand) Init(cd, runner *simplecobra.Commandeer) error {
|
func (c *serverCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||||
c.r = cd.Root.Command.(*rootCommand)
|
c.r = cd.Root.Command.(*rootCommand)
|
||||||
|
|
||||||
c.hugoBuilder = newHugoBuilder(
|
c.hugoBuilder = newHugoBuilder(
|
||||||
|
|
|
@ -66,13 +66,14 @@ func (c *templateCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, a
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *templateCommand) WithCobraCommand(cmd *cobra.Command) error {
|
func (c *templateCommand) Init(cd *simplecobra.Commandeer) error {
|
||||||
|
cmd := cd.CobraCommand
|
||||||
cmd.Short = "Print the site configuration"
|
cmd.Short = "Print the site configuration"
|
||||||
cmd.Long = `Print the site configuration, both default and custom settings.`
|
cmd.Long = `Print the site configuration, both default and custom settings.`
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *templateCommand) Init(cd, runner *simplecobra.Commandeer) error {
|
func (c *templateCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||||
c.r = cd.Root.Command.(*rootCommand)
|
c.r = cd.Root.Command.(*rootCommand)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/cache/filecache"
|
"github.com/gohugoio/hugo/cache/filecache"
|
||||||
|
@ -92,7 +93,7 @@ type Config struct {
|
||||||
// For internal use only.
|
// For internal use only.
|
||||||
Internal InternalConfig `mapstructure:"-" json:"-"`
|
Internal InternalConfig `mapstructure:"-" json:"-"`
|
||||||
// For internal use only.
|
// For internal use only.
|
||||||
C ConfigCompiled `mapstructure:"-" json:"-"`
|
C *ConfigCompiled `mapstructure:"-" json:"-"`
|
||||||
|
|
||||||
RootConfig
|
RootConfig
|
||||||
|
|
||||||
|
@ -188,6 +189,8 @@ type configCompiler interface {
|
||||||
|
|
||||||
func (c Config) cloneForLang() *Config {
|
func (c Config) cloneForLang() *Config {
|
||||||
x := c
|
x := c
|
||||||
|
x.C = nil
|
||||||
|
|
||||||
// Collapse all static dirs to one.
|
// Collapse all static dirs to one.
|
||||||
x.StaticDir = x.staticDirs()
|
x.StaticDir = x.staticDirs()
|
||||||
// These will go away soon ...
|
// These will go away soon ...
|
||||||
|
@ -302,7 +305,7 @@ func (c *Config) CompileConfig() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.C = ConfigCompiled{
|
c.C = &ConfigCompiled{
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
BaseURL: baseURL,
|
BaseURL: baseURL,
|
||||||
BaseURLLiveReload: baseURL,
|
BaseURLLiveReload: baseURL,
|
||||||
|
@ -329,11 +332,11 @@ func (c *Config) CompileConfig() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) IsKindEnabled(kind string) bool {
|
func (c *Config) IsKindEnabled(kind string) bool {
|
||||||
return !c.C.DisabledKinds[kind]
|
return !c.C.DisabledKinds[kind]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) IsLangDisabled(lang string) bool {
|
func (c *Config) IsLangDisabled(lang string) bool {
|
||||||
return c.C.DisabledLanguages[lang]
|
return c.C.DisabledLanguages[lang]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,10 +359,17 @@ type ConfigCompiled struct {
|
||||||
// With themes/modules we compute the configuration in multiple passes, and
|
// With themes/modules we compute the configuration in multiple passes, and
|
||||||
// errors with missing output format definitions may resolve itself.
|
// errors with missing output format definitions may resolve itself.
|
||||||
transientErr error
|
transientErr error
|
||||||
|
|
||||||
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// This may be set after the config is compiled.
|
// This may be set after the config is compiled.
|
||||||
func (c *ConfigCompiled) SetMainSections(sections []string) {
|
func (c *ConfigCompiled) SetMainSectionsIfNotSet(sections []string) {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
if len(c.MainSections) > 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
c.MainSections = sections
|
c.MainSections = sections
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -95,7 +95,7 @@ require (
|
||||||
github.com/aws/aws-sdk-go-v2/service/sts v1.7.0 // indirect
|
github.com/aws/aws-sdk-go-v2/service/sts v1.7.0 // indirect
|
||||||
github.com/aws/smithy-go v1.8.0 // indirect
|
github.com/aws/smithy-go v1.8.0 // indirect
|
||||||
github.com/bep/helpers v0.4.0 // indirect
|
github.com/bep/helpers v0.4.0 // indirect
|
||||||
github.com/bep/simplecobra v0.2.0 // indirect
|
github.com/bep/simplecobra v0.3.0 // indirect
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||||
github.com/dlclark/regexp2 v1.7.0 // indirect
|
github.com/dlclark/regexp2 v1.7.0 // indirect
|
||||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -187,6 +187,8 @@ github.com/bep/overlayfs v0.6.0 h1:sgLcq/qtIzbaQNl2TldGXOkHvqeZB025sPvHOQL+DYo=
|
||||||
github.com/bep/overlayfs v0.6.0/go.mod h1:NFjSmn3kCqG7KX2Lmz8qT8VhPPCwZap3UNogXawoQHM=
|
github.com/bep/overlayfs v0.6.0/go.mod h1:NFjSmn3kCqG7KX2Lmz8qT8VhPPCwZap3UNogXawoQHM=
|
||||||
github.com/bep/simplecobra v0.2.0 h1:gfdZZ8QlPBMC9R9DRzUsxExR3FyuNtRkqMJqK98SBno=
|
github.com/bep/simplecobra v0.2.0 h1:gfdZZ8QlPBMC9R9DRzUsxExR3FyuNtRkqMJqK98SBno=
|
||||||
github.com/bep/simplecobra v0.2.0/go.mod h1:EOp6bCKuuHmwA9bQcRC8LcDB60co2Cmht5X4xMIOwf0=
|
github.com/bep/simplecobra v0.2.0/go.mod h1:EOp6bCKuuHmwA9bQcRC8LcDB60co2Cmht5X4xMIOwf0=
|
||||||
|
github.com/bep/simplecobra v0.3.0 h1:BEeb/Q5qdsv5Yy9Go30ynZtAbI+jHV4f5VtNSXvp91E=
|
||||||
|
github.com/bep/simplecobra v0.3.0/go.mod h1:EOp6bCKuuHmwA9bQcRC8LcDB60co2Cmht5X4xMIOwf0=
|
||||||
github.com/bep/tmc v0.5.1 h1:CsQnSC6MsomH64gw0cT5f+EwQDcvZz4AazKunFwTpuI=
|
github.com/bep/tmc v0.5.1 h1:CsQnSC6MsomH64gw0cT5f+EwQDcvZz4AazKunFwTpuI=
|
||||||
github.com/bep/tmc v0.5.1/go.mod h1:tGYHN8fS85aJPhDLgXETVKp+PR382OvFi2+q2GkGsq0=
|
github.com/bep/tmc v0.5.1/go.mod h1:tGYHN8fS85aJPhDLgXETVKp+PR382OvFi2+q2GkGsq0=
|
||||||
github.com/bep/workers v1.0.0 h1:U+H8YmEaBCEaFZBst7GcRVEoqeRC9dzH2dWOwGmOchg=
|
github.com/bep/workers v1.0.0 h1:U+H8YmEaBCEaFZBst7GcRVEoqeRC9dzH2dWOwGmOchg=
|
||||||
|
|
|
@ -743,9 +743,12 @@ func (m *pageMaps) AssemblePages() error {
|
||||||
sw := §ionWalker{m: pm.contentMap}
|
sw := §ionWalker{m: pm.contentMap}
|
||||||
a := sw.applyAggregates()
|
a := sw.applyAggregates()
|
||||||
|
|
||||||
if a.mainSection != "" && len(pm.s.s.conf.C.MainSections) == 0 {
|
if a.mainSection != "" {
|
||||||
|
// Note, sites that have no custom config share a common config struct pointer.
|
||||||
|
// This means that we currently do not support setting different values per language.
|
||||||
|
// The end user can, however, configure this per language if needed.
|
||||||
mainSections := []string{strings.TrimRight(a.mainSection, "/")}
|
mainSections := []string{strings.TrimRight(a.mainSection, "/")}
|
||||||
pm.s.s.conf.C.SetMainSections(mainSections)
|
pm.s.s.conf.C.SetMainSectionsIfNotSet(mainSections)
|
||||||
}
|
}
|
||||||
pm.s.lastmod = a.datesAll.Lastmod()
|
pm.s.lastmod = a.datesAll.Lastmod()
|
||||||
if resource.IsZeroDates(pm.s.home) {
|
if resource.IsZeroDates(pm.s.home) {
|
||||||
|
|
Loading…
Reference in a new issue