Skip to content

Commit

Permalink
Merge branch 'master' into all-fix-typos
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Nov 4, 2023
2 parents 3caade5 + cee3a56 commit 72dc6c2
Show file tree
Hide file tree
Showing 389 changed files with 5,987 additions and 3,001 deletions.
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ cd hugo
go install
```

>Note: Some Go tools may not be fully updated to support Go Modules yet. One example would be LiteIDE. Follow [this workaround](https://github.com/visualfc/liteide/issues/986#issuecomment-428117702) for how to continue to work with Hugo below `GOPATH`.
For some convenient build and test targets, you also will want to install Mage:

```bash
Expand Down
29 changes: 11 additions & 18 deletions commands/commandeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (

"github.com/gohugoio/hugo/common/hstrings"
"github.com/gohugoio/hugo/common/htime"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/common/paths"
"github.com/gohugoio/hugo/config"
Expand All @@ -50,9 +51,7 @@ import (
"github.com/spf13/cobra"
)

var (
errHelp = errors.New("help requested")
)
var errHelp = errors.New("help requested")

// Execute executes a command.
func Execute(args []string) error {
Expand Down Expand Up @@ -182,11 +181,9 @@ func (r *rootCommand) ConfigFromConfig(key int32, oldConf *commonConfig) (*commo
cfg: oldConf.cfg,
fs: fs,
}, nil

})

return cc, err

}

func (r *rootCommand) ConfigFromProvider(key int32, cfg config.Provider) (*commonConfig, error) {
Expand All @@ -211,7 +208,7 @@ func (r *rootCommand) ConfigFromProvider(key int32, cfg config.Provider) (*commo
if !cfg.IsSet("workingDir") {
cfg.Set("workingDir", dir)
} else {
if err := os.MkdirAll(cfg.GetString("workingDir"), 0777); err != nil {
if err := os.MkdirAll(cfg.GetString("workingDir"), 0o777); err != nil {
return nil, fmt.Errorf("failed to create workingDir: %w", err)
}
}
Expand Down Expand Up @@ -303,7 +300,6 @@ func (r *rootCommand) ConfigFromProvider(key int32, cfg config.Provider) (*commo
})

return cc, err

}

func (r *rootCommand) HugFromConfig(conf *commonConfig) (*hugolib.HugoSites, error) {
Expand Down Expand Up @@ -348,7 +344,6 @@ func (r *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args
err := b.build()
return err
}()

if err != nil {
return err
}
Expand Down Expand Up @@ -434,26 +429,26 @@ func (r *rootCommand) createLogger(running bool) (loggers.Logger, error) {
}
} else {
if r.verbose {
helpers.Deprecated("--verbose", "use --logLevel info", false)
hugo.Deprecate("--verbose", "use --logLevel info", "v0.114.0")
hugo.Deprecate("--verbose", "use --logLevel info", "v0.114.0")
level = logg.LevelInfo
}

if r.debug {
helpers.Deprecated("--debug", "use --logLevel debug", false)
hugo.Deprecate("--debug", "use --logLevel debug", "v0.114.0")
level = logg.LevelDebug
}
}

optsLogger := loggers.Options{
Distinct: true,
Level: level,
Stdout: r.Out,
Stderr: r.Out,
StoreErrors: running,
DistinctLevel: logg.LevelWarn,
Level: level,
Stdout: r.Out,
Stderr: r.Out,
StoreErrors: running,
}

return loggers.New(optsLogger), nil

}

