From 37a2d5eb4e99b102ba39616917a4c76cb8a142a7 Mon Sep 17 00:00:00 2001 From: abdullah-alaadine <125296663+abdullah-alaadine@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:28:10 +0300 Subject: [PATCH 01/70] magefile: Update isGoLatest to check for Go 1.21 --- magefile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/magefile.go b/magefile.go index 2fc2c7f7515..c8542dad7c4 100644 --- a/magefile.go +++ b/magefile.go @@ -329,7 +329,7 @@ func runCmd(env map[string]string, cmd string, args ...any) error { } func isGoLatest() bool { - return strings.Contains(runtime.Version(), "1.14") + return strings.Contains(runtime.Version(), "1.21") } func isCI() bool { From 274852bcf254230fae30bed4883049ec94462e85 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Wed, 4 Oct 2023 22:25:43 +0300 Subject: [PATCH 02/70] all: Format files with gofmt --- commands/server.go | 2 +- common/paths/url.go | 21 ++++++++++++--------- tpl/math/round.go | 15 ++++++++------- tpl/tplimpl/template_ast_transformers.go | 3 ++- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/commands/server.go b/commands/server.go index 364e59f8ff3..63c09fccd50 100644 --- a/commands/server.go +++ b/commands/server.go @@ -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, diff --git a/common/paths/url.go b/common/paths/url.go index c538d8f2cbe..cefefdf11b7 100644 --- a/common/paths/url.go +++ b/common/paths/url.go @@ -51,9 +51,10 @@ var pb pathBridge // MakePermalink combines base URL with content path to create full URL paths. // Example -// base: http://spf13.com/ -// path: post/how-i-blog -// result: http://spf13.com/post/how-i-blog +// +// base: http://spf13.com/ +// path: post/how-i-blog +// result: http://spf13.com/post/how-i-blog func MakePermalink(host, plink string) *url.URL { base, err := url.Parse(host) if err != nil { @@ -117,17 +118,19 @@ func PrettifyURL(in string) string { // PrettifyURLPath takes a URL path to a content and converts it // to enable pretty URLs. -// /section/name.html becomes /section/name/index.html -// /section/name/ becomes /section/name/index.html -// /section/name/index.html becomes /section/name/index.html +// +// /section/name.html becomes /section/name/index.html +// /section/name/ becomes /section/name/index.html +// /section/name/index.html becomes /section/name/index.html func PrettifyURLPath(in string) string { return prettifyPath(in, pb) } // Uglify does the opposite of PrettifyURLPath(). -// /section/name/index.html becomes /section/name.html -// /section/name/ becomes /section/name.html -// /section/name.html becomes /section/name.html +// +// /section/name/index.html becomes /section/name.html +// /section/name/ becomes /section/name.html +// /section/name.html becomes /section/name.html func Uglify(in string) string { if path.Ext(in) == "" { if len(in) < 2 { diff --git a/tpl/math/round.go b/tpl/math/round.go index 9b33120af9d..e2b5057e0e1 100644 --- a/tpl/math/round.go +++ b/tpl/math/round.go @@ -20,19 +20,20 @@ const ( // Round returns the nearest integer, rounding half away from zero. // // Special cases are: +// // Round(±0) = ±0 // Round(±Inf) = ±Inf // Round(NaN) = NaN func _round(x float64) float64 { // Round is a faster implementation of: // - // func Round(x float64) float64 { - // t := Trunc(x) - // if Abs(x-t) >= 0.5 { - // return t + Copysign(1, x) - // } - // return t - // } + // func Round(x float64) float64 { + // t := Trunc(x) + // if Abs(x-t) >= 0.5 { + // return t + Copysign(1, x) + // } + // return t + // } const ( signMask = 1 << 63 fracMask = 1< Date: Fri, 29 Sep 2023 10:23:08 -0700 Subject: [PATCH 03/70] common/hugo: Add hugo.IsServer and hugo.IsDevelopment And deprecate site.IsServer. Closes #11510 --- common/hugo/hugo.go | 13 +++++++++++++ common/hugo/hugo_test.go | 13 +++++++++++-- docs/content/en/functions/hugo.md | 8 +++++++- docs/content/en/variables/site.md | 3 --- hugolib/site_new.go | 2 ++ resources/page/page_matcher_test.go | 5 +++++ resources/page/site.go | 3 +++ 7 files changed, 41 insertions(+), 6 deletions(-) diff --git a/common/hugo/hugo.go b/common/hugo/hugo.go index c28dd0b5308..1138cf2acb6 100644 --- a/common/hugo/hugo.go +++ b/common/hugo/hugo.go @@ -78,10 +78,22 @@ func (i HugoInfo) Generator() template.HTML { return template.HTML(fmt.Sprintf(``, 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 } @@ -99,6 +111,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 } diff --git a/common/hugo/hugo_test.go b/common/hugo/hugo_test.go index b0279f11137..5b4a6f9ad20 100644 --- a/common/hugo/hugo_test.go +++ b/common/hugo/hugo_test.go @@ -23,7 +23,7 @@ import ( 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()) @@ -38,15 +38,20 @@ 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) } type testConfig struct { environment string + running bool workingDir string } @@ -54,6 +59,10 @@ func (c testConfig) Environment() string { return c.environment } +func (c testConfig) Running() bool { + return c.running +} + func (c testConfig) WorkingDir() string { return c.workingDir } diff --git a/docs/content/en/functions/hugo.md b/docs/content/en/functions/hugo.md index 78d658c6665..5ed1ae85c93 100644 --- a/docs/content/en/functions/hugo.md +++ b/docs/content/en/functions/hugo.md @@ -31,11 +31,17 @@ relatedfuncs: [] `hugo.GoVersion` : (`string`) The Go version used to compile the Hugo binary (e.g., `go1.20.4`). {{< new-in "0.101.0" >}} +`hugo.IsDevelopment` +: (`bool`) Returns `true` if `hugo.Environment` is "development". + `hugo.IsExtended` : (`bool`) Returns `true` if the Hugo binary is the extended version. `hugo.IsProduction` -: (`bool`) Returns `true` if `hugo.Environment` is set to the production environment. +: (`bool`) Returns `true` if `hugo.Environment` is "production". + +`hugo.IsServer` +: (`bool`) Returns `true` if the site is being served with Hugo's built-in server. `hugo.Version` : (`hugo.VersionString`) The current version of the Hugo binary (e.g., `0.112.1`). diff --git a/docs/content/en/variables/site.md b/docs/content/en/variables/site.md index 117f4534603..ced5617b430 100644 --- a/docs/content/en/variables/site.md +++ b/docs/content/en/variables/site.md @@ -47,9 +47,6 @@ All the methods below, e.g. `.Site.RegularPages` can also be reached via the glo .Site.IsMultiLingual : whether there are more than one language in this site. See [Multilingual](/content-management/multilingual/) for more information. -.Site.IsServer -: a boolean to indicate if the site is being served with Hugo's built-in server. See [`hugo server`](/commands/hugo_server/) for more information. - .Site.Language.Lang : the language code of the current locale (e.g., `en`). diff --git a/hugolib/site_new.go b/hugolib/site_new.go index 8abd511c3ec..4db5eeb2871 100644 --- a/hugolib/site_new.go +++ b/hugolib/site_new.go @@ -356,7 +356,9 @@ func newHugoSitesNew(cfg deps.DepsCfg, d *deps.Deps, sites []*Site) (*HugoSites, } // Returns true if we're running in a server. +// Deprecated: use hugo.IsServer instead func (s *Site) IsServer() bool { + helpers.Deprecated(".Site.IsServer", "Use hugo.IsServer instead.", false) return s.conf.Internal.Running } diff --git a/resources/page/page_matcher_test.go b/resources/page/page_matcher_test.go index da47843db98..2108d51c290 100644 --- a/resources/page/page_matcher_test.go +++ b/resources/page/page_matcher_test.go @@ -159,6 +159,7 @@ func TestDecodeCascadeConfig(t *testing.T) { type testConfig struct { environment string + running bool workingDir string } @@ -166,6 +167,10 @@ func (c testConfig) Environment() string { return c.environment } +func (c testConfig) Running() bool { + return c.running +} + func (c testConfig) WorkingDir() string { return c.workingDir } diff --git a/resources/page/site.go b/resources/page/site.go index 6a352ef866c..7b8960fdd3d 100644 --- a/resources/page/site.go +++ b/resources/page/site.go @@ -56,6 +56,7 @@ type Site interface { Home() Page // Returns true if we're running in a server. + // Deprecated: use hugo.IsServer instead IsServer() bool // Returns the server port. @@ -211,6 +212,7 @@ func (s *siteWrapper) Home() Page { return s.s.Home() } +// Deprecated: use hugo.IsServer instead func (s *siteWrapper) IsServer() bool { return s.s.IsServer() } @@ -383,6 +385,7 @@ func (t testSite) GetIdentity() identity.Identity { return identity.KeyValueIdentity{Key: "site", Value: t.l.Lang} } +// Deprecated: use hugo.IsServer instead func (t testSite) IsServer() bool { return false } From 5993afa4c514676297dee907bb22eb1b57031f95 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Thu, 5 Oct 2023 08:47:46 -0700 Subject: [PATCH 04/70] commands: Update message displayed when running CLI from GUI Fixes #11525 --- commands/hugo_windows.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/hugo_windows.go b/commands/hugo_windows.go index e1fd981323b..169c6288f07 100644 --- a/commands/hugo_windows.go +++ b/commands/hugo_windows.go @@ -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.` } From d5d0f420d8e900126d1a733ca7a9d751288b8b26 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Fri, 6 Oct 2023 08:39:43 -0700 Subject: [PATCH 05/70] deps: Update github.com/tdewolff/minify/v2 v2.12.7 => v2.12.9 Fixes #11533 --- go.mod | 4 ++-- go.sum | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 2a045b75e74..29c25cdb4d6 100644 --- a/go.mod +++ b/go.mod @@ -61,8 +61,8 @@ require ( github.com/spf13/cobra v1.7.0 github.com/spf13/fsync v0.9.0 github.com/spf13/pflag v1.0.5 - github.com/tdewolff/minify/v2 v2.12.7 - github.com/tdewolff/parse/v2 v2.6.6 + github.com/tdewolff/minify/v2 v2.12.9 + github.com/tdewolff/parse/v2 v2.6.8 github.com/yuin/goldmark v1.5.6 go.uber.org/atomic v1.11.0 go.uber.org/automaxprocs v1.5.3 diff --git a/go.sum b/go.sum index af083fe5a6c..9cb52433bca 100644 --- a/go.sum +++ b/go.sum @@ -151,7 +151,6 @@ github.com/bep/workers v1.0.0 h1:U+H8YmEaBCEaFZBst7GcRVEoqeRC9dzH2dWOwGmOchg= github.com/bep/workers v1.0.0/go.mod h1:7kIESOB86HfR2379pwoMWNy8B50D7r99fRLUyPSNyCs= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -177,7 +176,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/disintegration/gift v1.2.1 h1:Y005a1X4Z7Uc+0gLpSAsKhWi4qLtsdEcMIbbdvdZ6pc= github.com/disintegration/gift v1.2.1/go.mod h1:Jh2i7f7Q2BM7Ezno3PhfezbR1xpUg9dUg3/RlKGr4HI= -github.com/djherbis/atime v1.1.0/go.mod h1:28OF6Y8s3NQWwacXc5eZTsEsiMzp7LF8MbXE+XJPdBE= github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0= github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= @@ -360,7 +358,6 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0 github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/marekm4/color-extractor v1.2.1 h1:3Zb2tQsn6bITZ8MBVhc33Qn1k5/SEuZ18mrXGUqIwn0= github.com/marekm4/color-extractor v1.2.1/go.mod h1:90VjmiHI6M8ez9eYUaXLdcKnS+BAOp7w+NpwBdkJmpA= -github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= @@ -435,11 +432,10 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tdewolff/minify/v2 v2.12.7 h1:pBzz2tAfz5VghOXiQIsSta6srhmTeinQPjRDHWoumCA= -github.com/tdewolff/minify/v2 v2.12.7/go.mod h1:ZRKTheiOGyLSK8hOZWWv+YoJAECzDivNgAlVYDHp/Ws= -github.com/tdewolff/parse/v2 v2.6.6 h1:Yld+0CrKUJaCV78DL1G2nk3C9lKrxyRTux5aaK/AkDo= -github.com/tdewolff/parse/v2 v2.6.6/go.mod h1:woz0cgbLwFdtbjJu8PIKxhW05KplTFQkOdX78o+Jgrs= -github.com/tdewolff/test v1.0.7/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= +github.com/tdewolff/minify/v2 v2.12.9 h1:dvn5MtmuQ/DFMwqf5j8QhEVpPX6fi3WGImhv8RUB4zA= +github.com/tdewolff/minify/v2 v2.12.9/go.mod h1:qOqdlDfL+7v0/fyymB+OP497nIxJYSvX4MQWA8OoiXU= +github.com/tdewolff/parse/v2 v2.6.8 h1:mhNZXYCx//xG7Yq2e/kVLNZw4YfYmeHbhx+Zc0OvFMA= +github.com/tdewolff/parse/v2 v2.6.8/go.mod h1:XHDhaU6IBgsryfdnpzUXBlT6leW/l25yrFBTEb4eIyM= github.com/tdewolff/test v1.0.9 h1:SswqJCmeN4B+9gEAi/5uqT0qpi1y2/2O47V/1hhGZT0= github.com/tdewolff/test v1.0.9/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= From 1b5f78b6b7335b02b6207a637498c4c8817999d1 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Sun, 8 Oct 2023 16:59:36 -0700 Subject: [PATCH 06/70] markup/tableofcontents: Return template.HTML from .Fragments.ToHTML Closes #11545 --- markup/goldmark/convert_test.go | 8 ++++---- markup/goldmark/toc_test.go | 9 ++++++--- markup/tableofcontents/tableofcontents.go | 5 +++-- markup/tableofcontents/tableofcontents_test.go | 16 ++++++++-------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/markup/goldmark/convert_test.go b/markup/goldmark/convert_test.go index ed791448b93..6d73b301f00 100644 --- a/markup/goldmark/convert_test.go +++ b/markup/goldmark/convert_test.go @@ -109,7 +109,7 @@ LINE1 * Autolink: https://gohugo.io/ * Strikethrough:~~Hi~~ Hello, world! - + ## Table | foo | bar | @@ -137,7 +137,7 @@ That's some text with a footnote.[^1] ## Definition Lists date -: the datetime assigned to this page. +: the datetime assigned to this page. description : the description for the content. @@ -204,8 +204,8 @@ unsafe = true toc, ok := b.(converter.TableOfContentsProvider) c.Assert(ok, qt.Equals, true) - tocHTML := toc.TableOfContents().ToHTML(1, 2, false) - c.Assert(tocHTML, qt.Contains, "TableOfContents") + tocString := string(toc.TableOfContents().ToHTML(1, 2, false)) + c.Assert(tocString, qt.Contains, "TableOfContents") } func TestConvertAutoIDAsciiOnly(t *testing.T) { diff --git a/markup/goldmark/toc_test.go b/markup/goldmark/toc_test.go index f7f7bb7a0b2..1b846877b72 100644 --- a/markup/goldmark/toc_test.go +++ b/markup/goldmark/toc_test.go @@ -62,7 +62,8 @@ And then some. c.Assert(err, qt.IsNil) b, err := conv.Convert(converter.RenderContext{Src: []byte(content), RenderTOC: true, GetRenderer: nopGetRenderer}) c.Assert(err, qt.IsNil) - got := b.(converter.TableOfContentsProvider).TableOfContents().ToHTML(2, 3, false) + tocHTML := b.(converter.TableOfContentsProvider).TableOfContents().ToHTML(2, 3, false) + got := string(tocHTML) c.Assert(got, qt.Equals, `