func (r *rootCommand) Reset() {
Expand Down Expand Up @@ -519,7 +514,6 @@ func applyLocalFlagsBuildConfig(cmd *cobra.Command, r *rootCommand) {
_ = cmd.Flags().SetAnnotation("cacheDir", cobra.BashCompSubdirsInDir, []string{})
cmd.Flags().StringP("contentDir", "c", "", "filesystem path to content directory")
_ = cmd.Flags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"})

}

// Flags needed to do a build (used by hugo and hugo server commands)
Expand Down Expand Up @@ -558,7 +552,6 @@ func applyLocalFlagsBuild(cmd *cobra.Command, r *rootCommand) {
cmd.Flags().StringSlice("disableKinds", []string{}, "disable different kind of pages (home, RSS etc.)")
cmd.Flags().Bool("minify", false, "minify any supported output format (HTML, XML etc.)")
_ = cmd.Flags().SetAnnotation("destination", cobra.BashCompSubdirsInDir, []string{})

}

func (r *rootCommand) timeTrack(start time.Time, name string) {
Expand Down
6 changes: 3 additions & 3 deletions commands/hugo_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func init() {
// This message to show to Windows users if Hugo is opened from explorer.exe
cobra.MousetrapHelpText = `
Hugo is a command-line tool for generating static website.
Hugo is a command-line tool for generating static websites.
You need to open PowerShell and run Hugo from there.
You need to open cmd.exe and run Hugo from there.
Visit https://gohugo.io/ for more information.`
}
1 change: 0 additions & 1 deletion commands/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ Ensure you run this within the root directory of your site.`,
cmd.Flags().StringVarP(&contentType, "kind", "k", "", "content type to create")
cmd.Flags().String("editor", "", "edit new content with this editor, if provided")
cmd.Flags().BoolVarP(&force, "force", "f", false, "overwrite file if it already exists")
cmd.Flags().StringVar(&format, "format", "toml", "preferred file format (toml, yaml or json)")
applyLocalFlagsBuildConfig(cmd, r)

},
Expand Down
2 changes: 1 addition & 1 deletion commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ func (c *serverCommand) serve() error {

for i := range baseURLs {
mu, listener, serverURL, endpoint, err := srv.createEndpoint(i)
var srv *http.Server
var srv *http.Server
if c.tlsCertFile != "" && c.tlsKeyFile != "" {
srv = &http.Server{
Addr: endpoint,
Expand Down
69 changes: 63 additions & 6 deletions common/hugo/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import (
"sort"
"strings"
"sync"
"time"

godartsassv1 "github.com/bep/godartsass"
"github.com/bep/logg"
"github.com/mitchellh/mapstructure"

"time"

"github.com/bep/godartsass/v2"
"github.com/gohugoio/hugo/common/hexec"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/hugofs/files"

"github.com/spf13/afero"
Expand Down Expand Up @@ -78,10 +79,22 @@ func (i HugoInfo) Generator() template.HTML {
return template.HTML(fmt.Sprintf(`<meta name="generator" content="Hugo %s">`, CurrentVersion.String()))
}

// IsDevelopment reports whether the current running environment is "development".
func (i HugoInfo) IsDevelopment() bool {
return i.Environment == EnvironmentDevelopment
}

// IsProduction reports whether the current running environment is "production".
func (i HugoInfo) IsProduction() bool {
return i.Environment == EnvironmentProduction
}

// IsServer reports whether the built-in server is running.
func (i HugoInfo) IsServer() bool {
return i.conf.Running()
}

// IsExtended reports whether the Hugo binary is the extended version.
func (i HugoInfo) IsExtended() bool {
return IsExtended
}
Expand All @@ -99,6 +112,7 @@ func (i HugoInfo) Deps() []*Dependency {
// ConfigProvider represents the config options that are relevant for HugoInfo.
type ConfigProvider interface {
Environment() string
Running() bool
WorkingDir() string
}

Expand Down Expand Up @@ -170,8 +184,10 @@ type buildInfo struct {
*debug.BuildInfo
}

var bInfo *buildInfo
var bInfoInit sync.Once
var (
bInfo *buildInfo
bInfoInit sync.Once
)

func getBuildInfo() *buildInfo {
bInfoInit.Do(func() {
Expand All @@ -198,7 +214,6 @@ func getBuildInfo() *buildInfo {
bInfo.GoArch = s.Value
}
}

})

return bInfo
Expand Down Expand Up @@ -242,7 +257,7 @@ func GetDependencyListNonGo() []string {
}

if dartSass := dartSassVersion(); dartSass.ProtocolVersion != "" {
var dartSassPath = "github.com/sass/dart-sass-embedded"
dartSassPath := "github.com/sass/dart-sass-embedded"
if IsDartSassV2() {
dartSassPath = "github.com/sass/dart-sass"
}
Expand Down Expand Up @@ -333,3 +348,45 @@ var (
func IsDartSassV2() bool {
return !strings.Contains(DartSassBinaryName, "embedded")
}

// Deprecate informs about a deprecation starting at the given version.
//
// A deprecation typically needs a simple change in the template, but doing so will make the template incompatible with older versions.
// Theme maintainers generally want
// 1. No warnings or errors in the console when building a Hugo site.
// 2. Their theme to work for at least the last few Hugo versions.
func Deprecate(item, alternative string, version string) {
level := deprecationLogLevelFromVersion(version)
DeprecateLevel(item, alternative, version, level)
}

// DeprecateLevel informs about a deprecation logging at the given level.
func DeprecateLevel(item, alternative, version string, level logg.Level) {
var msg string
if level == logg.LevelError {
msg = fmt.Sprintf("%s was deprecated in Hugo %s and will be removed in Hugo %s. %s", item, version, CurrentVersion.Next().ReleaseVersion(), alternative)
} else {
msg = fmt.Sprintf("%s was deprecated in Hugo %s and will be removed in a future release. %s", item, version, alternative)
}

loggers.Log().Logger().WithLevel(level).WithField(loggers.FieldNameCmd, "deprecated").Logf(msg)
}

// We ususally do about one minor version a month.
// We want people to run at least the current and previous version without any warnings.
// We want people who don't update Hugo that often to see the warnings and errors before we remove the feature.
func deprecationLogLevelFromVersion(ver string) logg.Level {
from := MustParseVersion(ver)
to := CurrentVersion
minorDiff := to.Minor - from.Minor
switch {
case minorDiff >= 12:
// Start failing the build after about a year.
return logg.LevelError
case minorDiff >= 6:
// Start printing warnings after about six months.
return logg.LevelWarn
default:
return logg.LevelInfo
}
}
28 changes: 26 additions & 2 deletions common/hugo/hugo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import (
"fmt"
"testing"

"github.com/bep/logg"
qt "github.com/frankban/quicktest"
)

func TestHugoInfo(t *testing.T) {
c := qt.New(t)

conf := testConfig{environment: "production", workingDir: "/mywork"}
conf := testConfig{environment: "production", workingDir: "/mywork", running: false}
hugoInfo := NewInfo(conf, nil)

c.Assert(hugoInfo.Version(), qt.Equals, CurrentVersion.Version())
Expand All @@ -38,22 +39,45 @@ func TestHugoInfo(t *testing.T) {
}
c.Assert(hugoInfo.Environment, qt.Equals, "production")
c.Assert(string(hugoInfo.Generator()), qt.Contains, fmt.Sprintf("Hugo %s", hugoInfo.Version()))
c.Assert(hugoInfo.IsDevelopment(), qt.Equals, false)
c.Assert(hugoInfo.IsProduction(), qt.Equals, true)
c.Assert(hugoInfo.IsExtended(), qt.Equals, IsExtended)
c.Assert(hugoInfo.IsServer(), qt.Equals, false)

devHugoInfo := NewInfo(testConfig{environment: "development"}, nil)
devHugoInfo := NewInfo(testConfig{environment: "development", running: true}, nil)
c.Assert(devHugoInfo.IsDevelopment(), qt.Equals, true)
c.Assert(devHugoInfo.IsProduction(), qt.Equals, false)
c.Assert(devHugoInfo.IsServer(), qt.Equals, true)
}

func TestDeprecationLogLevelFromVersion(t *testing.T) {
c := qt.New(t)

c.Assert(deprecationLogLevelFromVersion("0.55.0"), qt.Equals, logg.LevelError)
ver := CurrentVersion
c.Assert(deprecationLogLevelFromVersion(ver.String()), qt.Equals, logg.LevelInfo)
ver.Minor -= 1
c.Assert(deprecationLogLevelFromVersion(ver.String()), qt.Equals, logg.LevelInfo)
ver.Minor -= 6
c.Assert(deprecationLogLevelFromVersion(ver.String()), qt.Equals, logg.LevelWarn)
ver.Minor -= 6
c.Assert(deprecationLogLevelFromVersion(ver.String()), qt.Equals, logg.LevelError)
}

type testConfig struct {
environment string
running bool
workingDir string
}

func (c testConfig) Environment() string {
return c.environment
}

func (c testConfig) Running() bool {
return c.running
}

func (c testConfig) WorkingDir() string {
return c.workingDir
}
9 changes: 5 additions & 4 deletions common/hugo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ func (h VersionString) String() string {

// Compare implements the compare.Comparer interface.
func (h VersionString) Compare(other any) int {
v := MustParseVersion(h.String())
return compareVersions(v, other)
return compareVersions(h.Version(), other)
}

func (h VersionString) Version() Version {
return MustParseVersion(h.String())
}

// Eq implements the compare.Eqer interface.
Expand Down Expand Up @@ -264,7 +267,6 @@ func compareFloatWithVersion(v1 float64, v2 Version) int {

if v1maj > v2.Major {
return 1

}

if v1maj < v2.Major {
Expand All @@ -276,7 +278,6 @@ func compareFloatWithVersion(v1 float64, v2 Version) int {
}

return -1

}

func GoMinorVersion() int {
Expand Down
2 changes: 1 addition & 1 deletion common/hugo/version_current.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package hugo
// This should be the only one.
var CurrentVersion = Version{
Major: 0,
Minor: 120,
Minor: 121,
PatchLevel: 0,
Suffix: "-DEV",
}
Loading

0 comments on commit 72dc6c2

Please sign in to comment.