From d90e37e0c6e812f9913bf256c9c81aa05b7a08aa Mon Sep 17 00:00:00 2001 From: Bjørn Erik Pedersen Date: Wed, 2 Dec 2020 13:23:25 +0100 Subject: all: Format code with gofumpt See https://github.com/mvdan/gofumpt --- hugolib/404_test.go | 2 - hugolib/alias.go | 1 - hugolib/alias_test.go | 6 +- hugolib/breaking_changes_test.go | 11 -- hugolib/cascade_test.go | 11 -- hugolib/case_insensitive_test.go | 2 - hugolib/config.go | 11 -- hugolib/config_test.go | 6 - hugolib/configdir_test.go | 2 - hugolib/content_map.go | 14 +- hugolib/content_map_page.go | 8 -- hugolib/content_map_test.go | 12 -- hugolib/content_render_hooks_test.go | 11 -- hugolib/datafiles_test.go | 13 +- hugolib/disableKinds_test.go | 8 +- hugolib/embedded_shortcodes_test.go | 10 +- hugolib/embedded_templates_test.go | 1 - hugolib/fileInfo.go | 2 - hugolib/filesystems/basefs.go | 18 +-- hugolib/filesystems/basefs_test.go | 4 - hugolib/gitinfo.go | 1 - hugolib/hugo_modules_test.go | 28 +--- hugolib/hugo_sites.go | 15 +-- hugolib/hugo_sites_build.go | 12 -- hugolib/hugo_sites_build_errors_test.go | 10 -- hugolib/hugo_sites_build_test.go | 20 +-- hugolib/hugo_sites_multihost_test.go | 3 +- hugolib/hugo_sites_rebuild_test.go | 8 -- hugolib/hugo_smoke_test.go | 4 +- hugolib/image_test.go | 4 - hugolib/js_test.go | 2 - hugolib/language_content_dir_test.go | 11 +- hugolib/language_test.go | 1 - hugolib/menu_test.go | 10 +- hugolib/multilingual.go | 4 +- hugolib/openapi_test.go | 1 - hugolib/page.go | 11 -- hugolib/page__content.go | 1 - hugolib/page__data.go | 1 - hugolib/page__menus.go | 3 - hugolib/page__meta.go | 9 +- hugolib/page__new.go | 9 +- hugolib/page__output.go | 4 - hugolib/page__paginator.go | 2 - hugolib/page__paths.go | 6 +- hugolib/page__per_output.go | 8 -- hugolib/page__position.go | 1 - hugolib/page__ref.go | 2 - hugolib/page__tree.go | 3 - hugolib/page_kinds.go | 7 +- hugolib/page_permalink_test.go | 3 - hugolib/page_test.go | 39 ++---- hugolib/pagebundler_test.go | 29 +--- hugolib/pagecollections.go | 2 - hugolib/pagecollections_test.go | 18 +-- hugolib/pages_capture.go | 18 +-- hugolib/pages_capture_test.go | 5 +- hugolib/pages_language_merge_test.go | 1 - hugolib/pages_process.go | 2 - hugolib/pages_test.go | 14 +- hugolib/paginator_test.go | 2 - hugolib/paths/paths.go | 3 - hugolib/permalinker.go | 4 +- hugolib/resource_chain_babel_test.go | 1 - hugolib/resource_chain_test.go | 28 +--- hugolib/robotstxt_test.go | 1 - hugolib/shortcode.go | 34 ++--- hugolib/shortcode_test.go | 119 +++++++++-------- hugolib/site.go | 36 ++--- hugolib/siteJSONEncode_test.go | 1 - hugolib/site_benchmark_new_test.go | 230 ++++++++++++++++---------------- hugolib/site_output.go | 3 - hugolib/site_output_test.go | 16 +-- hugolib/site_render.go | 11 +- hugolib/site_sections_test.go | 9 -- hugolib/site_stats_test.go | 4 +- hugolib/site_test.go | 32 +---- hugolib/site_url_test.go | 7 +- hugolib/sitemap_test.go | 7 +- hugolib/taxonomy_test.go | 17 +-- hugolib/template_test.go | 34 +---- hugolib/testhelpers_test.go | 38 ++---- 82 files changed, 305 insertions(+), 817 deletions(-) (limited to 'hugolib') diff --git a/hugolib/404_test.go b/hugolib/404_test.go index cd203a669..383302e0b 100644 --- a/hugolib/404_test.go +++ b/hugolib/404_test.go @@ -57,7 +57,6 @@ Page: /404.html| Data: 1| `) - } func Test404WithBase(t *testing.T) { @@ -77,5 +76,4 @@ Page not found b.AssertFileContent("public/404.html", ` Base: Page not found`) - } diff --git a/hugolib/alias.go b/hugolib/alias.go index 6272b7910..891098c9d 100644 --- a/hugolib/alias.go +++ b/hugolib/alias.go @@ -47,7 +47,6 @@ type aliasPage struct { } func (a aliasHandler) renderAlias(permalink string, p page.Page) (io.Reader, error) { - var templ tpl.Template var found bool diff --git a/hugolib/alias_test.go b/hugolib/alias_test.go index 8f3b756ec..d5ffc06fe 100644 --- a/hugolib/alias_test.go +++ b/hugolib/alias_test.go @@ -38,8 +38,10 @@ outputs: ["HTML", "AMP", "JSON"] For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke. ` -const basicTemplate = "{{.Content}}" -const aliasTemplate = "ALIASTEMPLATE" +const ( + basicTemplate = "{{.Content}}" + aliasTemplate = "ALIASTEMPLATE" +) func TestAlias(t *testing.T) { t.Parallel() diff --git a/hugolib/breaking_changes_test.go b/hugolib/breaking_changes_test.go index c935d6e93..a22bc240f 100644 --- a/hugolib/breaking_changes_test.go +++ b/hugolib/breaking_changes_test.go @@ -21,11 +21,9 @@ import ( ) func Test073(t *testing.T) { - asertDisabledTaxonomyAndTerm := func(b *sitesBuilder, taxonomy, term bool) { b.Assert(b.CheckExists("public/tags/index.html"), qt.Equals, taxonomy) b.Assert(b.CheckExists("public/tags/tag1/index.html"), qt.Equals, term) - } assertOutputTaxonomyAndTerm := func(b *sitesBuilder, taxonomy, term bool) { @@ -48,7 +46,6 @@ func Test073(t *testing.T) { func(err error, out string, b *sitesBuilder) { b.Assert(err, qt.IsNil) assertOutputTaxonomyAndTerm(b, true, true) - }, }, { @@ -60,7 +57,6 @@ taxonomyTerm = ["JSON"] func(err error, out string, b *sitesBuilder) { b.Assert(err, qt.IsNil) assertOutputTaxonomyAndTerm(b, true, false) - }, }, { @@ -72,7 +68,6 @@ taxonomy = ["JSON"] func(err error, out string, b *sitesBuilder) { b.Assert(err, qt.Not(qt.IsNil)) b.Assert(out, qt.Contains, `ignoreErrors = ["error-output-taxonomy"]`) - }, }, { @@ -86,7 +81,6 @@ taxonomy = ["JSON"] func(err error, out string, b *sitesBuilder) { b.Assert(err, qt.IsNil) assertOutputTaxonomyAndTerm(b, true, false) - }, }, { @@ -95,7 +89,6 @@ taxonomy = ["JSON"] func(err error, out string, b *sitesBuilder) { b.Assert(err, qt.IsNil) asertDisabledTaxonomyAndTerm(b, false, false) - }, }, { @@ -104,7 +97,6 @@ taxonomy = ["JSON"] func(err error, out string, b *sitesBuilder) { b.Assert(err, qt.IsNil) asertDisabledTaxonomyAndTerm(b, false, true) - }, }, { @@ -125,7 +117,6 @@ taxonomy = ["JSON"] }, }, } { - t.Run(this.name, func(t *testing.T) { b := newTestSitesBuilder(t).WithConfigFile("toml", this.config) b.WithTemplatesAdded("_default/list.json", "JSON") @@ -135,7 +126,5 @@ taxonomy = ["JSON"] fmt.Println(out) this.assert(err, out, b) }) - } - } diff --git a/hugolib/cascade_test.go b/hugolib/cascade_test.go index a112fe10c..78409a4b1 100644 --- a/hugolib/cascade_test.go +++ b/hugolib/cascade_test.go @@ -51,7 +51,6 @@ func BenchmarkCascade(b *testing.B) { } func TestCascade(t *testing.T) { - allLangs := []string{"en", "nn", "nb", "sv"} langs := allLangs[:3] @@ -101,9 +100,7 @@ func TestCascade(t *testing.T) { // Check cascade into bundled page b.AssertFileContent("public/bundle1/index.html", `Resources: bp1.md|home.png|`) - }) - } func TestCascadeEdit(t *testing.T) { @@ -252,7 +249,6 @@ func newCascadeTestBuilder(t testing.TB, langs []string) *sitesBuilder { metaStr := "---\n" + yamlStr + "\n---" return metaStr - } createLangConfig := func(lang string) string { @@ -290,7 +286,6 @@ defaultContentLanguageInSubDir = false b := newTestSitesBuilder(t).WithConfigFile("toml", config) createContentFiles := func(lang string) { - withContent := func(filenameContent ...string) { for i := 0; i < len(filenameContent); i += 2 { b.WithContent(path.Join(lang, filenameContent[i]), filenameContent[i+1]) @@ -414,7 +409,6 @@ S1|p1:{{ $s1.Params.p1 }}|p2:{{ $s1.Params.p2 }}| b.WithContent("s2/p1/index.md", "---\ntitle: p1_2\n---") return b - } c.Run("slice", func(c *qt.C) { @@ -431,7 +425,6 @@ p2 = "p2" b.Build(BuildCfg{}) b.AssertFileContent("public/index.html", "P1|p1:p1|p2:p2") - }) c.Run("slice with _target", func(c *qt.C) { @@ -456,7 +449,6 @@ kind="section" P1|p1:p1|p2:| S1|p1:|p2:p2| `) - }) c.Run("slice with yaml _target", func(c *qt.C) { @@ -480,7 +472,6 @@ cascade: P1|p1:p1|p2:| S1|p1:|p2:p2| `) - }) c.Run("slice with json _target", func(c *qt.C) { @@ -510,7 +501,5 @@ S1|p1:|p2:p2| P1|p1:p1|p2:| S1|p1:|p2:p2| `) - }) - } diff --git a/hugolib/case_insensitive_test.go b/hugolib/case_insensitive_test.go index 42b9d7ef6..9aa88ab5b 100644 --- a/hugolib/case_insensitive_test.go +++ b/hugolib/case_insensitive_test.go @@ -127,7 +127,6 @@ Partial Site Global: {{ site.Params.COLOR }}|{{ site.Params.COLORS.YELLOW }} `) writeToFs(t, fs, "config.toml", caseMixingSiteConfigTOML) - } func TestCaseInsensitiveConfigurationVariations(t *testing.T) { @@ -184,7 +183,6 @@ Page2: {{ $page2.Params.ColoR }} `) sites, err := NewHugoSites(deps.DepsCfg{Fs: fs, Cfg: cfg}) - if err != nil { t.Fatalf("Failed to create sites: %s", err) } diff --git a/hugolib/config.go b/hugolib/config.go index 9acb7d701..5ef78acf4 100644 --- a/hugolib/config.go +++ b/hugolib/config.go @@ -123,7 +123,6 @@ var ErrNoConfigFile = errors.New("Unable to locate config file or config directo // LoadConfig loads Hugo configuration into a new Viper and then adds // a set of defaults. func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provider) error) (*viper.Viper, []string, error) { - if d.Environment == "" { d.Environment = hugo.EnvironmentProduction } @@ -258,7 +257,6 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid } return v, configFiles, err - } func loadLanguageSettings(cfg config.Provider, oldLangs langs.Languages) error { @@ -310,7 +308,6 @@ func (l configLoader) loadConfig(configName string, v *viper.Viper) (string, err } return filename, nil - } func (l configLoader) wrapFileError(err error, filename string) error { @@ -414,9 +411,7 @@ func (l configLoader) loadConfigFromConfigDir(v *viper.Viper) ([]string, error) } return nil - }) - if err != nil { return nil, err } @@ -427,7 +422,6 @@ func (l configLoader) loadConfigFromConfigDir(v *viper.Viper) ([]string, error) } func (l configLoader) loadModulesConfig(v1 *viper.Viper) (modules.Config, error) { - modConfig, err := modules.DecodeConfig(v1) if err != nil { return modules.Config{}, err @@ -475,7 +469,6 @@ func (l configLoader) collectModules(modConfig modules.Config, v1 *viper.Viper, } return nil - } modulesClient := modules.NewClient(modules.ClientConfig{ @@ -503,11 +496,9 @@ func (l configLoader) collectModules(modConfig modules.Config, v1 *viper.Viper, } return moduleConfig.ActiveModules, configFilenames, err - } func (l configLoader) applyThemeConfig(v1 *viper.Viper, theme modules.Module) error { - const ( paramsKey = "params" languagesKey = "languages" @@ -560,7 +551,6 @@ func (l configLoader) applyThemeConfig(v1 *viper.Viper, theme modules.Module) er } return nil - } func (configLoader) mergeStringMapKeepLeft(rootKey, key string, v1, v2 config.Provider) { @@ -587,7 +577,6 @@ func (configLoader) mergeStringMapKeepLeft(rootKey, key string, v1, v2 config.Pr } func loadDefaultSettingsFor(v *viper.Viper) error { - v.RegisterAlias("indexes", "taxonomies") /* diff --git a/hugolib/config_test.go b/hugolib/config_test.go index e8dce331d..aeeee5fa5 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -43,7 +43,6 @@ func TestLoadConfig(t *testing.T) { c.Assert(err, qt.IsNil) c.Assert(cfg.GetString("paginatePath"), qt.Equals, "side") - } func TestLoadMultiConfig(t *testing.T) { @@ -359,7 +358,6 @@ map[string]interface {}{ }, }, }`, got["menu"]) - } func TestPrivacyConfig(t *testing.T) { @@ -381,7 +379,6 @@ privacyEnhanced = true b.Build(BuildCfg{SkipRender: true}) c.Assert(b.H.Sites[0].Info.Config().Privacy.YouTube.PrivacyEnhanced, qt.Equals, true) - } func TestLoadConfigModules(t *testing.T) { @@ -477,11 +474,9 @@ project n4 ` c.Assert(graphb.String(), qt.Equals, expected) - } func TestLoadConfigWithOsEnvOverrides(t *testing.T) { - c := qt.New(t) baseConfig := ` @@ -534,5 +529,4 @@ quality = 75 c.Assert(cfg.Get("intSlice"), qt.DeepEquals, []interface{}{5, 8, 9}) c.Assert(cfg.Get("params.api_config.api_key"), qt.Equals, "new_key") c.Assert(cfg.Get("params.api_config.another_key"), qt.Equals, "default another_key") - } diff --git a/hugolib/configdir_test.go b/hugolib/configdir_test.go index bc1732fb2..aa1013ec0 100644 --- a/hugolib/configdir_test.go +++ b/hugolib/configdir_test.go @@ -123,7 +123,6 @@ p3 = "p3params_no_production" noMenus := cfg.Get("languages.no.menus.docs") c.Assert(noMenus, qt.Not(qt.IsNil)) c.Assert(len(noMenus.(([]map[string]interface{}))), qt.Equals, 1) - } func TestLoadConfigDirError(t *testing.T) { @@ -150,5 +149,4 @@ baseURL = "https://example.org" fe := herrors.UnwrapErrorWithFileContext(err) c.Assert(fe, qt.Not(qt.IsNil)) c.Assert(fe.Position().Filename, qt.Equals, filepath.FromSlash("config/development/config.toml")) - } diff --git a/hugolib/content_map.go b/hugolib/content_map.go index 652609e26..ca2aa3672 100644 --- a/hugolib/content_map.go +++ b/hugolib/content_map.go @@ -130,7 +130,7 @@ type cmInsertKeyBuilder struct { } func (b cmInsertKeyBuilder) ForPage(s string) *cmInsertKeyBuilder { - //fmt.Println("ForPage:", s, "baseKey:", b.baseKey, "key:", b.key) + // fmt.Println("ForPage:", s, "baseKey:", b.baseKey, "key:", b.key) baseKey := b.baseKey b.baseKey = s @@ -154,7 +154,7 @@ func (b cmInsertKeyBuilder) ForPage(s string) *cmInsertKeyBuilder { } func (b cmInsertKeyBuilder) ForResource(s string) *cmInsertKeyBuilder { - //fmt.Println("ForResource:", s, "baseKey:", b.baseKey, "key:", b.key) + // fmt.Println("ForResource:", s, "baseKey:", b.baseKey, "key:", b.key) baseKey := helpers.AddTrailingSlash(b.baseKey) s = strings.TrimPrefix(s, baseKey) @@ -287,7 +287,6 @@ func (c *contentBundleViewInfo) sections() []string { } return []string{c.name.plural, c.termKey} - } func (c *contentBundleViewInfo) term() string { @@ -393,7 +392,6 @@ func (m *contentMap) AddFilesBundle(header hugofs.FileMetaInfo, resources ...hug } return nil - } func (m *contentMap) CreateMissingNodes() error { @@ -462,7 +460,6 @@ func (m *contentMap) CreateMissingNodes() error { } return nil - } func (m *contentMap) getBundleDir(meta hugofs.FileMeta) string { @@ -611,7 +608,6 @@ func (m *contentMap) deleteBundleMatching(matches func(b *contentNode) bool) { if s != "" { m.resources.Delete(s) } - } // Deletes any empty root section that's not backed by a content file. @@ -686,7 +682,6 @@ func (m *contentMap) splitKey(k string) []string { } return strings.Split(k, "/")[1:] - } func (m *contentMap) testDump() string { @@ -701,7 +696,6 @@ func (m *contentMap) testDump() string { } for i, r := range []*contentTree{m.pages, m.sections} { - r.Walk(func(s string, v interface{}) bool { c := v.(*contentNode) cpToString := func(c *contentNode) string { @@ -730,7 +724,6 @@ func (m *contentMap) testDump() string { m.resources.WalkPrefix(resourcesPrefix, func(s string, v interface{}) bool { sb.WriteString("\t - R: " + filepath.ToSlash((v.(*contentNode).fi.(hugofs.FileMetaInfo)).Meta().Filename()) + "\n") return false - }) return false @@ -738,7 +731,6 @@ func (m *contentMap) testDump() string { } return sb.String() - } type contentMapConfig struct { @@ -787,7 +779,6 @@ func (b *contentNode) rootSection() string { return b.path } return b.path[:firstSlash] - } type contentTree struct { @@ -906,7 +897,6 @@ func (c *contentTree) WalkBelow(prefix string, fn radix.WalkFn) { } return fn(s, v) }) - } func (c *contentTree) getMatch(matches func(b *contentNode) bool) string { diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index e79228ba3..296363359 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -225,7 +225,6 @@ func (m *pageMap) newPageFromContentNode(n *contentNode, parentBucket *pagesMapB } func (m *pageMap) newResource(fim hugofs.FileMetaInfo, owner *pageState) (resource.Resource, error) { - if owner == nil { panic("owner is nil") } @@ -424,7 +423,6 @@ func (m *pageMap) assembleResources(s string, p *pageState, parentBucket *pagesM } func (m *pageMap) assembleSections() error { - var sectionsToDelete []string var err error @@ -508,7 +506,6 @@ func (m *pageMap) assembleSections() error { } func (m *pageMap) assembleTaxonomies() error { - var taxonomiesToDelete []string var err error @@ -565,7 +562,6 @@ func (m *pageMap) assembleTaxonomies() error { } return err - } func (m *pageMap) attachPageToViews(s string, b *contentNode) { @@ -656,7 +652,6 @@ func (m *pageMap) collectSections(query pageMapQuery, fn func(c *contentNode)) e } func (m *pageMap) collectSectionsFn(query pageMapQuery, fn func(s string, c *contentNode) bool) error { - if !strings.HasSuffix(query.Prefix, "/") { query.Prefix += "/" } @@ -957,11 +952,9 @@ func (w *sectionWalker) applyAggregates() *sectionAggregateHandler { return w.walkLevel("/", func() sectionWalkHandler { return §ionAggregateHandler{} }).(*sectionAggregateHandler) - } func (w *sectionWalker) walkLevel(prefix string, createVisitor func() sectionWalkHandler) sectionWalkHandler { - level := strings.Count(prefix, "/") visitor := createVisitor() @@ -1029,7 +1022,6 @@ func (w *sectionWalker) walkLevel(prefix string, createVisitor func() sectionWal }) return visitor - } type viewName struct { diff --git a/hugolib/content_map_test.go b/hugolib/content_map_test.go index 42a69c26b..9d7212735 100644 --- a/hugolib/content_map_test.go +++ b/hugolib/content_map_test.go @@ -43,7 +43,6 @@ func BenchmarkContentMap(b *testing.B) { mfi := fi.(hugofs.FileMetaInfo) return mfi - } createFs := func(fs afero.Fs, lang string) afero.Fs { @@ -55,7 +54,6 @@ func BenchmarkContentMap(b *testing.B) { meta["lang"] = lang meta["path"] = meta.Filename() meta["classifier"] = files.ClassifyContentFile(fi.Name(), meta.GetOpener()) - }) } @@ -87,7 +85,6 @@ func BenchmarkContentMap(b *testing.B) { b.StartTimer() } }) - } func TestContentMap(t *testing.T) { @@ -104,7 +101,6 @@ func TestContentMap(t *testing.T) { mfi := fi.(hugofs.FileMetaInfo) return mfi - } createFs := func(fs afero.Fs, lang string) afero.Fs { @@ -117,12 +113,10 @@ func TestContentMap(t *testing.T) { meta["path"] = meta.Filename() meta["classifier"] = files.ClassifyContentFile(fi.Name(), meta.GetOpener()) meta["translationBaseName"] = helpers.Filename(fi.Name()) - }) } c.Run("AddFiles", func(c *qt.C) { - memfs := afero.NewMemMapFs() fsl := func(lang string) afero.Fs { @@ -254,11 +248,9 @@ func TestContentMap(t *testing.T) { `, qt.Commentf(m.testDump())) - }) c.Run("CreateMissingNodes", func(c *qt.C) { - memfs := afero.NewMemMapFs() fsl := func(lang string) afero.Fs { @@ -297,7 +289,6 @@ func TestContentMap(t *testing.T) { - P: blog/page.md `, qt.Commentf(got)) - }) c.Run("cleanKey", func(c *qt.C) { @@ -309,15 +300,12 @@ func TestContentMap(t *testing.T) { {filepath.FromSlash("/a/b/"), "/a/b"}, {"/a//b/", "/a/b"}, } { - c.Assert(cleanTreeKey(test.in), qt.Equals, test.expected) - } }) } func TestContentMapSite(t *testing.T) { - b := newTestSitesBuilder(t) pageTempl := ` diff --git a/hugolib/content_render_hooks_test.go b/hugolib/content_render_hooks_test.go index 13bfe216a..197581bb6 100644 --- a/hugolib/content_render_hooks_test.go +++ b/hugolib/content_render_hooks_test.go @@ -54,7 +54,6 @@ title: P1 b.Build(BuildCfg{}) b.AssertFileContent("public/p1/index.html", `Link First Link|PARTIAL1_EDITED PARTIAL2_EDITEDEND`) - } func TestRenderHooks(t *testing.T) { @@ -243,7 +242,6 @@ SHORT3| // https://github.com/gohugoio/hugo/issues/7349 b.AssertFileContent("public/docs/p8/index.html", "Docs Level: 1") - } func TestRenderHooksDeleteTemplate(t *testing.T) { @@ -271,7 +269,6 @@ title: P1 b.Build(BuildCfg{}) b.AssertFileContent("public/p1/index.html", `

First Link

`) - } func TestRenderHookAddTemplate(t *testing.T) { @@ -297,11 +294,9 @@ title: P1 b.Build(BuildCfg{}) b.AssertFileContent("public/p1/index.html", `

html-render-link

`) - } func TestRenderHooksRSS(t *testing.T) { - b := newTestSitesBuilder(t) b.WithTemplates("index.html", ` @@ -352,12 +347,10 @@ P3. [I'm an inline-style link](https://www.example.org) P2:

P1. xml-link: https://www.bep.is|

P3:

P3. xml-link: https://www.example.org|

`) - } // https://github.com/gohugoio/hugo/issues/6629 func TestRenderLinkWithMarkupInText(t *testing.T) { - b := newTestSitesBuilder(t) b.WithConfigFile("toml", ` @@ -400,11 +393,9 @@ Image:

Some regular markup.

html-image: image.jpg|Text: Hello
Goodbye|Plain: Hello GoodbyeEND

`) - } func TestRenderString(t *testing.T) { - b := newTestSitesBuilder(t) b.WithTemplates("index.html", ` @@ -433,7 +424,6 @@ RSTART:

Bold Block Markdown

RSTART:italic org mode:REND RSTART:Hook Heading: 2:REND `) - } // https://github.com/gohugoio/hugo/issues/6882 @@ -460,5 +450,4 @@ func TestRenderStringOnListPage(t *testing.T) { } { b.AssertFileContent("public/"+filename, `Hello`) } - } diff --git a/hugolib/datafiles_test.go b/hugolib/datafiles_test.go index 294dc8379..f31024cf5 100644 --- a/hugolib/datafiles_test.go +++ b/hugolib/datafiles_test.go @@ -14,17 +14,16 @@ package hugolib import ( + "fmt" "path/filepath" "reflect" + "runtime" "testing" "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/deps" - "fmt" - "runtime" - qt "github.com/frankban/quicktest" ) @@ -197,7 +196,6 @@ func TestDataDirMultipleSources(t *testing.T) { doTestDataDir(t, dd, expected, "theme", "mytheme") - } // test (and show) the way values from four different sources, @@ -301,7 +299,8 @@ func TestDataDirNestedDirectories(t *testing.T) { expected := map[string]interface{}{ "a": []interface{}{"1", "2", "3"}, - "test1": map[string]interface{}{"20": map[string]interface{}{"05": map[string]interface{}{"b": map[string]interface{}{"artist": "Charlie Parker"}}, "06": map[string]interface{}{"a": map[string]interface{}{"artist": "Michael Brecker"}}}}} + "test1": map[string]interface{}{"20": map[string]interface{}{"05": map[string]interface{}{"b": map[string]interface{}{"artist": "Charlie Parker"}}, "06": map[string]interface{}{"a": map[string]interface{}{"artist": "Michael Brecker"}}}}, + } doTestDataDir(t, dd, expected, "theme", "mytheme") } @@ -331,9 +330,7 @@ func doTestDataDir(t *testing.T, dd dataDir, expected interface{}, configKeyValu } func doTestDataDirImpl(t *testing.T, dd dataDir, expected interface{}, configKeyValues ...interface{}) (err string) { - var ( - cfg, fs = newTestCfg() - ) + cfg, fs := newTestCfg() for i := 0; i < len(configKeyValues); i += 2 { cfg.Set(configKeyValues[i].(string), configKeyValues[i+1]) diff --git a/hugolib/disableKinds_test.go b/hugolib/disableKinds_test.go index 73786c730..87a60d636 100644 --- a/hugolib/disableKinds_test.go +++ b/hugolib/disableKinds_test.go @@ -13,9 +13,8 @@ package hugolib import ( - "testing" - "fmt" + "testing" qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/resources/page" @@ -100,7 +99,6 @@ title: Headless Local Lists Sub b.WithSourceFile("content/sect/no-publishresources/data.json", "DATA") return b - } getPage := func(b *sitesBuilder, ref string) page.Page { @@ -210,7 +208,6 @@ title: Headless Local Lists Sub b.Assert(getPageInPagePages(sect, "/sect/page.md"), qt.Not(qt.IsNil)) b.AssertFileContent("public/sitemap.xml", "sitemap") b.AssertFileContent("public/index.xml", "rss") - }) disableKind = kindRSS @@ -269,7 +266,6 @@ title: Headless Local Lists Sub b.Assert(getPageInSitePages(b, ref), qt.IsNil) sect := getPage(b, "/sect") b.Assert(getPageInPagePages(sect, ref), qt.IsNil) - }) c.Run("Build config, local list", func(c *qt.C) { @@ -356,7 +352,6 @@ home = [ "HTML", "RSS" ] // In Hugo 0.65 we consolidated the code paths and made RSS a pure output format, // but we should make sure to not break existing sites. b.Assert(b.CheckExists("public/index.xml"), qt.Equals, false) - } func TestBundleNoPublishResources(t *testing.T) { @@ -419,5 +414,4 @@ Section: MySection|RelPermalink: |Outputs: 0 b.Assert(b.CheckExists("public/sect/no-render/index.html"), qt.Equals, false) b.Assert(b.CheckExists("public/sect-no-render/index.html"), qt.Equals, false) - } diff --git a/hugolib/embedded_shortcodes_test.go b/hugolib/embedded_shortcodes_test.go index b8acb2d80..3ea1d8ab0 100644 --- a/hugolib/embedded_shortcodes_test.go +++ b/hugolib/embedded_shortcodes_test.go @@ -17,13 +17,12 @@ import ( "encoding/json" "fmt" "html/template" + "path/filepath" "strings" "testing" "github.com/spf13/cast" - "path/filepath" - "github.com/gohugoio/hugo/deps" qt "github.com/frankban/quicktest" @@ -86,12 +85,14 @@ func TestShortcodeHighlight(t *testing.T) { for _, this := range []struct { in, expected string }{ - {`{{< highlight java >}} + { + `{{< highlight java >}} void do(); {{< /highlight >}}`, `(?s)
}}
+		{
+			`{{< highlight java "style=friendly" >}}
 void do();
 {{< /highlight >}}`,
 			`(?s)
`,
@@ -205,7 +206,6 @@ title: Shorty
 
 		th.assertFileContentRegexp(filepath.Join("public", "simple", "index.html"), this.expected)
 	}
-
 }
 
 func TestShortcodeVimeo(t *testing.T) {
diff --git a/hugolib/embedded_templates_test.go b/hugolib/embedded_templates_test.go
index 39a905589..840b98232 100644
--- a/hugolib/embedded_templates_test.go
+++ b/hugolib/embedded_templates_test.go
@@ -76,5 +76,4 @@ title: My Site
 
 
 `)
-
 }
diff --git a/hugolib/fileInfo.go b/hugolib/fileInfo.go
index 4997142a1..fdfd34b16 100644
--- a/hugolib/fileInfo.go
+++ b/hugolib/fileInfo.go
@@ -63,7 +63,6 @@ func (fi *fileInfo) String() string {
 
 // TODO(bep) rename
 func newFileInfo(sp *source.SourceSpec, fi hugofs.FileMetaInfo) (*fileInfo, error) {
-
 	baseFi, err := sp.NewFileInfo(fi)
 	if err != nil {
 		return nil, err
@@ -74,7 +73,6 @@ func newFileInfo(sp *source.SourceSpec, fi hugofs.FileMetaInfo) (*fileInfo, erro
 	}
 
 	return f, nil
-
 }
 
 type bundleDirType int
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go
index ae3807360..e977633c8 100644
--- a/hugolib/filesystems/basefs.go
+++ b/hugolib/filesystems/basefs.go
@@ -16,6 +16,7 @@
 package filesystems
 
 import (
+	"fmt"
 	"io"
 	"os"
 	"path"
@@ -33,8 +34,6 @@ import (
 
 	"github.com/gohugoio/hugo/hugofs"
 
-	"fmt"
-
 	"github.com/gohugoio/hugo/hugolib/paths"
 	"github.com/spf13/afero"
 )
@@ -80,7 +79,7 @@ func (fs *BaseFs) AllDirs() []hugofs.FileMetaInfo {
 		fs.Content.Dirs,
 		fs.Assets.Dirs,
 		fs.Layouts.Dirs,
-		//fs.Resources.Dirs,
+		// fs.Resources.Dirs,
 		fs.StaticDirs,
 	} {
 		dirs = append(dirs, dirSet...)
@@ -160,7 +159,6 @@ func (s *SourceFilesystems) FileSystems() []*SourceFilesystem {
 		s.Archetypes,
 		// TODO(bep) static
 	}
-
 }
 
 // A SourceFilesystem holds the filesystem for a given source type in Hugo (data,
@@ -192,7 +190,6 @@ func (s SourceFilesystems) ContentStaticAssetFs(lang string) afero.Fs {
 
 	base := afero.NewCopyOnWriteFs(s.Assets.Fs, staticFs)
 	return afero.NewCopyOnWriteFs(base, s.Content.Fs)
-
 }
 
 // StaticFs returns the static filesystem for the given language.
@@ -277,7 +274,6 @@ func (s SourceFilesystems) MakeStaticPathRelative(filename string) string {
 
 // MakePathRelative creates a relative path from the given filename.
 func (d *SourceFilesystem) MakePathRelative(filename string) (string, bool) {
-
 	for _, dir := range d.Dirs {
 		meta := dir.(hugofs.FileMetaInfo).Meta()
 		currentPath := meta.Filename()
@@ -416,7 +412,6 @@ func (b *sourceFilesystemsBuilder) newSourceFilesystem(name string, fs afero.Fs,
 }
 
 func (b *sourceFilesystemsBuilder) Build() (*SourceFilesystems, error) {
-
 	if b.theBigFs == nil {
 
 		theBigFs, err := b.createMainOverlayFs(b.p)
@@ -435,7 +430,6 @@ func (b *sourceFilesystemsBuilder) Build() (*SourceFilesystems, error) {
 		dirs := b.theBigFs.overlayDirs[componentID]
 
 		return b.newSourceFilesystem(componentID, afero.NewBasePathFs(b.theBigFs.overlayMounts, componentID), dirs)
-
 	}
 
 	b.theBigFs.finalizeDirs()
@@ -491,11 +485,9 @@ func (b *sourceFilesystemsBuilder) Build() (*SourceFilesystems, error) {
 	}
 
 	return b.result, nil
-
 }
 
 func (b *sourceFilesystemsBuilder) createMainOverlayFs(p *paths.Paths) (*filesystemsCollector, error) {
-
 	var staticFsMap map[string]afero.Fs
 	if b.p.Cfg.GetBool("multihost") {
 		staticFsMap = make(map[string]afero.Fs)
@@ -536,7 +528,6 @@ func (b *sourceFilesystemsBuilder) createMainOverlayFs(p *paths.Paths) (*filesys
 	err := b.createOverlayFs(collector, modsReversed)
 
 	return collector, err
-
 }
 
 func (b *sourceFilesystemsBuilder) isContentMount(mnt modules.Mount) bool {
@@ -550,7 +541,6 @@ func (b *sourceFilesystemsBuilder) isStaticMount(mnt modules.Mount) bool {
 func (b *sourceFilesystemsBuilder) createModFs(
 	collector *filesystemsCollector,
 	md mountsDescriptor) error {
-
 	var (
 		fromTo        []hugofs.RootMapping
 		fromToContent []hugofs.RootMapping
@@ -641,7 +631,6 @@ func (b *sourceFilesystemsBuilder) createModFs(
 			sfs, found := collector.staticPerLanguage[lang]
 			if found {
 				collector.staticPerLanguage[lang] = afero.NewCopyOnWriteFs(sfs, bfs)
-
 			} else {
 				collector.staticPerLanguage[lang] = bfs
 			}
@@ -672,7 +661,6 @@ func (b *sourceFilesystemsBuilder) createModFs(
 	}
 
 	return nil
-
 }
 
 func printFs(fs afero.Fs, path string, w io.Writer) {
@@ -719,7 +707,6 @@ func (c *filesystemsCollector) addDirs(rfs *hugofs.RootMappingFs) {
 	for _, componentFolder := range files.ComponentFolders {
 		c.addDir(rfs, componentFolder)
 	}
-
 }
 
 func (c *filesystemsCollector) addDir(rfs *hugofs.RootMappingFs, componentFolder string) {
@@ -737,7 +724,6 @@ func (c *filesystemsCollector) finalizeDirs() {
 			c.reverseFis(dirs)
 		}
 	})
-
 }
 
 func (c *filesystemsCollector) reverseFis(fis []hugofs.FileMetaInfo) {
diff --git a/hugolib/filesystems/basefs_test.go b/hugolib/filesystems/basefs_test.go
index 2d273ae88..139d0c20e 100644
--- a/hugolib/filesystems/basefs_test.go
+++ b/hugolib/filesystems/basefs_test.go
@@ -274,7 +274,6 @@ func TestRealDirs(t *testing.T) {
 	c.Assert(realDirs[len(realDirs)-1], qt.Equals, filepath.Join(themesDir, "mytheme/assets/scss"))
 
 	c.Assert(bfs.theBigFs, qt.Not(qt.IsNil))
-
 }
 
 func TestStaticFs(t *testing.T) {
@@ -305,7 +304,6 @@ func TestStaticFs(t *testing.T) {
 	sfs := bfs.StaticFs("en")
 	checkFileContent(sfs, "f1.txt", c, "Hugo Rocks!")
 	checkFileContent(sfs, "f2.txt", c, "Hugo Themes Still Rocks!")
-
 }
 
 func TestStaticFsMultiHost(t *testing.T) {
@@ -402,7 +400,6 @@ func TestMakePathRelative(t *testing.T) {
 	c.Assert(makeRel(filepath.Join(workDir, "dist", "d1", "foo.txt")), qt.Equals, filepath.FromSlash("mydist/d1/foo.txt"))
 	c.Assert(makeRel(filepath.Join(workDir, "static", "d2", "foo.txt")), qt.Equals, filepath.FromSlash("d2/foo.txt"))
 	c.Assert(makeRel(filepath.Join(workDir, "dust", "d3", "foo.txt")), qt.Equals, filepath.FromSlash("foo/bar/d3/foo.txt"))
-
 }
 
 func checkFileCount(fs afero.Fs, dirname string, c *qt.C, expected int) {
@@ -412,7 +409,6 @@ func checkFileCount(fs afero.Fs, dirname string, c *qt.C, expected int) {
 }
 
 func checkFileContent(fs afero.Fs, filename string, c *qt.C, expected ...string) {
-
 	b, err := afero.ReadFile(fs, filename)
 	c.Assert(err, qt.IsNil)
 
diff --git a/hugolib/gitinfo.go b/hugolib/gitinfo.go
index 6acc47d17..17717ed52 100644
--- a/hugolib/gitinfo.go
+++ b/hugolib/gitinfo.go
@@ -32,7 +32,6 @@ func (g *gitInfo) forPage(p page.Page) *gitmap.GitInfo {
 	name = strings.TrimPrefix(name, "/")
 
 	return g.repo.Files[name]
-
 }
 
 func newGitInfo(cfg config.Provider) (*gitInfo, error) {
diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go
index b2ab59ef0..f63da5a07 100644
--- a/hugolib/hugo_modules_test.go
+++ b/hugolib/hugo_modules_test.go
@@ -93,11 +93,9 @@ github.com/gohugoio/hugoTestModule2 v0.0.0-20200131160637-9657d7697877/go.mod h1
 `)
 
 		return b, clean
-
 	}
 
 	t.Run("Target in subfolder", func(t *testing.T) {
-
 		b, clean := newTestBuilder(t, "ignoreImports=true")
 		defer clean()
 
@@ -107,7 +105,6 @@ github.com/gohugoio/hugoTestModule2 v0.0.0-20200131160637-9657d7697877/go.mod h1
 	})
 
 	t.Run("Ignore config", func(t *testing.T) {
-
 		b, clean := newTestBuilder(t, "ignoreConfig=true")
 		defer clean()
 
@@ -120,7 +117,6 @@ JS imported in module: |
 	})
 
 	t.Run("Ignore imports", func(t *testing.T) {
-
 		b, clean := newTestBuilder(t, "ignoreImports=true")
 		defer clean()
 
@@ -133,7 +129,6 @@ JS imported in module: |
 	})
 
 	t.Run("Create package.json", func(t *testing.T) {
-
 		b, clean := newTestBuilder(t, "")
 		defer clean()
 
@@ -197,7 +192,6 @@ JS imported in module: |
 	})
 
 	t.Run("Create package.json, no default", func(t *testing.T) {
-
 		b, clean := newTestBuilder(t, "")
 		defer clean()
 
@@ -249,11 +243,9 @@ JS imported in module: |
 
 		// https://github.com/gohugoio/hugo/issues/7690
 		b.AssertFileContent("package.hugo.json", origPackageJSON)
-
 	})
 
 	t.Run("Create package.json, no default, no package.json", func(t *testing.T) {
-
 		b, clean := newTestBuilder(t, "")
 		defer clean()
 
@@ -287,11 +279,8 @@ JS imported in module: |
  "name": "myhugosite",
  "version": "0.1.0"
 }`
-
 		})
-
 	})
-
 }
 
 // TODO(bep) this fails when testmodBuilder is also building ...
@@ -532,7 +521,6 @@ other="Theme C"
 		"i18n theme: Theme C",
 		"i18n theme2: Theme2 D",
 	)
-
 }
 
 func TestModulesIgnoreConfig(t *testing.T) {
@@ -560,7 +548,6 @@ a = "Should Be Ignored!"
 	b.AssertFileContentFn("public/index.html", func(s string) bool {
 		return !strings.Contains(s, "Ignored")
 	})
-
 }
 
 func TestModulesDisabled(t *testing.T) {
@@ -596,7 +583,6 @@ b = "B param"
 	b.AssertFileContentFn("public/index.html", func(s string) bool {
 		return strings.Contains(s, "A param") && !strings.Contains(s, "B param")
 	})
-
 }
 
 func TestModulesIncompatible(t *testing.T) {
@@ -650,7 +636,6 @@ min_version = 0.55.0
 	c := qt.New(t)
 
 	c.Assert(logger.LogCounters().WarnCounter.Count(), qt.Equals, uint64(3))
-
 }
 
 func TestModulesSymlinks(t *testing.T) {
@@ -740,7 +725,8 @@ weight = 2
 		bfs.Content.Fs,
 		bfs.Data.Fs,
 		bfs.Assets.Fs,
-		bfs.I18n.Fs} {
+		bfs.I18n.Fs,
+	} {
 
 		if i != 0 {
 			continue
@@ -756,7 +742,6 @@ weight = 2
 				}
 
 				_, err := fs.Stat(filepath.FromSlash(filename))
-
 				if err != nil {
 					if i > 0 && strings.HasSuffix(filename, "toml") && strings.Contains(err.Error(), "files not supported") {
 						// OK
@@ -803,7 +788,7 @@ title: "My Page"
 
 	b.Build(BuildCfg{})
 
-	//helpers.PrintFs(b.H.Fs.Source, "public", os.Stdout)
+	// helpers.PrintFs(b.H.Fs.Source, "public", os.Stdout)
 
 	b.AssertFileContent("public/mypage/index.html", "Permalink: https://example.org/mypage/")
 }
@@ -929,7 +914,6 @@ title: "Readme Edit"
 	b.AssertFileContent("public/index.html", `
 Readme Edit
 `)
-
 }
 
 func TestMountsPaths(t *testing.T) {
@@ -969,7 +953,6 @@ workingDir = %q
 			clean:      clean,
 			workingDir: workingDir,
 		}
-
 	}
 
 	c.Run("Default", func(c *qt.C) {
@@ -991,7 +974,6 @@ title: P1
 		b.Assert(filepath.ToSlash(f.PathFile()), qt.Equals, "content/blog/p1.md")
 
 		b.Assert(b.H.BaseFs.Layouts.Path(filepath.Join(test.workingDir, "layouts", "_default", "single.html")), qt.Equals, filepath.FromSlash("_default/single.html"))
-
 	})
 
 	c.Run("Mounts", func(c *qt.C) {
@@ -1047,9 +1029,7 @@ title: P1
 		b.Assert(b.H.BaseFs.Layouts.Path(filepath.Join(absShortcodesDir, "myshort.html")), qt.Equals, filepath.FromSlash("shortcodes/myshort.html"))
 		b.Assert(b.H.BaseFs.Content.Path(filepath.Join(subContentDir, "p1.md")), qt.Equals, filepath.FromSlash("blog/sub/p1.md"))
 		b.Assert(b.H.BaseFs.Content.Path(filepath.Join(test.workingDir, "README.md")), qt.Equals, filepath.FromSlash("_index.md"))
-
 	})
-
 }
 
 // https://github.com/gohugoio/hugo/issues/6299
@@ -1074,7 +1054,6 @@ func TestSiteWithGoModButNoModules(t *testing.T) {
 
 	b.WithSourceFile("go.mod", "")
 	b.Build(BuildCfg{})
-
 }
 
 // https://github.com/gohugoio/hugo/issues/6622
@@ -1128,5 +1107,4 @@ P1: {{ $p1.Title }}|{{ $p1.RelPermalink }}|Filename: {{ $p1.File.Filename }}
 	b.Build(BuildCfg{})
 
 	b.AssertFileContent("public/index.html", "P1: Abs|/p1/", "Filename: "+contentFilename)
-
 }
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
index 25ae3dd19..a016cab99 100644
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -295,13 +295,11 @@ func (h *HugoSites) GetContentPage(filename string) page.Page {
 // NewHugoSites creates a new collection of sites given the input sites, building
 // a language configuration based on those.
 func newHugoSites(cfg deps.DepsCfg, sites ...*Site) (*HugoSites, error) {
-
 	if cfg.Language != nil {
 		return nil, errors.New("Cannot provide Language in Cfg when sites are provided")
 	}
 
 	langConfig, err := newMultiLingualFromSites(cfg.Cfg, sites...)
-
 	if err != nil {
 		return nil, errors.Wrap(err, "failed to create language config")
 	}
@@ -437,7 +435,6 @@ func applyDeps(cfg deps.DepsCfg, sites ...*Site) error {
 				s.outputFormatsConfig,
 				s.mediaTypesConfig,
 			)
-
 			if err != nil {
 				return err
 			}
@@ -535,10 +532,7 @@ func (s *Site) withSiteTemplates(withTemplates ...func(templ tpl.TemplateManager
 }
 
 func createSitesFromConfig(cfg deps.DepsCfg) ([]*Site, error) {
-
-	var (
-		sites []*Site
-	)
+	var sites []*Site
 
 	languages := getLanguages(cfg.Cfg)
 
@@ -619,13 +613,11 @@ func (h *HugoSites) createSitesFromConfig(cfg config.Provider) error {
 	depsCfg := deps.DepsCfg{Fs: h.Fs, Cfg: cfg}
 
 	sites, err := createSitesFromConfig(depsCfg)
-
 	if err != nil {
 		return err
 	}
 
 	langConfig, err := newMultiLingualFromSites(depsCfg.Cfg, sites...)
-
 	if err != nil {
 		return err
 	}
@@ -707,7 +699,6 @@ func (cfg *BuildCfg) shouldRender(p *pageState) bool {
 }
 
 func (h *HugoSites) renderCrossSitesSitemap() error {
-
 	if !h.multilingual.enabled() || h.IsMultihost() {
 		return nil
 	}
@@ -750,7 +741,6 @@ func (h *HugoSites) renderCrossSitesRobotsTXT() error {
 		},
 	},
 		output.RobotsTxtFormat)
-
 	if err != nil {
 		return err
 	}
@@ -779,11 +769,9 @@ func (h *HugoSites) removePageByFilename(filename string) {
 		})
 		return nil
 	})
-
 }
 
 func (h *HugoSites) createPageCollections() error {
-
 	allPages := newLazyPagesFactory(func() page.Pages {
 		var pages page.Pages
 		for _, s := range h.Sites {
@@ -1083,7 +1071,6 @@ func (m *contentChangeMap) resolveAndRemove(filename string) (string, bundleDirT
 	}
 
 	return dir, bundleNot
-
 }
 
 func (m *contentChangeMap) addSymbolicLinkMapping(fim hugofs.FileMetaInfo) {
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index bd5c2b661..c1a4ab190 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -44,7 +44,6 @@ import (
 // Build builds all sites. If filesystem events are provided,
 // this is considered to be a potential partial rebuild.
 func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
-
 	if h.running {
 		// Make sure we don't trigger rebuilds in parallel.
 		h.runningMu.Lock()
@@ -70,7 +69,6 @@ func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
 		to <- h.pickOneAndLogTheRest(errors)
 
 		close(to)
-
 	}(errCollector, errs)
 
 	if h.Metrics != nil {
@@ -186,7 +184,6 @@ func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
 	}
 
 	return nil
-
 }
 
 // Build lifecycle methods below.
@@ -242,11 +239,9 @@ func (h *HugoSites) process(config *BuildCfg, init func(config *BuildCfg) error,
 	}
 
 	return firstSite.process(*config)
-
 }
 
 func (h *HugoSites) assemble(bcfg *BuildCfg) error {
-
 	if len(h.Sites) > 1 {
 		// The first is initialized during process; initialize the rest
 		for _, site := range h.Sites[1:] {
@@ -269,7 +264,6 @@ func (h *HugoSites) assemble(bcfg *BuildCfg) error {
 	}
 
 	return nil
-
 }
 
 func (h *HugoSites) render(config *BuildCfg) error {
@@ -327,7 +321,6 @@ func (h *HugoSites) render(config *BuildCfg) error {
 			}
 
 		}
-
 	}
 
 	if !config.SkipRender {
@@ -366,7 +359,6 @@ func (h *HugoSites) postProcess() error {
 					b, err := json.MarshalIndent(jsConfig, "", " ")
 					if err != nil {
 						h.Log.Warnf("Failed to create jsconfig.json: %s", err)
-
 					} else {
 						filename := filepath.Join(assetsDir, "jsconfig.json")
 						if h.running {
@@ -400,7 +392,6 @@ func (h *HugoSites) postProcess() error {
 	g, _ := workers.Start(context.Background())
 
 	handleFile := func(filename string) error {
-
 		content, err := afero.ReadFile(h.BaseFs.PublishFs, filename)
 		if err != nil {
 			return err
@@ -443,7 +434,6 @@ func (h *HugoSites) postProcess() error {
 		}
 
 		return nil
-
 	}
 
 	_ = afero.Walk(h.BaseFs.PublishFs, "", func(path string, info os.FileInfo, err error) error {
@@ -468,7 +458,6 @@ func (h *HugoSites) postProcess() error {
 	}
 
 	return g.Wait()
-
 }
 
 type publishStats struct {
@@ -512,5 +501,4 @@ func (h *HugoSites) writeBuildStats() error {
 	}
 
 	return nil
-
 }
diff --git a/hugolib/hugo_sites_build_errors_test.go b/hugolib/hugo_sites_build_errors_test.go
index d90a8b364..997aae564 100644
--- a/hugolib/hugo_sites_build_errors_test.go
+++ b/hugolib/hugo_sites_build_errors_test.go
@@ -34,11 +34,9 @@ func (t testSiteBuildErrorAsserter) assertErrorMessage(e1, e2 string) {
 	// The error message will contain filenames with OS slashes. Normalize before compare.
 	e1, e2 = filepath.ToSlash(e1), filepath.ToSlash(e2)
 	t.c.Assert(e2, qt.Contains, e1)
-
 }
 
 func TestSiteBuildErrors(t *testing.T) {
-
 	const (
 		yamlcontent = "yamlcontent"
 		tomlcontent = "tomlcontent"
@@ -92,7 +90,6 @@ func TestSiteBuildErrors(t *testing.T) {
 				a.c.Assert(fe.Position().ColumnNumber, qt.Equals, 1)
 				a.c.Assert(fe.ChromaLexer, qt.Equals, "go-html-template")
 				a.assertErrorMessage("\"layouts/foo/single.html:5:1\": parse failed: template: foo/single.html:5: unexpected \"}\" in operand", fe.Error())
-
 			},
 		},
 		{
@@ -107,7 +104,6 @@ func TestSiteBuildErrors(t *testing.T) {
 				a.c.Assert(fe.Position().ColumnNumber, qt.Equals, 14)
 				a.c.Assert(fe.ChromaLexer, qt.Equals, "go-html-template")
 				a.assertErrorMessage("\"layouts/_default/single.html:5:14\": execute of template failed", fe.Error())
-
 			},
 		},
 		{
@@ -122,7 +118,6 @@ func TestSiteBuildErrors(t *testing.T) {
 				a.c.Assert(fe.Position().ColumnNumber, qt.Equals, 14)
 				a.c.Assert(fe.ChromaLexer, qt.Equals, "go-html-template")
 				a.assertErrorMessage("\"layouts/_default/single.html:5:14\": execute of template failed", fe.Error())
-
 			},
 		},
 		{
@@ -184,7 +179,6 @@ func TestSiteBuildErrors(t *testing.T) {
 				fe := a.getFileError(err)
 				a.c.Assert(fe.Position().LineNumber, qt.Equals, 6)
 				a.c.Assert(fe.ErrorContext.ChromaLexer, qt.Equals, "toml")
-
 			},
 		},
 		{
@@ -198,7 +192,6 @@ func TestSiteBuildErrors(t *testing.T) {
 
 				a.c.Assert(fe.Position().LineNumber, qt.Equals, 3)
 				a.c.Assert(fe.ErrorContext.ChromaLexer, qt.Equals, "json")
-
 			},
 		},
 		{
@@ -235,7 +228,6 @@ func TestSiteBuildErrors(t *testing.T) {
 					return content
 				}
 				return test.fileFixer(content)
-
 			}
 
 			b.WithTemplatesAdded("layouts/shortcodes/sc.html", f(shortcode, `SHORTCODE L1
@@ -348,9 +340,7 @@ title: "A page"
 ---
 
 {{< c >}}`)
-
 	}
 
 	b.CreateSites().BuildFail(BuildCfg{})
-
 }
diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go
index 8d0872bd5..4d6a8697c 100644
--- a/hugolib/hugo_sites_build_test.go
+++ b/hugolib/hugo_sites_build_test.go
@@ -2,10 +2,9 @@ package hugolib
 
 import (
 	"fmt"
+	"path/filepath"
 	"strings"
 	"testing"
-
-	"path/filepath"
 	"time"
 
 	qt "github.com/frankban/quicktest"
@@ -199,7 +198,6 @@ p1 = "p1en"
 }
 
 func TestMultiSitesBuild(t *testing.T) {
-
 	for _, config := range []struct {
 		content string
 		suffix  string
@@ -208,7 +206,6 @@ func TestMultiSitesBuild(t *testing.T) {
 		{multiSiteYAMLConfigTemplate, "yml"},
 		{multiSiteJSONConfigTemplate, "json"},
 	} {
-
 		t.Run(config.suffix, func(t *testing.T) {
 			t.Parallel()
 			doTestMultiSitesBuild(t, config.content, config.suffix)
@@ -245,7 +242,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
 
 	c.Assert(enSite.language.Lang, qt.Equals, "en")
 
-	//dumpPages(enSite.RegularPages()...)
+	// dumpPages(enSite.RegularPages()...)
 
 	c.Assert(len(enSite.RegularPages()), qt.Equals, 5)
 	c.Assert(len(enSite.AllPages()), qt.Equals, 32)
@@ -412,7 +409,6 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
 	c.Assert(logoEn, qt.Not(qt.IsNil))
 	b.AssertFileContent("public/en/bundles/b1/index.html", "Resources: image/png: /blog/en/bundles/b1/logo.png")
 	b.AssertFileContent("public/en/bundles/b1/logo.png", "PNG Data")
-
 }
 
 func TestMultiSitesRebuild(t *testing.T) {
@@ -470,7 +466,6 @@ func TestMultiSitesRebuild(t *testing.T) {
 			[]fsnotify.Event{{Name: filepath.FromSlash("content/sect/doc2.en.md"), Op: fsnotify.Remove}},
 			func(t *testing.T) {
 				c.Assert(len(enSite.RegularPages()), qt.Equals, 4, qt.Commentf("1 en removed"))
-
 			},
 		},
 		{
@@ -508,7 +503,6 @@ func TestMultiSitesRebuild(t *testing.T) {
 				c.Assert(len(enSite.RegularPages()), qt.Equals, 6)
 				doc1 := readDestination(t, fs, "public/en/sect/doc1-slug/index.html")
 				c.Assert(strings.Contains(doc1, "CHANGED"), qt.Equals, true)
-
 			},
 		},
 		// Rename a file
@@ -527,7 +521,8 @@ func TestMultiSitesRebuild(t *testing.T) {
 				c.Assert(enSite.RegularPages()[1].Title(), qt.Equals, "new_en_1")
 				rendered := readDestination(t, fs, "public/en/new1renamed/index.html")
 				c.Assert(rendered, qt.Contains, "new_en_1")
-			}},
+			},
+		},
 		{
 			// Change a template
 			func(t *testing.T) {
@@ -567,7 +562,6 @@ func TestMultiSitesRebuild(t *testing.T) {
 				c.Assert(homeEn, qt.Not(qt.IsNil))
 				c.Assert(len(homeEn.Translations()), qt.Equals, 3)
 				c.Assert(homeEn.Translations()[0].Language().Lang, qt.Equals, "fr")
-
 			},
 		},
 		// Change a shortcode
@@ -593,14 +587,12 @@ func TestMultiSitesRebuild(t *testing.T) {
 		}
 
 		err := b.H.Build(BuildCfg{}, this.events...)
-
 		if err != nil {
 			t.Fatalf("[%d] Failed to rebuild sites: %s", i, err)
 		}
 
 		this.assertFunc(t)
 	}
-
 }
 
 // https://github.com/gohugoio/hugo/issues/4706
@@ -762,7 +754,6 @@ Title: My categories
 `)
 
 	for _, lang := range []string{"en", "nn"} {
-
 		b.WithContent(lang+"/mysection/page.md", `
 ---
 Title: My Page
@@ -770,7 +761,6 @@ categories: ["mycat"]
 ---
 
 `)
-
 	}
 
 	b.Build(BuildCfg{})
@@ -781,7 +771,6 @@ categories: ["mycat"]
 		"/categories",
 		"/categories/mycat",
 	} {
-
 		t.Run(path, func(t *testing.T) {
 			c := qt.New(t)
 
@@ -802,7 +791,6 @@ categories: ["mycat"]
 			c.Assert(len(m1), qt.Equals, 1)
 			c.Assert(len(m2), qt.Equals, 1)
 		})
-
 	}
 }
 
diff --git a/hugolib/hugo_sites_multihost_test.go b/hugolib/hugo_sites_multihost_test.go
index 4fe496042..b008fbdef 100644
--- a/hugolib/hugo_sites_multihost_test.go
+++ b/hugolib/hugo_sites_multihost_test.go
@@ -13,7 +13,7 @@ func TestMultihosts(t *testing.T) {
 
 	c := qt.New(t)
 
-	var configTemplate = `
+	configTemplate := `
 paginate = 1
 disablePathToLower = true
 defaultContentLanguage = "fr"
@@ -116,5 +116,4 @@ languageName = "Nynorsk"
 	c.Assert(len(bundleFr.Resources()), qt.Equals, 1)
 	b.AssertFileContent("public/fr/bundles/b1/logo.png", "PNG Data")
 	b.AssertFileContent("public/fr/bundles/b1/index.html", " image/png: /bundles/b1/logo.png")
-
 }
diff --git a/hugolib/hugo_sites_rebuild_test.go b/hugolib/hugo_sites_rebuild_test.go
index 4c4741385..d312d2199 100644
--- a/hugolib/hugo_sites_rebuild_test.go
+++ b/hugolib/hugo_sites_rebuild_test.go
@@ -20,7 +20,6 @@ import (
 )
 
 func TestSitesRebuild(t *testing.T) {
-
 	configFile := `
 baseURL = "https://example.com"
 title = "Rebuild this"
@@ -142,7 +141,6 @@ Data Inline: Rocks!
 		b.AssertFileContent("public/index.html", `
 Data: Rules!
 Data Inline: Rules!`)
-
 	})
 
 	// https://github.com/gohugoio/hugo/issues/6968
@@ -165,7 +163,6 @@ Data Inline: Rules!`)
 		b.Build(BuildCfg{testCounters: counters})
 
 		b.Assert(int(counters.contentRenderCounter), qt.Equals, 0)
-
 	})
 
 	t.Run("Page.Render, edit baseof", func(t *testing.T) {
@@ -190,7 +187,6 @@ prender: {{ $p.Title }}|{{ $p.Content }}
 		b.AssertFileContent("public/index.html", `
 Render /prender/: Baseof Edited:Single Main: Page 1|Mypartial1: Mypartial1:END
 `)
-
 	})
 
 	t.Run("Page.Render, edit partial in baseof", func(t *testing.T) {
@@ -215,7 +211,6 @@ prender: {{ $p.Title }}|{{ $p.Content }}
 		b.AssertFileContent("public/index.html", `
 Render /prender/: Baseof:Single Main: Page 1|Mypartial1: Mypartial1|Mypartial3: Mypartial3 Edited:END
 `)
-
 	})
 
 	t.Run("Edit RSS shortcode", func(t *testing.T) {
@@ -255,9 +250,7 @@ Output Shortcode AMP
 		b.AssertFileContent("public/amp/output/index.html", `
 Output Shortcode AMP Edited
 `)
-
 	})
-
 }
 
 // Issues #7623 #7625
@@ -320,5 +313,4 @@ P6 content
 P5 changed content
 P6 changed content
 `)
-
 }
diff --git a/hugolib/hugo_smoke_test.go b/hugolib/hugo_smoke_test.go
index 5aa508290..798504f0d 100644
--- a/hugolib/hugo_smoke_test.go
+++ b/hugolib/hugo_smoke_test.go
@@ -122,7 +122,7 @@ Footnotes:
 
 `
 
-	var pageContentAutoSummary = strings.Replace(pageContentAndSummaryDivider, "", "", 1)
+	pageContentAutoSummary := strings.Replace(pageContentAndSummaryDivider, "", "", 1)
 
 	b := newTestSitesBuilder(t).WithConfigFile("toml", configFile)
 	b.WithTemplatesAdded("shortcodes/markdown-shortcode.html", `
@@ -282,12 +282,10 @@ Some **Markdown** in JSON shortcode.
 	// Markdown vs shortcodes
 	// Check that all footnotes are grouped (even those from inside the shortcode)
 	b.AssertFileContentRe("public/blog/markyshort/index.html", `Footnotes:.*
    .*Fn 1.*Fn 2.*Fn 3.*
`) - } // https://github.com/golang/go/issues/30286 func TestDataRace(t *testing.T) { - const page = ` --- title: "The Page" diff --git a/hugolib/image_test.go b/hugolib/image_test.go index 84d43f5e9..9f0967414 100644 --- a/hugolib/image_test.go +++ b/hugolib/image_test.go @@ -38,7 +38,6 @@ func TestImageOps(t *testing.T) { defer clean() newBuilder := func(timeout interface{}) *sitesBuilder { - v := viper.New() v.Set("workingDir", workDir) v.Set("baseURL", "https://example.org") @@ -169,11 +168,9 @@ IMG SHORTCODE: /images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_129x239_r b.Build(BuildCfg{}) assertImages() - } func TestImageResizeMultilingual(t *testing.T) { - b := newTestSitesBuilder(t).WithConfigFile("toml", ` baseURL="https://example.org" defaultContentLanguage = "en" @@ -247,5 +244,4 @@ SUNSET2: {{ $resized2.RelPermalink }}/{{ $resized2.Width }}/Lat: {{ $resized2.Ex // TODO(bep) add this as a default assertion after Build()? b.AssertNoDuplicateWrites() - } diff --git a/hugolib/js_test.go b/hugolib/js_test.go index b4f1d2157..fbbd335b3 100644 --- a/hugolib/js_test.go +++ b/hugolib/js_test.go @@ -136,7 +136,6 @@ if (hasSpace.test(string)) var React = __toModule(require("react")); function greeter(person) { `) - } func TestJSBuild(t *testing.T) { @@ -208,5 +207,4 @@ Hello3 from mod2. Date from date-fns: ${today} Hello from lib in the main project Hello5 from mod2. var myparam = "Hugo Rocks!";`) - } diff --git a/hugolib/language_content_dir_test.go b/hugolib/language_content_dir_test.go index 0d1033c1f..117fdfb14 100644 --- a/hugolib/language_content_dir_test.go +++ b/hugolib/language_content_dir_test.go @@ -102,7 +102,7 @@ Content. var contentFiles []string section := "sect" - var contentRoot = func(lang string) string { + contentRoot := func(lang string) string { switch lang { case "nn": return "content/norsk" @@ -111,10 +111,9 @@ Content. default: return "content/main" } - } - var contentSectionRoot = func(lang string) string { + contentSectionRoot := func(lang string) string { return contentRoot(lang) + "/" + section } @@ -215,7 +214,7 @@ Content. err := b.BuildE(BuildCfg{}) - //dumpPages(b.H.Sites[1].RegularPages()...) + // dumpPages(b.H.Sites[1].RegularPages()...) c.Assert(err, qt.IsNil) @@ -228,7 +227,7 @@ Content. b.AssertFileContent("/my/project/public/en/mystatic/file1.yaml", "en") b.AssertFileContent("/my/project/public/nn/mystatic/file1.yaml", "nn") - //dumpPages(nnSite.RegularPages()...) + // dumpPages(nnSite.RegularPages()...) c.Assert(len(nnSite.RegularPages()), qt.Equals, 12) c.Assert(len(enSite.RegularPages()), qt.Equals, 13) @@ -317,7 +316,6 @@ Content. c.Assert(len(nnSect.Pages()), qt.Equals, 12) nnHome, _ := nnSite.Info.Home() c.Assert(nnHome.RelPermalink(), qt.Equals, "/nn/") - } // https://github.com/gohugoio/hugo/issues/6463 @@ -404,5 +402,4 @@ Page: /fr/event/page1/|ev-fr1 Page: /fr/event/page2/|ev-fr2 Page: /fr/other/page1/|other-fr1 Page: /fr/other/page2/|other-fr2`) - } diff --git a/hugolib/language_test.go b/hugolib/language_test.go index 9c3e434c2..16dcbcb03 100644 --- a/hugolib/language_test.go +++ b/hugolib/language_test.go @@ -24,7 +24,6 @@ import ( ) func TestI18n(t *testing.T) { - c := qt.New(t) //https://github.com/gohugoio/hugo/issues/7804 diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go index cfb4b954b..8717fa7db 100644 --- a/hugolib/menu_test.go +++ b/hugolib/menu_test.go @@ -14,9 +14,8 @@ package hugolib import ( - "testing" - "fmt" + "testing" qt "github.com/frankban/quicktest" ) @@ -104,11 +103,9 @@ Menu Main: {{ partial "menu.html" (dict "page" . "menu" "main") }}`, "/sect1/|Section One|Section One|100|-|-|"+ "/sect2/|Sect2s|Sect2s|0|-|HasMenuCurrent|"+ "/sect3/|Sect3s|Sect3s|0|-|-|") - } func TestMenuFrontMatter(t *testing.T) { - b := newTestSitesBuilder(t).WithSimpleConfigFile() b.WithTemplatesAdded("index.html", ` @@ -155,12 +152,10 @@ menu: "Main|P1: /blog/page1/", "Other|P2: /blog/page2/", ) - } // https://github.com/gohugoio/hugo/issues/5849 func TestMenuPageMultipleOutputFormats(t *testing.T) { - config := ` baseURL = "https://example.com" @@ -219,7 +214,6 @@ menu: "main" // https://github.com/gohugoio/hugo/issues/5989 func TestMenuPageSortByDate(t *testing.T) { - b := newTestSitesBuilder(t).WithSimpleConfigFile() b.WithContent("blog/a.md", ` @@ -269,7 +263,6 @@ menu: } func TestMenuParams(t *testing.T) { - b := newTestSitesBuilder(t).WithSimpleConfigFile() b.WithTemplatesAdded("index.html", ` @@ -315,5 +308,4 @@ menu: "Main|P1: /blog/page1/|map[]", "Main|P2: /blog/page2/|map[]", ) - } diff --git a/hugolib/multilingual.go b/hugolib/multilingual.go index 9b34c75e6..baebc9e0f 100644 --- a/hugolib/multilingual.go +++ b/hugolib/multilingual.go @@ -14,9 +14,8 @@ package hugolib import ( - "sync" - "errors" + "sync" "github.com/gohugoio/hugo/langs" @@ -69,7 +68,6 @@ func newMultiLingualFromSites(cfg config.Provider, sites ...*Site) (*Multilingua } return &Multilingual{Languages: languages, DefaultLang: langs.NewLanguage(defaultLang, cfg)}, nil - } func (ml *Multilingual) enabled() bool { diff --git a/hugolib/openapi_test.go b/hugolib/openapi_test.go index 82f080311..3f1bc400d 100644 --- a/hugolib/openapi_test.go +++ b/hugolib/openapi_test.go @@ -65,5 +65,4 @@ API: {{ $api.Info.Title | safeHTML }} b.Build(BuildCfg{}) b.AssertFileContent("public/index.html", `API: Hugo API`) - } diff --git a/hugolib/page.go b/hugolib/page.go index fac3f3492..47aeb6e9a 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -243,7 +243,6 @@ func (p *pageState) RegularPages() page.Pages { } p.regularPages = pages - }) return p.regularPages @@ -358,11 +357,9 @@ func (p *pageState) TranslationKey() string { } else if p.IsNode() { p.translationKey = path.Join(p.Kind(), p.SectionsPath()) } - }) return p.translationKey - } // AllTranslations returns all translations, including the current Page. @@ -469,7 +466,6 @@ func (p *pageState) getLayoutDescriptor() output.LayoutDescriptor { }) return p.layoutDescriptor - } func (p *pageState) resolveTemplate(layouts ...string) (tpl.Template, bool, error) { @@ -500,7 +496,6 @@ func (p *pageState) initOutputFormat(isRenderingSite bool, idx int) error { } return nil - } // Must be run after the site section tree etc. is built and ready. @@ -546,7 +541,6 @@ func (p *pageState) renderResources() (err error) { for _, i := range toBeDeleted { p.deleteResource(i) } - }) return @@ -681,7 +675,6 @@ func (p *pageState) Render(layout ...string) (template.HTML, error) { return "", p.wrapError(errors.Wrapf(err, "failed to execute template %q v", layout)) } return template.HTML(res), nil - } // wrapError adds some more context to the given error if possible/needed @@ -714,7 +707,6 @@ func (p *pageState) getContentConverter() converter.Converter { markup = "markdown" } p.m.contentConverter, err = p.m.newContentConverter(p, markup, p.m.renderingConfigOverrides) - }) if err != nil { @@ -724,7 +716,6 @@ func (p *pageState) getContentConverter() converter.Converter { } func (p *pageState) mapContent(bucket *pagesMapBucket, meta *pageMeta) error { - s := p.shortcodeState rn := &pageContentMap{ @@ -893,7 +884,6 @@ func (p *pageState) parseError(err error, input []byte, offset int) error { } pos := p.posFromInput(input, offset) return herrors.NewFileError("md", -1, pos.LineNumber, pos.ColumnNumber, err) - } func (p *pageState) pathOrTitle() string { @@ -955,7 +945,6 @@ func (p *pageState) shiftToOutputFormat(isRenderingSite bool, idx int) error { if isRenderingSite { cp := p.pageOutput.cp if cp == nil { - // Look for content to reuse. for i := 0; i < len(p.pageOutputs); i++ { if i == idx { diff --git a/hugolib/page__content.go b/hugolib/page__content.go index 91f26dc18..c08ac67af 100644 --- a/hugolib/page__content.go +++ b/hugolib/page__content.go @@ -65,7 +65,6 @@ func (p pageContent) contentToRender(renderedShortcodes map[string]string) []byt // Insert the placeholder so we can insert the content after // markdown processing. c = append(c, []byte(v.placeholder)...) - } default: panic(fmt.Sprintf("unknown item type %T", it)) diff --git a/hugolib/page__data.go b/hugolib/page__data.go index 9fc97f8f6..7ab668503 100644 --- a/hugolib/page__data.go +++ b/hugolib/page__data.go @@ -60,7 +60,6 @@ func (p *pageData) Data() interface{} { // Assign the function to the map to make sure it is lazily initialized p.data["pages"] = p.Pages - }) return p.data diff --git a/hugolib/page__menus.go b/hugolib/page__menus.go index 7b0ef0e43..e64ffa2c9 100644 --- a/hugolib/page__menus.go +++ b/hugolib/page__menus.go @@ -51,7 +51,6 @@ func (p *pageMenus) Menus() navigation.PageMenus { func (p *pageMenus) menus() navigation.PageMenus { p.init() return p.pm - } func (p *pageMenus) init() { @@ -68,7 +67,5 @@ func (p *pageMenus) init() { if err != nil { p.p.s.Log.Errorln(p.p.wrapError(err)) } - }) - } diff --git a/hugolib/page__meta.go b/hugolib/page__meta.go index d23718315..b14938655 100644 --- a/hugolib/page__meta.go +++ b/hugolib/page__meta.go @@ -238,7 +238,6 @@ func (p *pageMeta) Path() string { // RelatedKeywords implements the related.Document interface needed for fast page searches. func (p *pageMeta) RelatedKeywords(cfg related.IndexConfig) ([]related.Keyword, error) { - v, err := p.Param(cfg.Name) if err != nil { return nil, err @@ -269,7 +268,6 @@ func (p *pageMeta) Section() string { } panic("invalid page state") - } func (p *pageMeta) SectionsEntries() []string { @@ -368,9 +366,8 @@ func (pm *pageMeta) setMetadata(parentBucket *pagesMapBucket, p *pageState, fron } } else { p.bucket.cascade = map[page.PageMatcher]maps.Params{ - page.PageMatcher{}: maps.ToStringMap(cv), + {}: maps.ToStringMap(cv), } - } } } @@ -486,7 +483,6 @@ func (pm *pageMeta) setMetadata(parentBucket *pagesMapBucket, p *pageState, fron // this may get its language path added twice. // TODO(bep) eventually remove this. p.s.Log.Warnf(`Front matter in %q with the url %q with no leading / has what looks like the language prefix added. In Hugo 0.55 we added support for page relative URLs in front matter, no language prefix needed. Check the URL and consider to either add a leading / or remove the language prefix.`, p.pathOrTitle(), url) - } } pm.urlPaths.URL = url @@ -661,7 +657,6 @@ func (p *pageMeta) noListAlways() bool { } func (p *pageMeta) getListFilter(local bool) contentTreeNodeCallback { - return newContentTreeFilter(func(n *contentNode) bool { if n == nil { return true @@ -763,7 +758,6 @@ func (p *pageMeta) applyDefaultValues(n *contentNode) error { } return nil - } func (p *pageMeta) newContentConverter(ps *pageState, markup string, renderingConfigOverrides map[string]interface{}) (converter.Converter, error) { @@ -791,7 +785,6 @@ func (p *pageMeta) newContentConverter(ps *pageState, markup string, renderingCo ConfigOverrides: renderingConfigOverrides, }, ) - if err != nil { return converter.NopConverter, err } diff --git a/hugolib/page__new.go b/hugolib/page__new.go index 9ec089f27..b37631477 100644 --- a/hugolib/page__new.go +++ b/hugolib/page__new.go @@ -90,7 +90,6 @@ func newPageBase(metaProvider *pageMeta) (*pageState, error) { ps.AlternativeOutputFormatsProvider = ps return ps, nil - } func newPageBucket(p *pageState) *pagesMapBucket { @@ -102,7 +101,6 @@ func newPageFromMeta( parentBucket *pagesMapBucket, meta map[string]interface{}, metaProvider *pageMeta) (*pageState, error) { - if metaProvider.f == nil { metaProvider.f = page.NewZeroFile(metaProvider.s.DistinctWarningLog) } @@ -170,11 +168,9 @@ func newPageFromMeta( } return nil, nil - }) return ps, err - } // Used by the legacy 404, sitemap and robots.txt rendering @@ -182,7 +178,6 @@ func newPageStandalone(m *pageMeta, f output.Format) (*pageState, error) { m.configuredOutputFormats = output.Formats{f} m.standalone = true p, err := newPageFromMeta(nil, nil, nil, m) - if err != nil { return nil, err } @@ -192,7 +187,6 @@ func newPageStandalone(m *pageMeta, f output.Format) (*pageState, error) { } return p, nil - } type pageDeprecatedWarning struct { @@ -205,6 +199,7 @@ func (p *pageDeprecatedWarning) LanguagePrefix() string { return p.p.s.Info.Lang func (p *pageDeprecatedWarning) GetParam(key string) interface{} { return p.p.m.params[strings.ToLower(key)] } + func (p *pageDeprecatedWarning) RSSLink() template.URL { f := p.p.OutputFormats().Get("RSS") if f == nil { @@ -212,6 +207,7 @@ func (p *pageDeprecatedWarning) RSSLink() template.URL { } return template.URL(f.Permalink()) } + func (p *pageDeprecatedWarning) URL() string { if p.p.IsPage() && p.p.m.urlPaths.URL != "" { // This is the url set in front matter @@ -219,5 +215,4 @@ func (p *pageDeprecatedWarning) URL() string { } // Fall back to the relative permalink. return p.p.RelPermalink() - } diff --git a/hugolib/page__output.go b/hugolib/page__output.go index 1792e8d6a..a3235db49 100644 --- a/hugolib/page__output.go +++ b/hugolib/page__output.go @@ -25,7 +25,6 @@ func newPageOutput( pp pagePaths, f output.Format, render bool) *pageOutput { - var targetPathsProvider targetPathsHolder var linksProvider resource.ResourceLinksProvider @@ -65,7 +64,6 @@ func newPageOutput( } return po - } // We create a pageOutput for every output format combination, even if this @@ -118,7 +116,6 @@ func (o *pageOutput) initRenderHooks() error { }) return initErr - } func (p *pageOutput) initContentProvider(cp *pageContentOutput) { @@ -134,5 +131,4 @@ func (p *pageOutput) enablePlaceholders() { if p.cp != nil { p.cp.enablePlaceholders() } - } diff --git a/hugolib/page__paginator.go b/hugolib/page__paginator.go index 5948735d1..a5a3f07a6 100644 --- a/hugolib/page__paginator.go +++ b/hugolib/page__paginator.go @@ -59,7 +59,6 @@ func (p *pagePaginator) Paginate(seq interface{}, options ...interface{}) (*page } p.current = paginator.Pagers()[0] - }) if initErr != nil { @@ -102,7 +101,6 @@ func (p *pagePaginator) Paginator(options ...interface{}) (*page.Pager, error) { } p.current = paginator.Pagers()[0] - }) if initErr != nil { diff --git a/hugolib/page__paths.go b/hugolib/page__paths.go index d41b7c2bc..947cdde9d 100644 --- a/hugolib/page__paths.go +++ b/hugolib/page__paths.go @@ -26,7 +26,6 @@ func newPagePaths( s *Site, p page.Page, pm *pageMeta) (pagePaths, error) { - targetPathDescriptor, err := createTargetPathDescriptor(s, p, pm) if err != nil { return pagePaths{}, err @@ -71,7 +70,8 @@ func newPagePaths( targets[f.Name] = targetPathsHolder{ paths: paths, - OutputFormat: pageOutputFormats[permalinksIndex]} + OutputFormat: pageOutputFormats[permalinksIndex], + } } @@ -86,7 +86,6 @@ func newPagePaths( targetPaths: targets, targetPathDescriptor: targetPathDescriptor, }, nil - } type pagePaths struct { @@ -163,5 +162,4 @@ func createTargetPathDescriptor(s *Site, p page.Page, pm *pageMeta) (page.Target } return desc, nil - } diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go index aceeaeb36..dfc82c062 100644 --- a/hugolib/page__per_output.go +++ b/hugolib/page__per_output.go @@ -65,7 +65,6 @@ var ( var pageContentOutputDependenciesID = identity.KeyValueIdentity{Key: "pageOutput", Value: "dependencies"} func newPageContentOutput(p *pageState, po *pageOutput) (*pageContentOutput, error) { - parent := p.init var dependencyTracker identity.Manager @@ -195,7 +194,6 @@ func newPageContentOutput(p *pageState, po *pageOutput) (*pageContentOutput, err cp.content = helpers.BytesToHTML(cp.workContent) return nil - } // Recursive loops can only happen in content files with template code (shortcodes etc.) @@ -225,7 +223,6 @@ func newPageContentOutput(p *pageState, po *pageOutput) (*pageContentOutput, err }) return cp, nil - } type renderHooks struct { @@ -370,7 +367,6 @@ func (p *pageContentOutput) setAutoSummary() error { p.truncated = truncated return nil - } func (cp *pageContentOutput) renderContent(content []byte, renderTOC bool) (converter.Result, error) { @@ -379,7 +375,6 @@ func (cp *pageContentOutput) renderContent(content []byte, renderTOC bool) (conv } func (cp *pageContentOutput) renderContentWithConverter(c converter.Converter, content []byte, renderTOC bool) (converter.Result, error) { - r, err := c.Convert( converter.RenderContext{ Src: content, @@ -396,7 +391,6 @@ func (cp *pageContentOutput) renderContentWithConverter(c converter.Converter, c } return r, err - } func (p *pageContentOutput) setWordCounts(isCJKLanguage bool) { @@ -467,7 +461,6 @@ func executeToString(h tpl.TemplateHandler, templ tpl.Template, data interface{} return "", err } return b.String(), nil - } func splitUserDefinedSummaryAndContent(markup string, c []byte) (summary []byte, content []byte, err error) { @@ -487,7 +480,6 @@ func splitUserDefinedSummaryAndContent(markup string, c []byte) (summary []byte, switch markup { case "asciidocext": startTag = "div" - } // Walk back and forward to the surrounding tags. diff --git a/hugolib/page__position.go b/hugolib/page__position.go index 458b3e423..a087872cc 100644 --- a/hugolib/page__position.go +++ b/hugolib/page__position.go @@ -24,7 +24,6 @@ func newPagePosition(n *nextPrev) pagePosition { func newPagePositionInSection(n *nextPrev) pagePositionInSection { return pagePositionInSection{nextPrev: n} - } type nextPrev struct { diff --git a/hugolib/page__ref.go b/hugolib/page__ref.go index 41bd527db..f2b819c57 100644 --- a/hugolib/page__ref.go +++ b/hugolib/page__ref.go @@ -89,7 +89,6 @@ func (p pageRef) ref(argsm map[string]interface{}, source interface{}) (string, } return s.refLink(args.Path, source, false, args.OutputFormat) - } func (p pageRef) relRef(argsm map[string]interface{}, source interface{}) (string, error) { @@ -107,7 +106,6 @@ func (p pageRef) relRef(argsm map[string]interface{}, source interface{}) (strin } return s.refLink(args.Path, source, true, args.OutputFormat) - } type refArgs struct { diff --git a/hugolib/page__tree.go b/hugolib/page__tree.go index a617ad384..e4f3c6b51 100644 --- a/hugolib/page__tree.go +++ b/hugolib/page__tree.go @@ -59,7 +59,6 @@ func (pt pageTree) IsAncestor(other interface{}) (bool, error) { } return strings.HasPrefix(ref2.key, ref1.key+cmBranchSeparator), nil - } func (pt pageTree) CurrentSection() page.Page { @@ -106,7 +105,6 @@ func (pt pageTree) IsDescendant(other interface{}) (bool, error) { } return strings.HasPrefix(ref1.key, ref2.key+cmBranchSeparator), nil - } func (pt pageTree) FirstSection() page.Page { @@ -151,7 +149,6 @@ func (pt pageTree) InSection(other interface{}) (bool, error) { s2, _ := ref2.getCurrentSection() return s1 == s2, nil - } func (pt pageTree) Page() page.Page { diff --git a/hugolib/page_kinds.go b/hugolib/page_kinds.go index 683d12c1b..b63da1d13 100644 --- a/hugolib/page_kinds.go +++ b/hugolib/page_kinds.go @@ -19,11 +19,8 @@ import ( "github.com/gohugoio/hugo/resources/page" ) -var ( - - // This is all the kinds we can expect to find in .Site.Pages. - allKindsInPages = []string{page.KindPage, page.KindHome, page.KindSection, page.KindTerm, page.KindTaxonomy} -) +// This is all the kinds we can expect to find in .Site.Pages. +var allKindsInPages = []string{page.KindPage, page.KindHome, page.KindSection, page.KindTerm, page.KindTaxonomy} const ( diff --git a/hugolib/page_permalink_test.go b/hugolib/page_permalink_test.go index 9081ea898..0939cc1ff 100644 --- a/hugolib/page_permalink_test.go +++ b/hugolib/page_permalink_test.go @@ -104,11 +104,9 @@ Content } }) } - } func TestRelativeURLInFrontMatter(t *testing.T) { - config := ` baseURL = "https://example.com" defaultContentLanguage = "en" @@ -148,5 +146,4 @@ Some content. b.AssertFileContent("public/myblog/p1/index.html", "Single: A page|Hello|en|RelPermalink: /myblog/p1/|Permalink: https://example.com/myblog/p1/|") b.AssertFileContent("public/myblog/p2/index.html", "Single: A page|Hello|en|RelPermalink: /myblog/p2/|Permalink: https://example.com/myblog/p2/|") b.AssertFileContent("public/myblog/p3/index.html", "Single: A page|Hello|en|RelPermalink: /myblog/p3/|Permalink: https://example.com/myblog/p3/|") - } diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 3a30216ed..b21fd1d2d 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -17,6 +17,10 @@ import ( "fmt" "html/template" "os" + "path/filepath" + "strings" + "testing" + "time" "github.com/gohugoio/hugo/markup/rst" @@ -26,11 +30,6 @@ import ( "github.com/gohugoio/hugo/common/loggers" - "path/filepath" - "strings" - "testing" - "time" - "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/resources/page" @@ -370,7 +369,6 @@ func normalizeExpected(ext, str string) string { func testAllMarkdownEnginesForPages(t *testing.T, assertFunc func(t *testing.T, ext string, pages page.Pages), settings map[string]interface{}, pageSources ...string) { - engines := []struct { ext string shouldExecute func() bool @@ -391,7 +389,6 @@ func testAllMarkdownEnginesForPages(t *testing.T, cfg.Set(k, v) } return nil - }) contentDir := "content" @@ -430,7 +427,6 @@ func testAllMarkdownEnginesForPages(t *testing.T, b.Assert(content(home), qt.Contains, "Home Page Content") } - } // Issue #1076 @@ -492,7 +488,6 @@ categories: ["cool stuff"] checkDated(p, p.Kind()) } checkDate(s.Info.LastChange(), "site") - } func TestPageDatesSections(t *testing.T) { @@ -646,7 +641,6 @@ Simple Page With Some Date` for _, p := range pages { c.Assert(hasDate(p), qt.Equals, true) } - } fields := []string{"date", "publishdate", "pubdate", "published"} @@ -677,7 +671,6 @@ title: Raw p := s.RegularPages()[0] c.Assert("**Raw**", qt.Equals, p.RawContent()) - } func TestPageWithShortCodeInSummary(t *testing.T) { @@ -714,7 +707,6 @@ func TestPageWithAdditionalExtension(t *testing.T) { } func TestTableOfContents(t *testing.T) { - cfg, fs := newTestCfg() c := qt.New(t) @@ -738,7 +730,6 @@ func TestPageWithMoreTag(t *testing.T) { checkPageContent(t, p, normalizeExpected(ext, "

Summary Same Line

\n\n

Some more text

\n")) checkPageSummary(t, p, normalizeExpected(ext, "

Summary Same Line

")) checkPageType(t, p, "page") - } testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithSummaryDelimiterSameLine) @@ -746,7 +737,6 @@ func TestPageWithMoreTag(t *testing.T) { // #2973 func TestSummaryWithHTMLTagsOnNextLine(t *testing.T) { - assertFunc := func(t *testing.T, ext string, pages page.Pages) { c := qt.New(t) p := pages[0] @@ -838,7 +828,6 @@ func TestPageWithLastmodFromGitInfo(t *testing.T) { // 2018-08-11 is the Git author date for testsite/content_nn/first-post.md c.Assert(nnSite.RegularPages()[0].Lastmod().Format("2006-01-02"), qt.Equals, "2018-08-11") - } func TestPageWithFrontMatterConfig(t *testing.T) { @@ -904,7 +893,6 @@ Content } }) } - } func TestWordCountWithAllCJKRunesWithoutHasCJKLanguage(t *testing.T) { @@ -970,7 +958,6 @@ func TestWordCountWithIsCJKLanguageFalse(t *testing.T) { } testAllMarkdownEnginesForPages(t, assertFunc, settings, simplePageWithIsCJKLanguageFalse) - } func TestWordCount(t *testing.T) { @@ -988,7 +975,6 @@ func TestWordCount(t *testing.T) { if p.ReadingTime() != 3 { t.Fatalf("[%s] incorrect min read. expected %v, got %v", ext, 3, p.ReadingTime()) } - } testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithLongContent) @@ -1052,7 +1038,6 @@ func TestTranslationKey(t *testing.T) { p2 := s.RegularPages()[1] c.Assert(p2.TranslationKey(), qt.Equals, "page/sect/simple") - } func TestChompBOM(t *testing.T) { @@ -1125,7 +1110,6 @@ but if you like it, hit :+1: and get subscribed! } } - } func TestPageHTMLContent(t *testing.T) { @@ -1162,7 +1146,6 @@ title: "HTML Content" "Summary: \n

This is summary

\n|Truncated: true", "|

This is the main content.

|", ) - } // https://github.com/gohugoio/hugo/issues/5381 @@ -1278,7 +1261,6 @@ Content:{{ .Content }} "Title: hello", "Content:

This is the content.

", ) - } // https://github.com/gohugoio/hugo/issues/5781 @@ -1305,11 +1287,11 @@ Content. func TestShouldBuild(t *testing.T) { t.Parallel() - var past = time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC) - var future = time.Date(2037, 11, 17, 20, 34, 58, 651387237, time.UTC) - var zero = time.Time{} + past := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC) + future := time.Date(2037, 11, 17, 20, 34, 58, 651387237, time.UTC) + zero := time.Time{} - var publishSettings = []struct { + publishSettings := []struct { buildFuture bool buildExpired bool buildDrafts bool @@ -1434,7 +1416,6 @@ tags: } else { c.Assert(p.RelPermalink(), qt.Equals, "/post/test0.dot/") } - }) } } @@ -1442,7 +1423,6 @@ tags: // https://github.com/gohugoio/hugo/issues/4675 func TestWordCountAndSimilarVsSummary(t *testing.T) { - t.Parallel() c := qt.New(t) @@ -1534,7 +1514,6 @@ Summary: In Chinese, 好 means good. b.AssertFileContent("public/p4/index.html", "WordCount: 7\nFuzzyWordCount: 100\nReadingTime: 1\nLen Plain: 638\nLen PlainWords: 7\nTruncated: true\nLen Summary: 43\nLen Content: 651") b.AssertFileContent("public/p5/index.html", "WordCount: 206\nFuzzyWordCount: 300\nReadingTime: 1\nLen Plain: 638\nLen PlainWords: 7\nTruncated: true\nLen Summary: 229\nLen Content: 652") b.AssertFileContent("public/p6/index.html", "WordCount: 7\nFuzzyWordCount: 100\nReadingTime: 1\nLen Plain: 638\nLen PlainWords: 7\nTruncated: false\nLen Summary: 637\nLen Content: 652") - } func TestScratchSite(t *testing.T) { @@ -1619,7 +1598,6 @@ author = "Jo Nesbø" "Author name page string: Kurt Vonnegut|", "Author page string: Jo Nesbø|", "Author site config: Kurt Vonnegut") - } func TestGoldmark(t *testing.T) { @@ -1742,7 +1720,6 @@ $$$ for i, ext := range []string{"md", "html"} { b.WithContent(fmt.Sprintf("page%d.%s", i+1, ext), content) - } b.Build(BuildCfg{}) diff --git a/hugolib/pagebundler_test.go b/hugolib/pagebundler_test.go index fa420a025..8f9459564 100644 --- a/hugolib/pagebundler_test.go +++ b/hugolib/pagebundler_test.go @@ -14,8 +14,11 @@ package hugolib import ( + "fmt" + "io" "os" "path" + "path/filepath" "regexp" "strings" "testing" @@ -29,16 +32,10 @@ import ( "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/resources/page" - "io" - "github.com/gohugoio/hugo/htesting" "github.com/gohugoio/hugo/media" - "path/filepath" - - "fmt" - "github.com/gohugoio/hugo/deps" "github.com/spf13/viper" @@ -265,12 +262,10 @@ func TestPageBundlerSiteRegular(t *testing.T) { b.AssertFileContent(filepath.FromSlash("/work/public/root/index.html"), "Single Title") } - }) } } } - } func TestPageBundlerSiteMultilingual(t *testing.T) { @@ -296,7 +291,7 @@ func TestPageBundlerSiteMultilingual(t *testing.T) { c.Assert(len(s.RegularPages()), qt.Equals, 8) c.Assert(len(s.Pages()), qt.Equals, 16) - //dumpPages(s.AllPages()...) + // dumpPages(s.AllPages()...) c.Assert(len(s.AllPages()), qt.Equals, 31) bundleWithSubPath := s.getPage(page.KindPage, "lb/index") @@ -350,7 +345,6 @@ func TestPageBundlerSiteMultilingual(t *testing.T) { b.AssertFileContent("public/nn/bc/data1.nn.json", "data1.nn") b.AssertFileContent("public/nn/bc/data2.json", "data2") b.AssertFileContent("public/nn/bc/logo-bc.png", "logo") - }) } } @@ -393,7 +387,6 @@ func TestMultilingualDisableLanguage(t *testing.T) { c.Assert(p.Language().Lang != "nn", qt.Equals, true) return false }) - } func TestPageBundlerSiteWitSymbolicLinksInContent(t *testing.T) { @@ -499,7 +492,6 @@ TheContent. b.AssertFileContent(filepath.FromSlash(workDir+"/public/a/page/index.html"), "TheContent") b.AssertFileContent(filepath.FromSlash(workDir+"/public/symbolic1/s1/index.html"), "TheContent") b.AssertFileContent(filepath.FromSlash(workDir+"/public/symbolic2/a1/index.html"), "TheContent") - } func TestPageBundlerHeadless(t *testing.T) { @@ -583,7 +575,6 @@ HEADLESS {{< myShort >}} c.Assert(s.RegularPages(), qt.HasLen, 1) c.Assert(s.home.RegularPages(), qt.HasLen, 1) c.Assert(s.home.Pages(), qt.HasLen, 1) - } func TestPageBundlerHeadlessIssue6552(t *testing.T) { @@ -705,7 +696,6 @@ Single content. b.AssertFileContent("public/section-not-bundle/index.html", "Section Page", "Content:

Section content.

") b.AssertFileContent("public/section-not-bundle/single/index.html", "Section Single", "|

Single content.

") - } func newTestBundleSources(t testing.TB) (*hugofs.Fs, *viper.Viper) { @@ -873,7 +863,6 @@ Content for 은행. c.Assert(err, qt.IsNil) return fs, cfg - } func newTestBundleSourcesMultilingual(t *testing.T) (*hugofs.Fs, *viper.Viper) { @@ -955,7 +944,7 @@ TheContent. writeSource(t, fs, filepath.Join(workDir, "base", "lb", "c", "one.png"), "content") writeSource(t, fs, filepath.Join(workDir, "base", "lb", "c", "d", "deep.png"), "content") - //Translated bundle in some sensible sub path. + // Translated bundle in some sensible sub path. writeSource(t, fs, filepath.Join(workDir, "base", "bf", "my-bf-bundle", "index.md"), pageContent) writeSource(t, fs, filepath.Join(workDir, "base", "bf", "my-bf-bundle", "index.nn.md"), pageContent) writeSource(t, fs, filepath.Join(workDir, "base", "bf", "my-bf-bundle", "page.md"), pageContent) @@ -994,7 +983,6 @@ date: 2017-01-15 b.Build(BuildCfg{}) b.AssertFileContent("public/mybundle/data.json", "My changed data") - } // https://github.com/gohugoio/hugo/issues/4870 @@ -1023,7 +1011,6 @@ slug: %s c.Assert(b.CheckExists("public/about/services1/this-is-the-slug/index.html"), qt.Equals, true) c.Assert(b.CheckExists("public/about/services2/this-is-another-slug/index.html"), qt.Equals, true) - } func TestBundleMisc(t *testing.T) { @@ -1112,13 +1099,11 @@ slug: leaf b.AssertFileContentFn("public/en/index.html", func(s string) bool { // Check ignored files return !regexp.MustCompile("README|ignore").MatchString(s) - }) b.AssertFileContent("public/nn/index.html", filepath.FromSlash("page|sect1/sect2/page.md|CurrentSection: sect1")) b.AssertFileContentFn("public/nn/index.html", func(s string) bool { return !strings.Contains(s, "enonly") - }) // Check order of inherited data file @@ -1136,7 +1121,6 @@ slug: leaf b.AssertFileContent("public/en/b2/index.html", "/en/b2/leaf/", filepath.FromSlash("section|sect1/sect2/_index.md|CurrentSection: sect1/sect2/_index.md")) - } // Issue 6136 @@ -1214,7 +1198,6 @@ Num Pages: {{ len .Site.Pages }} "page|/en/blog/sect2/b1/|Content: s2.b1|Resources: R: data.json|s2.b1.data|", "page|/en/blog/sect2/b2/|Content: s2.b2|Resources: R: s2.b2.bundlecontent|", ) - } // #6208 @@ -1256,11 +1239,9 @@ title: %q page|bundle sub index| page|bundle sub p2| `) - } func TestBundleTransformMany(t *testing.T) { - b := newTestSitesBuilder(t).WithSimpleConfigFile().Running() for i := 1; i <= 50; i++ { diff --git a/hugolib/pagecollections.go b/hugolib/pagecollections.go index 49378452f..c1c9ef88b 100644 --- a/hugolib/pagecollections.go +++ b/hugolib/pagecollections.go @@ -205,7 +205,6 @@ func (c *PageCollections) getSectionOrPage(ref string) (*contentNode, string) { } return m.getPage(s, name), name - } // For Ref/Reflink and .Site.GetPage do simple name lookups for the potentially ambigous myarticle.md and /myarticle.md, @@ -326,7 +325,6 @@ func (c *PageCollections) getContentNode(context page.Page, isReflink bool, ref // Ref/relref supports this potentially ambigous lookup. return getByName(path.Base(name)) - } func (*PageCollections) findPagesByKindIn(kind string, inPages page.Pages) page.Pages { diff --git a/hugolib/pagecollections_test.go b/hugolib/pagecollections_test.go index b9623eb34..d664b7f4e 100644 --- a/hugolib/pagecollections_test.go +++ b/hugolib/pagecollections_test.go @@ -71,7 +71,6 @@ func BenchmarkGetPage(b *testing.B) { } func createGetPageRegularBenchmarkSite(t testing.TB) *Site { - var ( c = qt.New(t) cfg, fs = newTestCfg() @@ -89,7 +88,6 @@ func createGetPageRegularBenchmarkSite(t testing.TB) *Site { } return buildSingleSite(c, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) - } func TestBenchmarkGetPageRegular(t *testing.T) { @@ -142,7 +140,6 @@ func BenchmarkGetPageRegular(b *testing.B) { c.Assert(page, qt.Not(qt.IsNil)) } }) - } type getPageTest struct { @@ -172,7 +169,6 @@ func (t *getPageTest) check(p page.Page, err error, errorMsg string, c *qt.C) { } func TestGetPage(t *testing.T) { - var ( cfg, fs = newTestCfg() c = qt.New(t) @@ -246,10 +242,10 @@ func TestGetPage(t *testing.T) { {"Absolute, page in subsection", page.KindPage, nil, []string{"/sect3/page1.md", "/Sect3/Page1.md"}, "Title3_1"}, {"Absolute, section, subsection with same name", page.KindSection, nil, []string{"/sect3/sect7"}, "another sect7"}, {"Absolute, page, deep", page.KindPage, nil, []string{"/sect3/subsect/deep.md"}, "deep page"}, - {"Absolute, page, OS slashes", page.KindPage, nil, []string{filepath.FromSlash("/sect5/page3.md")}, "Title5_3"}, //test OS-specific path + {"Absolute, page, OS slashes", page.KindPage, nil, []string{filepath.FromSlash("/sect5/page3.md")}, "Title5_3"}, // test OS-specific path {"Absolute, unique", page.KindPage, nil, []string{"/sect3/unique.md"}, "UniqueBase"}, {"Absolute, unique, case", page.KindPage, nil, []string{"/sect3/Unique2.md", "/sect3/unique2.md", "/sect3/unique2", "/sect3/Unique2"}, "UniqueBase2"}, - //next test depends on this page existing + // next test depends on this page existing // {"NoPage", nil, []string{"/unique.md"}, ""}, // ISSUE #4969: this is resolving to /sect3/unique.md {"Absolute, missing page", "NoPage", nil, []string{"/missing-page.md"}, ""}, {"Absolute, missing section", "NoPage", nil, []string{"/missing-section"}, ""}, @@ -267,7 +263,7 @@ func TestGetPage(t *testing.T) { {"Rel sect7 dot", page.KindSection, sec3, []string{"./sect7"}, "another sect7"}, {"Dot deep", page.KindPage, sec3, []string{"./subsect/deep.md"}, "deep page"}, {"Dot dot inner", page.KindPage, sec3, []string{"./subsect/../../sect7/page9.md"}, "Title7_9"}, - {"Dot OS slash", page.KindPage, sec3, []string{filepath.FromSlash("../sect5/page3.md")}, "Title5_3"}, //test OS-specific path + {"Dot OS slash", page.KindPage, sec3, []string{filepath.FromSlash("../sect5/page3.md")}, "Title5_3"}, // test OS-specific path {"Dot unique", page.KindPage, sec3, []string{"./unique.md"}, "UniqueBase"}, {"Dot sect", "NoPage", sec3, []string{"./sect2"}, ""}, //{"NoPage", sec3, []string{"sect2"}, ""}, // ISSUE: /sect3 page relative query is resolving to /sect2 @@ -275,7 +271,7 @@ func TestGetPage(t *testing.T) { {"Abs, ignore context, home", page.KindHome, sec3, []string{"/"}, "home page"}, {"Abs, ignore context, about", page.KindPage, sec3, []string{"/about.md"}, "about page"}, {"Abs, ignore context, page in section", page.KindPage, sec3, []string{"/sect4/page2.md"}, "Title4_2"}, - {"Abs, ignore context, page subsect deep", page.KindPage, sec3, []string{"/sect3/subsect/deep.md"}, "deep page"}, //next test depends on this page existing + {"Abs, ignore context, page subsect deep", page.KindPage, sec3, []string{"/sect3/subsect/deep.md"}, "deep page"}, // next test depends on this page existing {"Abs, ignore context, page deep", "NoPage", sec3, []string{"/subsect/deep.md"}, ""}, // Taxonomies @@ -308,10 +304,8 @@ func TestGetPage(t *testing.T) { page2, err := s.getPageNew(test.context, ref) test.check(page2, err, errorMsg, c) } - }) } - } // https://github.com/gohugoio/hugo/issues/6034 @@ -338,7 +332,6 @@ NOT FOUND b.AssertFileContent("public/what/index.html", `Members: members what`) b.AssertFileContent("public/where/index.html", `Members: members where`) b.AssertFileContent("public/who/index.html", `NOT FOUND`) - } // https://github.com/gohugoio/hugo/issues/7016 @@ -377,7 +370,6 @@ NOT FOUND b.AssertFileContent("public/index.html", `Docs p1: p1`) b.AssertFileContent("public/en/index.html", `NOT FOUND`) - } func TestShouldDoSimpleLookup(t *testing.T) { @@ -387,7 +379,6 @@ func TestShouldDoSimpleLookup(t *testing.T) { c.Assert(shouldDoSimpleLookup("/foo.md"), qt.Equals, true) c.Assert(shouldDoSimpleLookup("./foo.md"), qt.Equals, false) c.Assert(shouldDoSimpleLookup("docs/foo.md"), qt.Equals, false) - } func TestRegularPagesRecursive(t *testing.T) { @@ -426,5 +417,4 @@ Sect1 RegularPagesRecursive: page:/docs/sect1/ps1/|page:/docs/sect1/ps2/|page:/d `) - } diff --git a/hugolib/pages_capture.go b/hugolib/pages_capture.go index 9f2e4bab1..98e9fda51 100644 --- a/hugolib/pages_capture.go +++ b/hugolib/pages_capture.go @@ -44,7 +44,6 @@ func newPagesCollector( logger loggers.Logger, contentTracker *contentChangeMap, proc pagesCollectorProcessorProvider, filenames ...string) *pagesCollector { - return &pagesCollector{ fs: sp.SourceFs, contentMap: contentMap, @@ -75,7 +74,6 @@ func (b *fileinfoBundle) containsResource(name string) bool { } return false - } type pageBundles map[string]*fileinfoBundle @@ -154,7 +152,6 @@ func (c *pagesCollector) isCascadingEdit(dir contentDirKey) (bool, string) { } return true - }) return isCascade, section @@ -213,7 +210,6 @@ func (c *pagesCollector) Collect() (collectErr error) { } return - } func (c *pagesCollector) isBundleHeader(fi hugofs.FileMetaInfo) bool { @@ -343,7 +339,6 @@ func (c *pagesCollector) collectDir(dirname string, partial bool, inFilter func( dir hugofs.FileMetaInfo, path string, readdir []hugofs.FileMetaInfo) error { - if btype > bundleNot && c.tracker != nil { c.tracker.add(path, btype) } @@ -367,7 +362,6 @@ func (c *pagesCollector) collectDir(dirname string, partial bool, inFilter func( } return nil - } filter := func(fim hugofs.FileMetaInfo) bool { @@ -469,7 +463,6 @@ func (c *pagesCollector) collectDir(dirname string, partial bool, inFilter func( // Keep walking. return readdir, nil - } var postHook hugofs.WalkHook @@ -504,14 +497,13 @@ func (c *pagesCollector) collectDir(dirname string, partial bool, inFilter func( Info: fim, HookPre: preHook, HookPost: postHook, - WalkFn: wfn}) + WalkFn: wfn, + }) return w.Walk() - } func (c *pagesCollector) handleBundleBranch(readdir []hugofs.FileMetaInfo) error { - // Maps bundles to its language. bundles := pageBundles{} @@ -542,7 +534,6 @@ func (c *pagesCollector) handleBundleBranch(readdir []hugofs.FileMetaInfo) error } return c.handleFiles(contentFiles...) - } func (c *pagesCollector) handleBundleLeaf(dir hugofs.FileMetaInfo, path string, readdir []hugofs.FileMetaInfo) error { @@ -558,7 +549,6 @@ func (c *pagesCollector) handleBundleLeaf(dir hugofs.FileMetaInfo, path string, } return c.addToBundle(info, bundleLeaf, bundles) - } // Start a new walker from the given path. @@ -568,14 +558,14 @@ func (c *pagesCollector) handleBundleLeaf(dir hugofs.FileMetaInfo, path string, Logger: c.logger, Info: dir, DirEntries: readdir, - WalkFn: walk}) + WalkFn: walk, + }) if err := w.Walk(); err != nil { return err } return c.proc.Process(bundles) - } func (c *pagesCollector) handleFiles(fis ...hugofs.FileMetaInfo) error { diff --git a/hugolib/pages_capture_test.go b/hugolib/pages_capture_test.go index 4401ca6ed..0fdc73e76 100644 --- a/hugolib/pages_capture_test.go +++ b/hugolib/pages_capture_test.go @@ -30,13 +30,12 @@ import ( ) func TestPagesCapture(t *testing.T) { - cfg, hfs := newTestCfg() fs := hfs.Source c := qt.New(t) - var writeFile = func(filename string) { + writeFile := func(filename string) { c.Assert(afero.WriteFile(fs, filepath.FromSlash(filename), []byte(fmt.Sprintf("content-%s", filename)), 0755), qt.IsNil) } @@ -61,7 +60,6 @@ func TestPagesCapture(t *testing.T) { c.Assert(coll.Collect(), qt.IsNil) c.Assert(len(proc.items), qt.Equals, 4) }) - } type testPagesCollectorProcessor struct { @@ -73,6 +71,7 @@ func (proc *testPagesCollectorProcessor) Process(item interface{}) error { proc.items = append(proc.items, item) return nil } + func (proc *testPagesCollectorProcessor) Start(ctx context.Context) context.Context { return ctx } diff --git a/hugolib/pages_language_merge_test.go b/hugolib/pages_language_merge_test.go index 7d7181214..fb59235c1 100644 --- a/hugolib/pages_language_merge_test.go +++ b/hugolib/pages_language_merge_test.go @@ -85,7 +85,6 @@ func TestMergeLanguages(t *testing.T) { unchanged, err := nnSite.RegularPages().MergeByLanguageInterface(nil) c.Assert(err, qt.IsNil) c.Assert(unchanged, deepEqualsPages, nnSite.RegularPages()) - } func TestMergeLanguagesTemplate(t *testing.T) { diff --git a/hugolib/pages_process.go b/hugolib/pages_process.go index af029fee9..90b67a717 100644 --- a/hugolib/pages_process.go +++ b/hugolib/pages_process.go @@ -156,7 +156,6 @@ func (p *sitePagesProcessor) copyFile(fim hugofs.FileMetaInfo) error { defer f.Close() return s.publish(&s.PathSpec.ProcessingStats.Files, target, f) - } func (p *sitePagesProcessor) doProcess(item interface{}) error { @@ -189,7 +188,6 @@ func (p *sitePagesProcessor) doProcess(item interface{}) error { panic(fmt.Sprintf("unrecognized item type in Process: %T", item)) } return nil - } func (p *sitePagesProcessor) shouldSkip(fim hugofs.FileMetaInfo) bool { diff --git a/hugolib/pages_test.go b/hugolib/pages_test.go index 6a371b421..0d879d2c7 100644 --- a/hugolib/pages_test.go +++ b/hugolib/pages_test.go @@ -55,13 +55,13 @@ func BenchmarkPagesPrevNext(b *testing.B) { } for _, variant := range []Variant{ - Variant{".Next", nil, func(p page.Page, pages page.Pages) { p.Next() }}, - Variant{".Prev", nil, func(p page.Page, pages page.Pages) { p.Prev() }}, - Variant{"Pages.Next", nil, func(p page.Page, pages page.Pages) { pages.Next(p) }}, - Variant{"Pages.Prev", nil, func(p page.Page, pages page.Pages) { pages.Prev(p) }}, - Variant{"Pages.Shuffled.Next", shufflePages, func(p page.Page, pages page.Pages) { pages.Next(p) }}, - Variant{"Pages.Shuffled.Prev", shufflePages, func(p page.Page, pages page.Pages) { pages.Prev(p) }}, - Variant{"Pages.ByTitle.Next", func(pages page.Pages) page.Pages { return pages.ByTitle() }, func(p page.Page, pages page.Pages) { pages.Next(p) }}, + {".Next", nil, func(p page.Page, pages page.Pages) { p.Next() }}, + {".Prev", nil, func(p page.Page, pages page.Pages) { p.Prev() }}, + {"Pages.Next", nil, func(p page.Page, pages page.Pages) { pages.Next(p) }}, + {"Pages.Prev", nil, func(p page.Page, pages page.Pages) { pages.Prev(p) }}, + {"Pages.Shuffled.Next", shufflePages, func(p page.Page, pages page.Pages) { pages.Next(p) }}, + {"Pages.Shuffled.Prev", shufflePages, func(p page.Page, pages page.Pages) { pages.Prev(p) }}, + {"Pages.ByTitle.Next", func(pages page.Pages) page.Pages { return pages.ByTitle() }, func(p page.Page, pages page.Pages) { pages.Next(p) }}, } { for _, numPages := range []int{300, 5000} { b.Run(fmt.Sprintf("%s-pages-%d", variant.name, numPages), func(b *testing.B) { diff --git a/hugolib/paginator_test.go b/hugolib/paginator_test.go index e6a196150..a8d8ac8df 100644 --- a/hugolib/paginator_test.go +++ b/hugolib/paginator_test.go @@ -47,7 +47,6 @@ title: Page %d Content. `, i)) } - } b.WithContent(content...) @@ -97,7 +96,6 @@ URL: {{ $pag.URL }} b.AssertFileContent("public/nn/index.xml", "Page Number: 1", "0: 1/1 true") - } // Issue 6023 diff --git a/hugolib/paths/paths.go b/hugolib/paths/paths.go index 97d4f17ba..8af77b072 100644 --- a/hugolib/paths/paths.go +++ b/hugolib/paths/paths.go @@ -82,7 +82,6 @@ type Paths struct { func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) { baseURLstr := cfg.GetString("baseURL") baseURL, err := newBaseURLFromString(baseURLstr) - if err != nil { return nil, errors.Wrapf(err, "Failed to create baseURL from %q:", baseURLstr) } @@ -106,7 +105,6 @@ func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) { if l, ok := cfg.(*langs.Language); ok { language = l - } if l, ok := cfg.Get("languagesSorted").(langs.Languages); ok { @@ -268,7 +266,6 @@ func (p *Paths) RelPathify(filename string) string { } return strings.TrimPrefix(strings.TrimPrefix(filename, p.WorkingDir), FilePathSeparator) - } // AbsPathify creates an absolute path if given a working dir and arelative path. diff --git a/hugolib/permalinker.go b/hugolib/permalinker.go index 29dad6ce4..aeaa673f7 100644 --- a/hugolib/permalinker.go +++ b/hugolib/permalinker.go @@ -13,9 +13,7 @@ package hugolib -var ( - _ Permalinker = (*pageState)(nil) -) +var _ Permalinker = (*pageState)(nil) // Permalinker provides permalinks of both the relative and absolute kind. type Permalinker interface { diff --git a/hugolib/resource_chain_babel_test.go b/hugolib/resource_chain_babel_test.go index e6e4ed8d3..e56c037f1 100644 --- a/hugolib/resource_chain_babel_test.go +++ b/hugolib/resource_chain_babel_test.go @@ -127,5 +127,4 @@ var Car = function Car(brand) { this.carname = brand; }; `) - } diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go index 7573199aa..5ee62254a 100644 --- a/hugolib/resource_chain_test.go +++ b/hugolib/resource_chain_test.go @@ -15,14 +15,10 @@ package hugolib import ( "bytes" - - jww "github.com/spf13/jwalterweatherman" - "fmt" "io" "math/rand" "os" - "os/exec" "path/filepath" "runtime" @@ -30,6 +26,8 @@ import ( "testing" "time" + jww "github.com/spf13/jwalterweatherman" + "github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/htesting" @@ -92,7 +90,6 @@ T1: {{ $r.Content }} b.Build(BuildCfg{}) b.AssertFileContent(filepath.Join(workDir, "public/index.html"), `T1: moo{color:#fff}`) - } func TestSCSSWithRegularCSSImport(t *testing.T) { @@ -155,7 +152,6 @@ moo { /* foo */ `) - } func TestSCSSWithThemeOverrides(t *testing.T) { @@ -241,7 +237,6 @@ T1: {{ $r.Content }} b.Build(BuildCfg{}) b.AssertFileContent(filepath.Join(workDir, "public/index.html"), `T1: moo{color:#ccc}boo{color:green}`) - } // https://github.com/gohugoio/hugo/issues/6274 @@ -289,7 +284,6 @@ T1: {{ $r.Content }} b.Build(BuildCfg{}) b.AssertFileContent(filepath.Join(workDir, "public/index.html"), `T1: foo{color:#ccc}`) - } func TestResourceChainBasic(t *testing.T) { @@ -394,11 +388,9 @@ End.`) b.AssertFileContent("public/page1/index.html", `HELLO: /hello.min.a2d1cb24f24b322a7dad520414c523e9.html`) b.AssertFileContent("public/page2/index.html", `HELLO: /hello.min.a2d1cb24f24b322a7dad520414c523e9.html`) - } func BenchmarkResourceChainPostProcess(b *testing.B) { - for i := 0; i < b.N; i++ { b.StopTimer() s := newTestSitesBuilder(b) @@ -431,7 +423,6 @@ End. s.Build(BuildCfg{}) } - } func TestResourceChains(t *testing.T) { @@ -472,7 +463,6 @@ T6: {{ $bundle1.Permalink }} c.Assert(b.CheckExists("public/styles/templ.min.css"), qt.Equals, false) b.AssertFileContent("public/styles/bundle1.css", `.home{color:blue}body{color:#333}`) - }}, {"minify", func() bool { return true }, func(b *sitesBuilder) { @@ -550,10 +540,8 @@ T3: Content: {{ $combinedJs.Content }}|{{ $combinedJs.RelPermalink }} Fingerprinted: {{ $fingerprinted.RelPermalink }} `) }, func(b *sitesBuilder) { - b.AssertFileContent("public/index.html", "Fingerprinted: /bundle/concat.b5d4045c3f466fa91fe2cc6abe79232a1a57cdf104f7a26e716e0a1e2789df78.txt") b.AssertFileContent("public/bundle/concat.b5d4045c3f466fa91fe2cc6abe79232a1a57cdf104f7a26e716e0a1e2789df78.txt", "ABC") - }}, {"fromstring", func() bool { return true }, func(b *sitesBuilder) { @@ -561,11 +549,9 @@ Fingerprinted: {{ $fingerprinted.RelPermalink }} {{ $r := "Hugo Rocks!" | resources.FromString "rocks/hugo.txt" }} {{ $r.Content }}|{{ $r.RelPermalink }}|{{ $r.Permalink }}|{{ $r.MediaType.Type }} `) - }, func(b *sitesBuilder) { b.AssertFileContent("public/index.html", `Hugo Rocks!|/rocks/hugo.txt|http://example.com/rocks/hugo.txt|text/plain`) b.AssertFileContent("public/rocks/hugo.txt", "Hugo Rocks!") - }}, {"execute-as-template", func() bool { return true @@ -579,10 +565,8 @@ T1: {{ $var }} {{ $result := "{{ .Kind | upper }}" | resources.FromString "mytpl.txt" | resources.ExecuteAsTemplate "result.txt" . }} T2: {{ $result.Content }}|{{ $result.RelPermalink}}|{{$result.MediaType.Type }} `) - }, func(b *sitesBuilder) { b.AssertFileContent("public/index.html", `T2: HOME|/result.txt|text/plain`, `T1: Hugo Home`) - }}, {"fingerprint", func() bool { return true }, func(b *sitesBuilder) { b.WithTemplates("home.html", ` @@ -604,7 +588,6 @@ T4: {{ $r2.Data.Integrity }}| b.AssertFileContent("public/index.html", `T2: ab|/rocks/hugo.2d408a0717ec188158278a796c689044361dc6fdde28d6f04973b80896e1823975cdbf12eb63f9e0591328ee235d80e9b5bf1aa6a44f4617ff3caf6400eb172d.txt|text/plain|sha512-LUCKBxfsGIFYJ4p5bGiQRDYdxv3eKNbwSXO4CJbhgjl1zb8S62P54FkTKO4jXYDptb8apqRPRhf/PK9kAOsXLQ==|`) b.AssertFileContent("public/index.html", `T3: ab|/rocks/hugo.187ef4436122d1cc2f40dc2b92f0eba0.txt|text/plain|md5-GH70Q2Ei0cwvQNwrkvDroA==|`) b.AssertFileContent("public/index.html", `T4: sha256-Hgu9bGhroFC46wP/7txk/cnYCUf86CGrvl1tyNJSxaw=|`) - }}, // https://github.com/gohugoio/hugo/issues/5226 {"baseurl-path", func() bool { return true }, func(b *sitesBuilder) { @@ -615,7 +598,6 @@ T1: {{ $r1.Permalink }}|{{ $r1.RelPermalink }} `) }, func(b *sitesBuilder) { b.AssertFileContent("public/index.html", `T1: https://example.com/hugo/rocks/hugo.txt|/hugo/rocks/hugo.txt`) - }}, // https://github.com/gohugoio/hugo/issues/4944 @@ -629,7 +611,6 @@ Inline: {{ $cssInline.Content }} Publish 1: {{ $cssPublish1.Content }} {{ $cssPublish1.RelPermalink }} Publish 2: {{ $cssPublish2.Permalink }} `) - }, func(b *sitesBuilder) { b.AssertFileContent("public/index.html", `Inline: body{color:green}`, @@ -766,7 +747,6 @@ $color: #333; test.prepare(b) b.Build(BuildCfg{}) test.verify(b) - }) } } @@ -785,7 +765,6 @@ func TestMultiSiteResource(t *testing.T) { c.Assert(b.CheckExists("public/en/text/pipes.txt"), qt.Equals, false) b.AssertFileContent("public/en/index.html", "Default Home Page", "String Resource: /blog/text/pipes.txt") b.AssertFileContent("public/text/pipes.txt", "Hugo Pipes") - } func TestResourcesMatch(t *testing.T) { @@ -842,7 +821,6 @@ Hello2: Hello Hello1: Bonjour Hello2: Bonjour `) - } func TestResourceChainPostCSS(t *testing.T) { @@ -971,7 +949,6 @@ Styles Content: Len: 770878| b.Assert(strings.Contains(content, "class-in-a"), qt.Equals, true) b.Assert(strings.Contains(content, "class-in-b"), qt.Equals, true) - } assertCss(b) @@ -1031,7 +1008,6 @@ class-in-b { build("always", true) build("fallback", true) build("never", true) - } func TestResourceMinifyDisabled(t *testing.T) { diff --git a/hugolib/robotstxt_test.go b/hugolib/robotstxt_test.go index e924cb8dc..6bc39e97c 100644 --- a/hugolib/robotstxt_test.go +++ b/hugolib/robotstxt_test.go @@ -38,5 +38,4 @@ func TestRobotsTXTOutput(t *testing.T) { b.Build(BuildCfg{}) b.AssertFileContent("public/robots.txt", "User-agent: Googlebot") - } diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index 619047e38..483fad2e1 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -16,29 +16,25 @@ package hugolib import ( "bytes" "fmt" + "html/template" + "path" + "reflect" + "regexp" + "sort" "strconv" + "strings" + "sync" "github.com/gohugoio/hugo/helpers" - "html/template" - "path" - "github.com/gohugoio/hugo/common/herrors" "github.com/pkg/errors" - "reflect" - - "regexp" - "sort" - "github.com/gohugoio/hugo/parser/pageparser" "github.com/gohugoio/hugo/resources/page" _errors "github.com/pkg/errors" - "strings" - "sync" - "github.com/gohugoio/hugo/common/maps" "github.com/gohugoio/hugo/common/text" "github.com/gohugoio/hugo/common/urls" @@ -153,7 +149,6 @@ func (scp *ShortcodeWithPage) Get(key interface{}) interface{} { } return x.Interface() - } func (scp *ShortcodeWithPage) page() page.Page { @@ -230,7 +225,7 @@ func (sc shortcode) String() string { keys = append(keys, k) } sort.Strings(keys) - var tmp = make(map[string]interface{}) + tmp := make(map[string]interface{}) for _, k := range keys { tmp[k] = v[k] @@ -261,7 +256,6 @@ type shortcodeHandler struct { } func newShortcodeHandler(p *pageState, s *Site, placeholderFunc func() string) *shortcodeHandler { - sh := &shortcodeHandler{ p: p, s: s, @@ -286,7 +280,6 @@ func renderShortcode( sc *shortcode, parent *ShortcodeWithPage, p *pageState) (string, bool, error) { - var tmpl tpl.Template // Tracks whether this shortcode or any of its children has template variations @@ -360,7 +353,6 @@ func renderShortcode( if sc.doMarkup && (level > 0 || sc.configVersion() == 1) { var err error b, err := p.pageOutput.cp.renderContent([]byte(inner), false) - if err != nil { return "", false, err } @@ -413,7 +405,6 @@ func (s *shortcodeHandler) hasShortcodes() bool { } func (s *shortcodeHandler) renderShortcodesForPage(p *pageState, f output.Format) (map[string]string, bool, error) { - rendered := make(map[string]string) tplVariants := tpl.TemplateVariants{ @@ -455,9 +446,9 @@ func (s *shortcodeHandler) extractShortcode(ordinal, level int, pt *pageparser.I } sc := &shortcode{ordinal: ordinal} - var cnt = 0 - var nestedOrdinal = 0 - var nextLevel = level + 1 + cnt := 0 + nestedOrdinal := 0 + nextLevel := level + 1 fail := func(err error, i pageparser.Item) error { return s.parseError(err, pt.Input(), i.Pos) @@ -568,7 +559,6 @@ Loop: } else { return sc, errShortCodeIllegalState } - } } else { // positional params @@ -583,7 +573,6 @@ Loop: } else { return sc, errShortCodeIllegalState } - } } case currItem.IsDone(): @@ -599,7 +588,6 @@ Loop: // Replace prefixed shortcode tokens with the real content. // Note: This function will rewrite the input slice. func replaceShortcodeTokens(source []byte, replacements map[string]string) ([]byte, error) { - if len(replacements) == 0 { return source, nil } diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 9e923b093..7f206a788 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -17,6 +17,8 @@ import ( "fmt" "path/filepath" "reflect" + "strings" + "testing" "github.com/gohugoio/hugo/markup/asciidocext" "github.com/gohugoio/hugo/markup/rst" @@ -26,9 +28,6 @@ import ( "github.com/gohugoio/hugo/parser/pageparser" "github.com/gohugoio/hugo/resources/page" - "strings" - "testing" - "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl" "github.com/spf13/cast" @@ -96,7 +95,6 @@ func TestNonSC(t *testing.T) { func TestHyphenatedSC(t *testing.T) { t.Parallel() wt := func(tem tpl.TemplateManager) error { - tem.AddTemplate("_internal/shortcodes/hyphenated-video.html", `Playing Video {{ .Get 0 }}`) return nil } @@ -286,7 +284,6 @@ func TestParentShortcode(t *testing.T) { } CheckShortCodeMatch(t, `{{< r1 pr1="p1" >}}1: {{< r2 pr2="p2" >}}2: {{< r3 pr3="p3" >}}{{< /r3 >}}{{< /r2 >}}{{< /r1 >}}`, "1: p1 1: 2: p1p2 2: 3: p1p2p3 ", wt) - } func TestFigureOnlySrc(t *testing.T) { @@ -392,7 +389,6 @@ title: "Shortcodes Galore!" return func(c *qt.C, shortcode *shortcode, err error) { c.Assert(err, qt.IsNil) c.Assert(str(shortcode), qt.Matches, ".*"+re+".*") - } } @@ -413,10 +409,14 @@ title: "Shortcodes Galore!" {"inner", `{{< inner >}}Inner Content{{< / inner >}}`, regexpCheck("inner;inline:false;closing:true;inner:{Inner Content};")}, // issue #934 {"inner self-closing", `{{< inner />}}`, regexpCheck("inner;.*inner:{}")}, - {"nested inner", `{{< inner >}}Inner Content->{{% inner2 param1 %}}inner2txt{{% /inner2 %}}Inner close->{{< / inner >}}`, - regexpCheck("inner;.*inner:{Inner Content->.*Inner close->}")}, - {"nested, nested inner", `{{< inner >}}inner2->{{% inner2 param1 %}}inner2txt->inner3{{< inner3>}}inner3txt{{}}{{% /inner2 %}}final close->{{< / inner >}}`, - regexpCheck("inner:{inner2-> inner2.*{{inner2txt->inner3.*final close->}")}, + { + "nested inner", `{{< inner >}}Inner Content->{{% inner2 param1 %}}inner2txt{{% /inner2 %}}Inner close->{{< / inner >}}`, + regexpCheck("inner;.*inner:{Inner Content->.*Inner close->}"), + }, + { + "nested, nested inner", `{{< inner >}}inner2->{{% inner2 param1 %}}inner2txt->inner3{{< inner3>}}inner3txt{{}}{{% /inner2 %}}final close->{{< / inner >}}`, + regexpCheck("inner:{inner2-> inner2.*{{inner2txt->inner3.*final close->}"), + }, {"closed without content", `{{< inner param1 >}}{{< / inner >}}`, regexpCheck("inner.*inner:{}")}, {"inline", `{{< my.inline >}}Hi{{< /my.inline >}}`, regexpCheck("my.inline;inline:true;closing:true;inner:{Hi};")}, } { @@ -441,10 +441,8 @@ title: "Shortcodes Galore!" short, err := handler.extractShortcode(0, 0, iter) test.check(c, short, err) - }) } - } func TestShortcodesInSite(t *testing.T) { @@ -456,11 +454,14 @@ func TestShortcodesInSite(t *testing.T) { outFile string expected interface{} }{ - {"sect/doc1.md", `a{{< b >}}c`, - filepath.FromSlash("public/sect/doc1/index.html"), "

abc

\n"}, + { + "sect/doc1.md", `a{{< b >}}c`, + filepath.FromSlash("public/sect/doc1/index.html"), "

abc

\n", + }, // Issue #1642: Multiple shortcodes wrapped in P // Deliberately forced to pass even if they maybe shouldn't. - {"sect/doc2.md", `a + { + "sect/doc2.md", `a {{< b >}} {{< c >}} @@ -468,8 +469,10 @@ func TestShortcodesInSite(t *testing.T) { e`, filepath.FromSlash("public/sect/doc2/index.html"), - "

a

\n\n

b
\nc\nd

\n\n

e

\n"}, - {"sect/doc3.md", `a + "

a

\n\n

b
\nc\nd

\n\n

e

\n", + }, + { + "sect/doc3.md", `a {{< b >}} {{< c >}} @@ -478,8 +481,10 @@ e`, e`, filepath.FromSlash("public/sect/doc3/index.html"), - "

a

\n\n

b
\nc

\n\nd\n\n

e

\n"}, - {"sect/doc4.md", `a + "

a

\n\n

b
\nc

\n\nd\n\n

e

\n", + }, + { + "sect/doc4.md", `a {{< b >}} {{< b >}} {{< b >}} @@ -497,23 +502,33 @@ e`, `, filepath.FromSlash("public/sect/doc4/index.html"), - "

a\nb\nb\nb\nb\nb

\n"}, + "

a\nb\nb\nb\nb\nb

\n", + }, // #2192 #2209: Shortcodes in markdown headers - {"sect/doc5.md", `# {{< b >}} + { + "sect/doc5.md", `# {{< b >}} ## {{% c %}}`, - filepath.FromSlash("public/sect/doc5/index.html"), `-hbhb">b`}, + filepath.FromSlash("public/sect/doc5/index.html"), `-hbhb">b`, + }, // #2223 pygments - {"sect/doc6.md", "\n```bash\nb = {{< b >}} c = {{% c %}}\n```\n", + { + "sect/doc6.md", "\n```bash\nb = {{< b >}} c = {{% c %}}\n```\n", filepath.FromSlash("public/sect/doc6/index.html"), - `b`}, + `b`, + }, // #2249 - {"sect/doc7.ad", `_Shortcodes:_ *b: {{< b >}} c: {{% c %}}*`, + { + "sect/doc7.ad", `_Shortcodes:_ *b: {{< b >}} c: {{% c %}}*`, filepath.FromSlash("public/sect/doc7/index.html"), - "
\n

Shortcodes: b: b c: c

\n
\n"}, - {"sect/doc8.rst", `**Shortcodes:** *b: {{< b >}} c: {{% c %}}*`, + "
\n

Shortcodes: b: b c: c

\n
\n", + }, + { + "sect/doc8.rst", `**Shortcodes:** *b: {{< b >}} c: {{% c %}}*`, filepath.FromSlash("public/sect/doc8/index.html"), - "
\n\n\n

Shortcodes: b: b c: c

\n
"}, - {"sect/doc9.mmark", ` + "
\n\n\n

Shortcodes: b: b c: c

\n
", + }, + { + "sect/doc9.mmark", ` --- menu: main: @@ -521,9 +536,11 @@ menu: --- **Shortcodes:** *b: {{< b >}} c: {{% c %}}*`, filepath.FromSlash("public/sect/doc9/index.html"), - "

Shortcodes: b: b c: c

\n"}, + "

Shortcodes: b: b c: c

\n", + }, // Issue #1229: Menus not available in shortcode. - {"sect/doc10.md", `--- + { + "sect/doc10.md", `--- menu: main: identifier: 'parent' @@ -532,22 +549,27 @@ tags: --- **Menus:** {{< menu >}}`, filepath.FromSlash("public/sect/doc10/index.html"), - "

Menus: 1

\n"}, + "

Menus: 1

\n", + }, // Issue #2323: Taxonomies not available in shortcode. - {"sect/doc11.md", `--- + { + "sect/doc11.md", `--- tags: - Bugs --- **Tags:** {{< tags >}}`, filepath.FromSlash("public/sect/doc11/index.html"), - "

Tags: 2

\n"}, - {"sect/doc12.md", `--- + "

Tags: 2

\n", + }, + { + "sect/doc12.md", `--- title: "Foo" --- {{% html-indented-v1 %}}`, "public/sect/doc12/index.html", - "

Hugo!

"}, + "

Hugo!

", + }, } temp := tests[:0] @@ -582,7 +604,6 @@ title: "Foo" templ.AddTemplate("_internal/shortcodes/tags.html", `{{ len .Page.Site.Taxonomies.tags }}`) return nil - } cfg, fs := newTestCfg() @@ -615,7 +636,6 @@ title: "Foo" }) } - } func TestShortcodeMultipleOutputFormats(t *testing.T) { @@ -741,11 +761,9 @@ CSV: {{< myShort >}} "Single CSV", "ShortCSV", ) - } func BenchmarkReplaceShortcodeTokens(b *testing.B) { - type input struct { in []byte replacements map[string]string @@ -764,8 +782,8 @@ func BenchmarkReplaceShortcodeTokens(b *testing.B) { {strings.Repeat("A ", 3000) + " HAHAHUGOSHORTCODE-1HBHB." + strings.Repeat("BC ", 1000) + " HAHAHUGOSHORTCODE-1HBHB.", map[string]string{"HAHAHUGOSHORTCODE-1HBHB": "Hello World"}, []byte(strings.Repeat("A ", 3000) + " Hello World." + strings.Repeat("BC ", 1000) + " Hello World.")}, } - var in = make([]input, b.N*len(data)) - var cnt = 0 + in := make([]input, b.N*len(data)) + cnt := 0 for i := 0; i < b.N; i++ { for _, this := range data { in[cnt] = input{[]byte(this.input), this.replacements, this.expect} @@ -780,7 +798,6 @@ func BenchmarkReplaceShortcodeTokens(b *testing.B) { currIn := in[cnt] cnt++ results, err := replaceShortcodeTokens(currIn.in, currIn.replacements) - if err != nil { b.Fatalf("[%d] failed: %s", i, err) continue @@ -790,7 +807,6 @@ func BenchmarkReplaceShortcodeTokens(b *testing.B) { } } - } } @@ -826,9 +842,12 @@ func TestReplaceShortcodeTokens(t *testing.T) { {"Hello

HAHAHUGOSHORTCODE-1HBHB. END

.", "PREFIX", map[string]string{"HAHAHUGOSHORTCODE-1HBHB": "World"}, "Hello

World. END

."}, {"

Hello HAHAHUGOSHORTCODE-1HBHB

. END.", "PREFIX", map[string]string{"HAHAHUGOSHORTCODE-1HBHB": "World"}, "

Hello World

. END."}, {"Hello

HAHAHUGOSHORTCODE-1HBHB12", "PREFIX", map[string]string{"HAHAHUGOSHORTCODE-1HBHB": "World"}, "Hello

World12"}, - {"Hello HAHAHUGOSHORTCODE-1HBHB. HAHAHUGOSHORTCODE-1HBHB-HAHAHUGOSHORTCODE-1HBHB HAHAHUGOSHORTCODE-1HBHB HAHAHUGOSHORTCODE-1HBHB HAHAHUGOSHORTCODE-1HBHB END", "P", map[string]string{"HAHAHUGOSHORTCODE-1HBHB": strings.Repeat("BC", 100)}, + { + "Hello HAHAHUGOSHORTCODE-1HBHB. HAHAHUGOSHORTCODE-1HBHB-HAHAHUGOSHORTCODE-1HBHB HAHAHUGOSHORTCODE-1HBHB HAHAHUGOSHORTCODE-1HBHB HAHAHUGOSHORTCODE-1HBHB END", "P", + map[string]string{"HAHAHUGOSHORTCODE-1HBHB": strings.Repeat("BC", 100)}, fmt.Sprintf("Hello %s. %s-%s %s %s %s END", - strings.Repeat("BC", 100), strings.Repeat("BC", 100), strings.Repeat("BC", 100), strings.Repeat("BC", 100), strings.Repeat("BC", 100), strings.Repeat("BC", 100))}, + strings.Repeat("BC", 100), strings.Repeat("BC", 100), strings.Repeat("BC", 100), strings.Repeat("BC", 100), strings.Repeat("BC", 100), strings.Repeat("BC", 100)), + }, } { results, err := replaceShortcodeTokens([]byte(this.input), this.replacements) @@ -848,7 +867,6 @@ func TestReplaceShortcodeTokens(t *testing.T) { } } - } func TestShortcodeGetContent(t *testing.T) { @@ -919,7 +937,6 @@ C-%s` "Single Content:

Logo:P1:|P2:logo.png/PNG logo|:P1: P1:|P2:docs1p1/

C-s1p1

\n|", "P2:docbp1/

C-bp1

", ) - } // https://github.com/gohugoio/hugo/issues/5833 @@ -978,7 +995,6 @@ SHORTCODE: {{< c >}} b.Build(BuildCfg{}) assert("Edit.") - } func TestShortcodePreserveOrder(t *testing.T) { @@ -1036,7 +1052,6 @@ weight: %d ordinal: 0 scratch ordinal: 1 scratch get ordinal: 0 ordinal: 2 scratch ordinal: 3 scratch get ordinal: 2 ordinal: 4 scratch ordinal: 5 scratch get ordinal: 4`) - } func TestShortcodeVariables(t *testing.T) { @@ -1074,7 +1089,6 @@ String: {{ . | safeHTML }} filepath.FromSlash("String: \"content/page.md:7:4\""), "Name: s1", ) - } func TestInlineShortcodes(t *testing.T) { @@ -1311,10 +1325,8 @@ title: "Hugo Rocks!" `, ) } - }) } - } // https://github.com/gohugoio/hugo/issues/6857 @@ -1334,5 +1346,4 @@ title: "No Inner!" err := b.BuildE(BuildCfg{}) b.Assert(err.Error(), qt.Contains, `failed to extract shortcode: shortcode "noinner" has no .Inner, yet a closing tag was provided`) - } diff --git a/hugolib/site.go b/hugolib/site.go index 05dd2307a..4175fecc2 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -251,7 +251,6 @@ func (s *Site) prepareInits() { }) s.init.prevNextInSection = init.Branch(func() (interface{}, error) { - var sections page.Pages s.home.treeRef.m.collectSectionsRecursiveIncludingSelf(pageMapQuery{Prefix: s.home.treeRef.key}, func(n *contentNode) { sections = append(sections, n.p) @@ -317,7 +316,6 @@ func (s *Site) prepareInits() { err := s.pageMap.assembleTaxonomies() return nil, err }) - } type siteRenderingContext struct { @@ -375,7 +373,8 @@ func (s *Site) isEnabled(kind string) bool { // reset returns a new Site prepared for rebuild. func (s *Site) reset() *Site { - return &Site{Deps: s.Deps, + return &Site{ + Deps: s.Deps, disabledKinds: s.disabledKinds, titleFunc: s.titleFunc, relatedDocsHandler: s.relatedDocsHandler.Clone(), @@ -394,7 +393,6 @@ func (s *Site) reset() *Site { PageCollections: s.PageCollections, siteCfg: s.siteCfg, } - } // newSite creates a new site with the given configuration. @@ -427,7 +425,6 @@ func newSite(cfg deps.DepsCfg) (*Site, error) { // This is a potentially ambigous situation. It may be correct. ignorableLogger.Errorsf(constants.ErrIDAmbigousDisableKindTaxonomy, `You have the value 'taxonomy' in the disabledKinds list. In Hugo 0.73.0 we fixed these to be what most people expect (taxonomy and term). But this also means that your site configuration may not do what you expect. If it is correct, you can suppress this message by following the instructions below.`) - } var ( @@ -566,7 +563,6 @@ But this also means that your site configuration may not do what you expect. If s.prepareInits() return s, nil - } // NewSite creates a new site with the given dependency configuration. @@ -623,7 +619,6 @@ func newSiteForLang(lang *langs.Language, withTemplate ...func(templ tpl.Templat cfg := deps.DepsCfg{WithTemplate: withTemplates, Cfg: lang} return NewSiteForCfg(cfg) - } // NewSiteForCfg creates a new site for the given configuration. @@ -635,7 +630,6 @@ func NewSiteForCfg(cfg deps.DepsCfg) (*Site, error) { return nil, err } return h.Sites[0], nil - } type SiteInfo struct { @@ -669,12 +663,10 @@ type SiteInfo struct { func (s *SiteInfo) Pages() page.Pages { return s.s.Pages() - } func (s *SiteInfo) RegularPages() page.Pages { return s.s.RegularPages() - } func (s *SiteInfo) AllPages() page.Pages { @@ -761,7 +753,6 @@ func (s *SiteInfo) ServerPort() int { // GoogleAnalytics is kept here for historic reasons. func (s *SiteInfo) GoogleAnalytics() string { return s.Config().Services.GoogleAnalytics.ID - } // DisqusShortname is kept here for historic reasons. @@ -1193,7 +1184,6 @@ func (s *Site) processPartial(config *BuildCfg, init func(config *BuildCfg) erro } return nil - } func (s *Site) process(config BuildCfg) (err error) { @@ -1206,11 +1196,9 @@ func (s *Site) process(config BuildCfg) (err error) { return } return err - } func (s *Site) render(ctx *siteRenderContext) (err error) { - if err := page.Clear(); err != nil { return err } @@ -1228,7 +1216,6 @@ func (s *Site) render(ctx *siteRenderContext) (err error) { return } } - } if err = s.renderPages(ctx); err != nil { @@ -1309,7 +1296,7 @@ func (s *Site) initializeSiteInfo() error { languagePrefix = "/" + lang.Lang } - var uglyURLs = func(p page.Page) bool { + uglyURLs := func(p page.Page) bool { return false } @@ -1388,7 +1375,6 @@ func (s *Site) readAndProcessContent(filenames ...string) error { } func (s *Site) getMenusFromConfig() navigation.Menus { - ret := navigation.Menus{} if menus := s.language.GetStringMap("menus"); menus != nil { @@ -1425,7 +1411,6 @@ func (s *Site) getMenusFromConfig() navigation.Menus { } func (s *SiteInfo) createNodeMenuEntryURL(in string) string { - if !strings.HasPrefix(in, "/") { return in } @@ -1471,15 +1456,16 @@ func (s *Site) assembleMenus() { return false } - me := navigation.MenuEntry{Identifier: id, - Name: p.LinkTitle(), - Weight: p.Weight(), - Page: p} + me := navigation.MenuEntry{ + Identifier: id, + Name: p.LinkTitle(), + Weight: p.Weight(), + Page: p, + } flat[twoD{sectionPagesMenu, me.KeyName()}] = &me return false }) - } // Add menu entries provided by pages @@ -1538,7 +1524,6 @@ func (s *Site) getLanguageTargetPathLang(alwaysInSubDir bool) string { // get any lanaguagecode to prefix the relative permalink with. func (s *Site) getLanguagePermalinkLang(alwaysInSubDir bool) string { - if !s.Info.IsMultiLingual() || s.h.IsMultihost() { return "" } @@ -1800,7 +1785,6 @@ func (s *Site) kindFromSections(sections []string) string { } return s.kindFromSectionPath(path.Join(sections...)) - } func (s *Site) kindFromSectionPath(sectionPath string) string { @@ -1823,7 +1807,6 @@ func (s *Site) newPage( parentbBucket *pagesMapBucket, kind, title string, sections ...string) *pageState { - m := map[string]interface{}{} if title != "" { m["title"] = title @@ -1838,7 +1821,6 @@ func (s *Site) newPage( kind: kind, sections: sections, }) - if err != nil { panic(err) } diff --git a/hugolib/siteJSONEncode_test.go b/hugolib/siteJSONEncode_test.go index ac0286ce2..94bac1873 100644 --- a/hugolib/siteJSONEncode_test.go +++ b/hugolib/siteJSONEncode_test.go @@ -41,5 +41,4 @@ Content. b.Build(BuildCfg{}) b.AssertFileContent("public/index.html", `"Date":"2019-02-28T00:00:00Z"`) - } diff --git a/hugolib/site_benchmark_new_test.go b/hugolib/site_benchmark_new_test.go index 1f16c97e5..228dbeb5d 100644 --- a/hugolib/site_benchmark_new_test.go +++ b/hugolib/site_benchmark_new_test.go @@ -118,7 +118,6 @@ See my [About](/about/) page for details. ` func getBenchmarkSiteNewTestCases() []siteBenchmarkTestcase { - pageContentWithCategory := func(size int, category string) string { return getBenchmarkTestDataPageContentForMarkdown(size, category, benchmarkMarkdownSnippets) } @@ -132,40 +131,41 @@ baseURL = "https://example.com" ` benchmarks := []siteBenchmarkTestcase{ - {"Bundle with image", func(b testing.TB) *sitesBuilder { - sb := newTestSitesBuilder(b).WithConfigFile("toml", config) - sb.WithContent("content/blog/mybundle/index.md", pageContent(1)) - sb.WithSunset("content/blog/mybundle/sunset1.jpg") + { + "Bundle with image", func(b testing.TB) *sitesBuilder { + sb := newTestSitesBuilder(b).WithConfigFile("toml", config) + sb.WithContent("content/blog/mybundle/index.md", pageContent(1)) + sb.WithSunset("content/blog/mybundle/sunset1.jpg") - return sb - }, + return sb + }, func(s *sitesBuilder) { s.AssertFileContent("public/blog/mybundle/index.html", "/blog/mybundle/sunset1.jpg") s.CheckExists("public/blog/mybundle/sunset1.jpg") - }, }, - {"Bundle with JSON file", func(b testing.TB) *sitesBuilder { - sb := newTestSitesBuilder(b).WithConfigFile("toml", config) - sb.WithContent("content/blog/mybundle/index.md", pageContent(1)) - sb.WithContent("content/blog/mybundle/mydata.json", `{ "hello": "world" }`) + { + "Bundle with JSON file", func(b testing.TB) *sitesBuilder { + sb := newTestSitesBuilder(b).WithConfigFile("toml", config) + sb.WithContent("content/blog/mybundle/index.md", pageContent(1)) + sb.WithContent("content/blog/mybundle/mydata.json", `{ "hello": "world" }`) - return sb - }, + return sb + }, func(s *sitesBuilder) { s.AssertFileContent("public/blog/mybundle/index.html", "Resources: application/json: /blog/mybundle/mydata.json") s.CheckExists("public/blog/mybundle/mydata.json") - }, }, - {"Tags and categories", func(b testing.TB) *sitesBuilder { - sb := newTestSitesBuilder(b).WithConfigFile("toml", ` + { + "Tags and categories", func(b testing.TB) *sitesBuilder { + sb := newTestSitesBuilder(b).WithConfigFile("toml", ` title = "Tags and Cats" baseURL = "https://example.com" `) - const pageTemplate = ` + const pageTemplate = ` --- title: "Some tags and cats" categories: ["caGR", "cbGR"] @@ -175,50 +175,51 @@ tags: ["taGR", "tbGR"] Some content. ` - for i := 1; i <= 100; i++ { - content := strings.Replace(pageTemplate, "GR", strconv.Itoa(i/3), -1) - sb.WithContent(fmt.Sprintf("content/page%d.md", i), content) - } + for i := 1; i <= 100; i++ { + content := strings.Replace(pageTemplate, "GR", strconv.Itoa(i/3), -1) + sb.WithContent(fmt.Sprintf("content/page%d.md", i), content) + } - return sb - }, + return sb + }, func(s *sitesBuilder) { s.AssertFileContent("public/page3/index.html", "/page3/|Permalink: https://example.com/page3/") s.AssertFileContent("public/tags/ta3/index.html", "|ta3|") }, }, - {"Canonify URLs", func(b testing.TB) *sitesBuilder { - sb := newTestSitesBuilder(b).WithConfigFile("toml", ` + { + "Canonify URLs", func(b testing.TB) *sitesBuilder { + sb := newTestSitesBuilder(b).WithConfigFile("toml", ` title = "Canon" baseURL = "https://example.com" canonifyURLs = true `) - for i := 1; i <= 100; i++ { - sb.WithContent(fmt.Sprintf("content/page%d.md", i), pageContent(i)) - } + for i := 1; i <= 100; i++ { + sb.WithContent(fmt.Sprintf("content/page%d.md", i), pageContent(i)) + } - return sb - }, + return sb + }, func(s *sitesBuilder) { s.AssertFileContent("public/page8/index.html", "https://example.com/about/") }, }, - {"Deep content tree", func(b testing.TB) *sitesBuilder { - return getBenchmarkSiteDeepContent(b) - }, + { + "Deep content tree", func(b testing.TB) *sitesBuilder { + return getBenchmarkSiteDeepContent(b) + }, func(s *sitesBuilder) { s.CheckExists("public/blog/mybundle/index.html") s.Assert(len(s.H.Sites), qt.Equals, 4) s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, len(s.H.Sites[1].RegularPages())) s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, 30) - }, }, - {"Many HTML templates", func(b testing.TB) *sitesBuilder { - - pageTemplateTemplate := ` + { + "Many HTML templates", func(b testing.TB) *sitesBuilder { + pageTemplateTemplate := ` @@ -243,7 +244,7 @@ canonifyURLs = true ` - sb := newTestSitesBuilder(b).WithConfigFile("toml", ` + sb := newTestSitesBuilder(b).WithConfigFile("toml", ` baseURL = "https://example.com" [languages] @@ -262,37 +263,36 @@ contentDir="content/sv" `) - createContent := func(dir, name string) { - sb.WithContent(filepath.Join("content", dir, name), pageContent(1)) - } + createContent := func(dir, name string) { + sb.WithContent(filepath.Join("content", dir, name), pageContent(1)) + } - for _, lang := range []string{"en", "fr", "no", "sv"} { - sb.WithTemplatesAdded(fmt.Sprintf("_default/single.%s.html", lang), pageTemplateTemplate) - sb.WithTemplatesAdded(fmt.Sprintf("_default/list.%s.html", lang), pageTemplateTemplate) + for _, lang := range []string{"en", "fr", "no", "sv"} { + sb.WithTemplatesAdded(fmt.Sprintf("_default/single.%s.html", lang), pageTemplateTemplate) + sb.WithTemplatesAdded(fmt.Sprintf("_default/list.%s.html", lang), pageTemplateTemplate) - for level := 1; level <= 5; level++ { - sectionDir := path.Join(lang, strings.Repeat("section/", level)) - createContent(sectionDir, "_index.md") - for i := 1; i <= 3; i++ { - leafBundleDir := path.Join(sectionDir, fmt.Sprintf("bundle%d", i)) - createContent(leafBundleDir, "index.md") + for level := 1; level <= 5; level++ { + sectionDir := path.Join(lang, strings.Repeat("section/", level)) + createContent(sectionDir, "_index.md") + for i := 1; i <= 3; i++ { + leafBundleDir := path.Join(sectionDir, fmt.Sprintf("bundle%d", i)) + createContent(leafBundleDir, "index.md") + } } } - } - return sb - }, + return sb + }, func(s *sitesBuilder) { s.CheckExists("public/blog/mybundle/index.html") s.Assert(len(s.H.Sites), qt.Equals, 4) s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, len(s.H.Sites[1].RegularPages())) s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, 15) - }, }, - {"Page collections", func(b testing.TB) *sitesBuilder { - - pageTemplateTemplate := ` + { + "Page collections", func(b testing.TB) *sitesBuilder { + pageTemplateTemplate := ` {{ if .IsNode }} {{ len .Paginator.Pages }} {{ end }} @@ -308,7 +308,7 @@ contentDir="content/sv" {{ with .Prev }}Prev: {{ .RelPermalink }}{{ end }} ` - sb := newTestSitesBuilder(b).WithConfigFile("toml", ` + sb := newTestSitesBuilder(b).WithConfigFile("toml", ` baseURL = "https://example.com" [languages] @@ -327,57 +327,55 @@ contentDir="content/sv" `) - sb.WithTemplates("index.html", pageTemplateTemplate) - sb.WithTemplates("_default/single.html", pageTemplateTemplate) - sb.WithTemplates("_default/list.html", pageTemplateTemplate) + sb.WithTemplates("index.html", pageTemplateTemplate) + sb.WithTemplates("_default/single.html", pageTemplateTemplate) + sb.WithTemplates("_default/list.html", pageTemplateTemplate) - r := rand.New(rand.NewSource(99)) + r := rand.New(rand.NewSource(99)) - createContent := func(dir, name string) { - var content string - if strings.Contains(name, "_index") { - content = pageContent(1) + createContent := func(dir, name string) { + var content string + if strings.Contains(name, "_index") { + content = pageContent(1) + } else { + content = pageContentWithCategory(1, fmt.Sprintf("category%d", r.Intn(5)+1)) + } - } else { - content = pageContentWithCategory(1, fmt.Sprintf("category%d", r.Intn(5)+1)) + sb.WithContent(filepath.Join("content", dir, name), content) } - sb.WithContent(filepath.Join("content", dir, name), content) - } - - createBundledFiles := func(dir string) { - sb.WithContent(filepath.Join("content", dir, "data.json"), `{ "hello": "world" }`) - for i := 1; i <= 3; i++ { - sb.WithContent(filepath.Join("content", dir, fmt.Sprintf("page%d.md", i)), pageContent(1)) + createBundledFiles := func(dir string) { + sb.WithContent(filepath.Join("content", dir, "data.json"), `{ "hello": "world" }`) + for i := 1; i <= 3; i++ { + sb.WithContent(filepath.Join("content", dir, fmt.Sprintf("page%d.md", i)), pageContent(1)) + } } - } - for _, lang := range []string{"en", "fr", "no", "sv"} { - for level := 1; level <= r.Intn(5)+1; level++ { - sectionDir := path.Join(lang, strings.Repeat("section/", level)) - createContent(sectionDir, "_index.md") - createBundledFiles(sectionDir) - for i := 1; i <= r.Intn(20)+1; i++ { - leafBundleDir := path.Join(sectionDir, fmt.Sprintf("bundle%d", i)) - createContent(leafBundleDir, "index.md") - createBundledFiles(path.Join(leafBundleDir, "assets1")) - createBundledFiles(path.Join(leafBundleDir, "assets1", "assets2")) + for _, lang := range []string{"en", "fr", "no", "sv"} { + for level := 1; level <= r.Intn(5)+1; level++ { + sectionDir := path.Join(lang, strings.Repeat("section/", level)) + createContent(sectionDir, "_index.md") + createBundledFiles(sectionDir) + for i := 1; i <= r.Intn(20)+1; i++ { + leafBundleDir := path.Join(sectionDir, fmt.Sprintf("bundle%d", i)) + createContent(leafBundleDir, "index.md") + createBundledFiles(path.Join(leafBundleDir, "assets1")) + createBundledFiles(path.Join(leafBundleDir, "assets1", "assets2")) + } } } - } - return sb - }, + return sb + }, func(s *sitesBuilder) { s.CheckExists("public/blog/mybundle/index.html") s.Assert(len(s.H.Sites), qt.Equals, 4) s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, 26) - }, }, - {"List terms", func(b testing.TB) *sitesBuilder { - - pageTemplateTemplate := ` + { + "List terms", func(b testing.TB) *sitesBuilder { + pageTemplateTemplate := `
    {{ range (.GetTerms "categories") }}
  • {{ .LinkTitle }}
  • @@ -385,46 +383,44 @@ contentDir="content/sv"
` - sb := newTestSitesBuilder(b).WithConfigFile("toml", ` + sb := newTestSitesBuilder(b).WithConfigFile("toml", ` baseURL = "https://example.com" `) - sb.WithTemplates("_default/single.html", pageTemplateTemplate) + sb.WithTemplates("_default/single.html", pageTemplateTemplate) - r := rand.New(rand.NewSource(99)) + r := rand.New(rand.NewSource(99)) - createContent := func(dir, name string) { - var content string - if strings.Contains(name, "_index") { - content = pageContent(1) - } else { - content = pageContentWithCategory(1, fmt.Sprintf("category%d", r.Intn(5)+1)) - sb.WithContent(filepath.Join("content", dir, name), content) + createContent := func(dir, name string) { + var content string + if strings.Contains(name, "_index") { + content = pageContent(1) + } else { + content = pageContentWithCategory(1, fmt.Sprintf("category%d", r.Intn(5)+1)) + sb.WithContent(filepath.Join("content", dir, name), content) + } } - } - for level := 1; level <= r.Intn(5)+1; level++ { - sectionDir := path.Join(strings.Repeat("section/", level)) - createContent(sectionDir, "_index.md") - for i := 1; i <= r.Intn(33); i++ { - leafBundleDir := path.Join(sectionDir, fmt.Sprintf("bundle%d", i)) - createContent(leafBundleDir, "index.md") + for level := 1; level <= r.Intn(5)+1; level++ { + sectionDir := path.Join(strings.Repeat("section/", level)) + createContent(sectionDir, "_index.md") + for i := 1; i <= r.Intn(33); i++ { + leafBundleDir := path.Join(sectionDir, fmt.Sprintf("bundle%d", i)) + createContent(leafBundleDir, "index.md") + } } - } - return sb - }, + return sb + }, func(s *sitesBuilder) { s.AssertFileContent("public/section/bundle8/index.html", `
  • category1
  • `) s.Assert(len(s.H.Sites), qt.Equals, 1) s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, 35) - }, }, } return benchmarks - } // Run the benchmarks below as tests. Mostly useful when adding new benchmark @@ -440,7 +436,6 @@ func TestBenchmarkSiteNew(b *testing.T) { b.Fatal(err) } bm.check(s) - }) } } @@ -465,7 +460,6 @@ Edited!!`, p.Title())) // We could probably optimize that case, but it's not trivial. b.Assert(int(counters.contentRenderCounter), qt.Equals, 4) b.AssertFileContent("public"+p.RelPermalink()+"index.html", "Edited!!") - } func BenchmarkSiteNew(b *testing.B) { diff --git a/hugolib/site_output.go b/hugolib/site_output.go index 6a630f4ea..c9c9f0ae5 100644 --- a/hugolib/site_output.go +++ b/hugolib/site_output.go @@ -51,7 +51,6 @@ func createDefaultOutputFormats(allFormats output.Formats) map[string]output.For } return m - } func createSiteOutputFormats(allFormats output.Formats, outputs map[string]interface{}, rssDisabled bool) (map[string]output.Formats, error) { @@ -84,7 +83,6 @@ func createSiteOutputFormats(allFormats output.Formats, outputs map[string]inter // This is legacy behaviour. We used to have both // a RSS page kind and output format. continue - } return nil, fmt.Errorf("failed to resolve output format %q from site config", format) } @@ -107,5 +105,4 @@ func createSiteOutputFormats(allFormats output.Formats, outputs map[string]inter } return outFormats, nil - } diff --git a/hugolib/site_output_test.go b/hugolib/site_output_test.go index c324be7dd..5a329942c 100644 --- a/hugolib/site_output_test.go +++ b/hugolib/site_output_test.go @@ -14,6 +14,7 @@ package hugolib import ( + "fmt" "strings" "testing" @@ -22,8 +23,6 @@ import ( "github.com/spf13/afero" - "fmt" - "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/output" "github.com/spf13/viper" @@ -40,7 +39,6 @@ func TestSiteWithPageOutputs(t *testing.T) { } func doTestSiteWithPageOutputs(t *testing.T, outputs []string) { - outputsStr := strings.Replace(fmt.Sprintf("%q", outputs), " ", ", ", -1) siteConfig := ` @@ -215,7 +213,6 @@ Len Pages: {{ .Kind }} {{ len .Site.RegularPages }} Page Number: {{ .Paginator.P b.Assert(home.HasShortcode("myShort"), qt.Equals, true) b.Assert(home.HasShortcode("doesNotExist"), qt.Equals, false) - } // Issue #3447 @@ -250,9 +247,8 @@ baseName = "feed" s := h.Sites[0] - //Issue #3450 + // Issue #3450 c.Assert(s.Info.RSSLink, qt.Equals, "http://example.com/blog/feed.xml") - } // Issue #3614 @@ -325,11 +321,9 @@ baseName = "customdelimbase" c.Assert(outputs.Get("DEF").RelPermalink(), qt.Equals, "/blog/defaultdelimbase.defd") c.Assert(outputs.Get("NOS").RelPermalink(), qt.Equals, "/blog/nosuffixbase") c.Assert(outputs.Get("CUS").RelPermalink(), qt.Equals, "/blog/customdelimbase_del") - } func TestCreateSiteOutputFormats(t *testing.T) { - t.Run("Basic", func(t *testing.T) { c := qt.New(t) @@ -358,7 +352,6 @@ func TestCreateSiteOutputFormats(t *testing.T) { c.Assert(outputs[kindSitemap], deepEqualsOutputFormats, output.Formats{output.SitemapFormat}) c.Assert(outputs[kindRobotsTXT], deepEqualsOutputFormats, output.Formats{output.RobotsTxtFormat}) c.Assert(outputs[kind404], deepEqualsOutputFormats, output.Formats{output.HTMLFormat}) - }) // Issue #4528 @@ -376,9 +369,7 @@ func TestCreateSiteOutputFormats(t *testing.T) { outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false) c.Assert(err, qt.IsNil) c.Assert(outputs[page.KindTaxonomy], deepEqualsOutputFormats, output.Formats{output.JSONFormat}) - }) - } func TestCreateSiteOutputFormatsInvalidConfig(t *testing.T) { @@ -432,7 +423,6 @@ func TestCreateSiteOutputFormatsCustomFormats(t *testing.T) { // https://github.com/gohugoio/hugo/issues/5849 func TestOutputFormatPermalinkable(t *testing.T) { - config := ` baseURL = "https://example.com" @@ -575,7 +565,6 @@ Output Formats: {{ len .OutputFormats }};{{ range .OutputFormats }}{{ .Name }};{ "This RelPermalink: /blog/html-base-nobase/", outputFormats, ) - } func TestSiteWithPageNoOutputs(t *testing.T) { @@ -625,5 +614,4 @@ WordCount: {{ .WordCount }} b.AssertFileContent("public/outputs-empty/index.html", "HTML:", "Word1. Word2.") b.AssertFileContent("public/outputs-string/index.html", "O1:", "Word1. Word2.") - } diff --git a/hugolib/site_render.go b/hugolib/site_render.go index 531d481f0..84293cfc0 100644 --- a/hugolib/site_render.go +++ b/hugolib/site_render.go @@ -53,7 +53,6 @@ func (s siteRenderContext) renderSingletonPages() bool { // 1 for all sites return s.sitesOutIdx == 0 - } // renderPages renders pages each corresponding to a markdown file. @@ -107,7 +106,6 @@ func pageRenderer( pages <-chan *pageState, results chan<- error, wg *sync.WaitGroup) { - defer wg.Done() for p := range pages { @@ -184,7 +182,6 @@ func (s *Site) logMissingLayout(name, layout, kind, outputFormat string) { // renderPaginator must be run after the owning Page has been rendered. func (s *Site) renderPaginator(p *pageState, templ tpl.Template) error { - paginatePath := s.Cfg.GetString("paginatePath") d := p.targetPathDescriptor @@ -234,7 +231,6 @@ func (s *Site) render404() error { }, output.HTMLFormat, ) - if err != nil { return err } @@ -269,10 +265,10 @@ func (s *Site) renderSitemap() error { kind: kindSitemap, urlPaths: pagemeta.URLPath{ URL: s.siteCfg.sitemap.Filename, - }}, + }, + }, output.HTMLFormat, ) - if err != nil { return err } @@ -305,7 +301,6 @@ func (s *Site) renderRobotsTXT() error { }, }, output.RobotsTxtFormat) - if err != nil { return err } @@ -317,7 +312,6 @@ func (s *Site) renderRobotsTXT() error { templ := s.lookupLayouts("robots.txt", "_default/robots.txt", "_internal/_default/robots.txt") return s.renderAndWritePage(&s.PathSpec.ProcessingStats.Pages, "Robots Txt", p.targetPaths().TargetFilename, p, templ) - } // renderAliases renders shell pages that simply have a redirect in the header. @@ -385,7 +379,6 @@ func (s *Site) renderAliases() error { // renderMainLanguageRedirect creates a redirect to the main language home, // depending on if it lives in sub folder (e.g. /en) or not. func (s *Site) renderMainLanguageRedirect() error { - if !s.h.multilingual.enabled() || s.h.IsMultihost() { // No need for a redirect return nil diff --git a/hugolib/site_sections_test.go b/hugolib/site_sections_test.go index 81196be7f..2a4c39533 100644 --- a/hugolib/site_sections_test.go +++ b/hugolib/site_sections_test.go @@ -25,7 +25,6 @@ import ( ) func TestNestedSections(t *testing.T) { - var ( c = qt.New(t) cfg, fs = newTestCfg() @@ -139,7 +138,6 @@ PAG|{{ .Title }}|{{ $sect.InSection . }} // > b,c c.Assert(getPage(p, "/empty1/b"), qt.IsNil) // No _index.md page. c.Assert(getPage(p, "/empty1/b/c"), qt.Not(qt.IsNil)) - }}, {"empty2", func(c *qt.C, p page.Page) { // > b,c,d where b and d have _index.md files. @@ -157,7 +155,6 @@ PAG|{{ .Title }}|{{ $sect.InSection . }} c.Assert(cp.Eq(d), qt.Equals, false) c.Assert(cp.Eq(cp), qt.Equals, true) c.Assert(cp.Eq("asdf"), qt.Equals, false) - }}, {"empty3", func(c *qt.C, p page.Page) { // b,c,d with regular page in b @@ -166,7 +163,6 @@ PAG|{{ .Title }}|{{ $sect.InSection . }} e3 := getPage(p, "/empty3/b/empty3") c.Assert(e3, qt.Not(qt.IsNil)) c.Assert(e3.File().LogicalName(), qt.Equals, "empty3.md") - }}, {"empty3", func(c *qt.C, p page.Page) { xxx := getPage(p, "/empty3/nil") @@ -234,7 +230,6 @@ PAG|{{ .Title }}|{{ $sect.InSection . }} } c.Assert(p.Eq(p.CurrentSection()), qt.Equals, true) - }}, {"l1,l2_2", func(c *qt.C, p page.Page) { c.Assert(p.Title(), qt.Equals, "T22_-1") @@ -278,7 +273,6 @@ PAG|{{ .Title }}|{{ $sect.InSection . }} isAncestor, err = nilp.IsAncestor(l1) c.Assert(err, qt.IsNil) c.Assert(isAncestor, qt.Equals, false) - }}, {"perm a,link", func(c *qt.C, p page.Page) { c.Assert(p.Title(), qt.Equals, "T9_-1") @@ -290,7 +284,6 @@ PAG|{{ .Title }}|{{ $sect.InSection . }} last := p.Pages()[3] c.Assert(last.RelPermalink(), qt.Equals, "/perm-a/link/t1_5/") - }}, } @@ -335,7 +328,6 @@ PAG|{{ .Title }}|{{ $sect.InSection . }} c.Assert(sectionWithSpace.RelPermalink(), qt.Equals, "/spaces-in-section/") th.assertFileContent("public/l1/l2/page/2/index.html", "L1/l2-IsActive: true", "PAG|T2_3|true") - } func TestNextInSectionNested(t *testing.T) { @@ -380,5 +372,4 @@ Next: {{ with .NextInSection }}{{ .RelPermalink }}{{ end }}| "Prev: /blog/cool/cool2/|", "Next: |") b.AssertFileContent("public/blog/cool/cool2/index.html", "Prev: |", "Next: /blog/cool/cool1/|") - } diff --git a/hugolib/site_stats_test.go b/hugolib/site_stats_test.go index 9c7bb240d..df1f64840 100644 --- a/hugolib/site_stats_test.go +++ b/hugolib/site_stats_test.go @@ -84,7 +84,8 @@ aliases: [/Ali%d] stats := []*helpers.ProcessingStats{ h.Sites[0].PathSpec.ProcessingStats, - h.Sites[1].PathSpec.ProcessingStats} + h.Sites[1].PathSpec.ProcessingStats, + } stats[0].Table(ioutil.Discard) stats[1].Table(ioutil.Discard) @@ -94,5 +95,4 @@ aliases: [/Ali%d] helpers.ProcessingStatsTable(&buff, stats...) c.Assert(buff.String(), qt.Contains, "Pages | 19 | 6") - } diff --git a/hugolib/site_test.go b/hugolib/site_test.go index a2b3a0451..922563420 100644 --- a/hugolib/site_test.go +++ b/hugolib/site_test.go @@ -47,7 +47,6 @@ func TestRenderWithInvalidTemplate(t *testing.T) { withTemplate := createWithTemplateFromNameValues("missing", templateMissingFunc) buildSingleSiteExpected(t, true, false, deps.DepsCfg{Fs: fs, Cfg: cfg, WithTemplate: withTemplate}, BuildCfg{}) - } func TestDraftAndFutureRender(t *testing.T) { @@ -70,7 +69,6 @@ func TestDraftAndFutureRender(t *testing.T) { for _, src := range sources { writeSource(t, fs, filepath.Join("content", src[0]), src[1]) - } return buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) @@ -105,7 +103,6 @@ func TestDraftAndFutureRender(t *testing.T) { if len(s.RegularPages()) != 4 { t.Fatal("Drafts or Future posts not included as expected") } - } func TestFutureExpirationRender(t *testing.T) { @@ -121,7 +118,6 @@ func TestFutureExpirationRender(t *testing.T) { for _, src := range sources { writeSource(t, fs, filepath.Join("content", src[0]), src[1]) - } return buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) @@ -174,7 +170,6 @@ func TestPageWithUnderScoreIndexInFilename(t *testing.T) { s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) c.Assert(len(s.RegularPages()), qt.Equals, 1) - } // Issue #957 @@ -188,7 +183,6 @@ func TestCrossrefs(t *testing.T) { } func doTestCrossrefs(t *testing.T, relative, uglyURLs bool) { - c := qt.New(t) baseURL := "http://foo/bar" @@ -257,7 +251,8 @@ THE END.`, refShortcode), deps.DepsCfg{ Fs: fs, Cfg: cfg, - WithTemplate: createWithTemplateFromNameValues("_default/single.html", "{{.Content}}")}, + WithTemplate: createWithTemplateFromNameValues("_default/single.html", "{{.Content}}"), + }, BuildCfg{}) c.Assert(len(s.RegularPages()), qt.Equals, 4) @@ -276,9 +271,7 @@ THE END.`, refShortcode), for _, test := range tests { th.assertFileContent(test.doc, test.expected) - } - } // Issue #939 @@ -291,7 +284,6 @@ func TestShouldAlwaysHaveUglyURLs(t *testing.T) { } func doTestShouldAlwaysHaveUglyURLs(t *testing.T, uglyURLs bool) { - cfg, fs := newTestCfg() c := qt.New(t) @@ -299,7 +291,8 @@ func doTestShouldAlwaysHaveUglyURLs(t *testing.T, uglyURLs bool) { cfg.Set("baseURL", "http://auth/bub") cfg.Set("blackfriday", map[string]interface{}{ - "plainIDAnchors": true}) + "plainIDAnchors": true, + }) cfg.Set("uglyURLs", uglyURLs) @@ -351,7 +344,6 @@ func doTestShouldAlwaysHaveUglyURLs(t *testing.T, uglyURLs bool) { t.Errorf("%s content expected:\n%q\ngot:\n%q", test.doc, test.expected, content) } } - } // Issue #3355 @@ -418,7 +410,6 @@ Main section page: {{ .RelPermalink }} } else { b.AssertFileContent("public/index.html", "mainSections: [blog]", "Main section page: /blog/page3/") } - }) } } @@ -501,7 +492,6 @@ func doTestSectionNaming(t *testing.T, canonify, uglify, pluralize bool) { th.assertFileContent(filepath.Join("public", test.doc), test.expected) } - } func TestAbsURLify(t *testing.T) { @@ -521,7 +511,6 @@ func TestAbsURLify(t *testing.T) { for _, src := range sources { writeSource(t, fs, filepath.Join("content", src[0]), src[1]) - } writeSource(t, fs, filepath.Join("layouts", "blue/single.html"), templateWithURLAbs) @@ -608,7 +597,6 @@ func TestOrderedPages(t *testing.T) { for _, src := range weightedSources { writeSource(t, fs, filepath.Join("content", src[0]), src[1]) - } s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) @@ -895,7 +883,6 @@ func setupLinkingMockSite(t *testing.T) *Site { map[string]interface{}{}) writeSourcesToSource(t, "content", fs, sources...) return buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) - } func TestRefLinking(t *testing.T) { @@ -945,14 +932,13 @@ func TestRefLinking(t *testing.T) { // try to confuse parsing {"embedded.dot.md", "", true, "/level2/level3/embedded.dot/"}, - //test empty link, as well as fragment only link + // test empty link, as well as fragment only link {"", "", true, ""}, } { - t.Run(fmt.Sprint(i), func(t *testing.T) { checkLinkCase(site, test.link, currentPage, test.relative, test.outputFormat, test.expected, t, i) - //make sure fragment links are also handled + // make sure fragment links are also handled checkLinkCase(site, test.link+"#intro", currentPage, test.relative, test.outputFormat, test.expected+"#intro", t, i) }) } @@ -983,11 +969,9 @@ func TestRefIssues(t *testing.T) { b.AssertFileContent("public/post/b1/index.html", `Content:

    Ref: http://example.com/post/b2/

    `) b.AssertFileContent("public/post/nested-a/content-a/index.html", `Content: http://example.com/post/nested-b/content-b/`) - } func TestClassCollector(t *testing.T) { - for _, minify := range []bool{false, true} { t.Run(fmt.Sprintf("minify-%t", minify), func(t *testing.T) { statsFilename := "hugo_stats.json" @@ -1053,9 +1037,7 @@ Some text. } } `) - }) - } } @@ -1102,7 +1084,6 @@ ABC. `) for _, lang := range []string{"en", "nb", "no", "sv"} { - for i := 100; i <= 999; i++ { b.WithContent(fmt.Sprintf("p%d.%s.md", i, lang), fmt.Sprintf("---\ntitle: p%s%d\n---", lang, i)) } @@ -1126,5 +1107,4 @@ ABC. b.Assert(els.Tags, qt.HasLen, 9) b.Assert(els.IDs, qt.HasLen, 1) } - } diff --git a/hugolib/site_url_test.go b/hugolib/site_url_test.go index c51285eb4..d668095b9 100644 --- a/hugolib/site_url_test.go +++ b/hugolib/site_url_test.go @@ -15,13 +15,12 @@ package hugolib import ( "fmt" + "html/template" "path/filepath" "testing" "github.com/gohugoio/hugo/resources/page" - "html/template" - qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" ) @@ -52,7 +51,8 @@ func TestShouldNotAddTrailingSlashToBaseURL(t *testing.T) { {"http://base.com/", "http://base.com/"}, {"http://base.com/sub/", "http://base.com/sub/"}, {"http://base.com/sub", "http://base.com/sub"}, - {"http://base.com", "http://base.com"}} { + {"http://base.com", "http://base.com"}, + } { cfg, fs := newTestCfg() cfg.Set("baseURL", this.in) @@ -184,5 +184,4 @@ Do not go gentle into that good night. c.Assert(sect1.RelPermalink(), qt.Equals, "/ss1/") th.assertFileContent(filepath.Join("public", "ss1", "index.html"), "P1|URL: /ss1/|Next: /ss1/page/2/") th.assertFileContent(filepath.Join("public", "ss1", "page", "2", "index.html"), "P2|URL: /ss1/page/2/|Next: /ss1/page/3/") - } diff --git a/hugolib/sitemap_test.go b/hugolib/sitemap_test.go index 27fbf11d8..7302f6e62 100644 --- a/hugolib/sitemap_test.go +++ b/hugolib/sitemap_test.go @@ -14,9 +14,8 @@ package hugolib import ( - "testing" - "reflect" + "testing" qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/config" @@ -43,7 +42,6 @@ func TestSitemapOutput(t *testing.T) { } func doTestSitemapOutput(t *testing.T, internal bool) { - c := qt.New(t) cfg, fs := newTestCfg() cfg.Set("baseURL", "http://auth/bub/") @@ -82,7 +80,6 @@ func doTestSitemapOutput(t *testing.T, internal bool) { content := readDestination(th, th.Fs, outputSitemap) c.Assert(content, qt.Not(qt.Contains), "404") - } func TestParseSitemap(t *testing.T) { @@ -99,12 +96,10 @@ func TestParseSitemap(t *testing.T) { if !reflect.DeepEqual(expected, result) { t.Errorf("Got \n%v expected \n%v", result, expected) } - } // https://github.com/gohugoio/hugo/issues/5910 func TestSitemapOutputFormats(t *testing.T) { - b := newTestSitesBuilder(t).WithSimpleConfigFile() b.WithContent("blog/html-amp.md", ` diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go index 4eeb92e06..dba4f4856 100644 --- a/hugolib/taxonomy_test.go +++ b/hugolib/taxonomy_test.go @@ -16,13 +16,12 @@ package hugolib import ( "fmt" "path/filepath" - - "github.com/gohugoio/hugo/resources/page" - "reflect" "strings" "testing" + "github.com/gohugoio/hugo/resources/page" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" @@ -73,7 +72,6 @@ func TestTaxonomiesWithAndWithoutContentFile(t *testing.T) { } func doTestTaxonomiesWithAndWithoutContentFile(t *testing.T, uglyURLs bool) { - siteConfig := ` baseURL = "http://example.com/blog" uglyURLs = %t @@ -202,7 +200,6 @@ permalinkeds: // Issue #2977 b.AssertFileContent(pathFunc("public/empties/index.html"), "Taxonomy Term Page", "Empties") - } // https://github.com/gohugoio/hugo/issues/5513 @@ -285,7 +282,6 @@ title: "This is S3s" b.AssertFileContent("public/news/categories/index.html", "Taxonomy Term Page 1|News/Categories|Hello|https://example.com/news/categories/|") b.AssertFileContent("public/t1/t2/t3s/index.html", "Taxonomy Term Page 1|T1/T2/T3s|Hello|https://example.com/t1/t2/t3s/|") b.AssertFileContent("public/s1/s2/s3s/index.html", "Taxonomy Term Page 1|This is S3s|Hello|https://example.com/s1/s2/s3s/|") - } // https://github.com/gohugoio/hugo/issues/5719 @@ -329,7 +325,6 @@ Content. b.AssertFileContent("public/index.html", `
  • Hugo Rocks! 10
  • `) b.AssertFileContent("public/categories/index.html", `
  • This is Cool 10
  • `) b.AssertFileContent("public/tags/index.html", `
  • Rocks I say! 10
  • `) - } // Issue 6213 @@ -361,7 +356,6 @@ categories: ["regular"] dra, _ := s.getPageNew(nil, "categories/draft") b.Assert(reg, qt.Not(qt.IsNil)) b.Assert(dra, qt.IsNil) - } func TestTaxonomiesIndexDraft(t *testing.T) { @@ -398,7 +392,6 @@ Content. b.AssertFileContentFn("public/index.html", func(s string) bool { return !strings.Contains(s, "categories") }) - } // https://github.com/gohugoio/hugo/issues/6927 @@ -442,7 +435,6 @@ NO HOME FOR YOU b.Assert(b.CheckExists("public/index.html"), qt.Equals, false) b.Assert(b.CheckExists("public/categories/index.html"), qt.Equals, false) b.Assert(b.CheckExists("public/posts/index.html"), qt.Equals, false) - } // https://github.com/gohugoio/hugo/issues/6173 @@ -470,7 +462,6 @@ categories: ["funny"] b.AssertFileContent("public/categories/index.html", `Resource: /categories/data.json|application/json`) b.AssertFileContent("public/categories/funny/index.html", `Resource: /categories/funny/funnydata.json|application/json`) - } func TestTaxonomiesRemoveOne(t *testing.T) { @@ -528,7 +519,6 @@ Len funny: 2 Cats:|/p2/| Funny:|/p1/| Funny:|/p2/|`) - } //https://github.com/gohugoio/hugo/issues/6590 @@ -579,7 +569,6 @@ Len categories.funny: 2 categories.funny:|/| categories.funny:|/blog/p1/| `) - } func TestTaxonomiesPageCollections(t *testing.T) { @@ -653,7 +642,6 @@ Category Paginator /categories/birds/|/categories/cats/|/categories/dogs/|/categ b.AssertFileContent("public/404.html", "\n404 Terms: :END\n\t") b.AssertFileContent("public/categories/funny/index.xml", `http://example.com/section/p1/`) b.AssertFileContent("public/categories/index.xml", `http://example.com/categories/funny/`) - } func TestTaxonomiesDirectoryOverlaps(t *testing.T) { @@ -705,5 +693,4 @@ abcdefgs: {{ template "print-page" $abcdefgs }}|IsAncestor: {{ $abcdefgs.IsAnces abc: /abcdefgs/abc/|abc|term|Parent: /abcdefgs/|CurrentSection: /abcdefgs/|FirstSection: /|IsAncestor: false|IsDescendant: true abcdefgs: /abcdefgs/|Abcdefgs|taxonomy|Parent: /|CurrentSection: /|FirstSection: /|IsAncestor: true|IsDescendant: false `) - } diff --git a/hugolib/template_test.go b/hugolib/template_test.go index 39f1b9e2e..769bcd4e6 100644 --- a/hugolib/template_test.go +++ b/hugolib/template_test.go @@ -51,7 +51,6 @@ func TestTemplateLookupOrder(t *testing.T) { func(t *testing.T) { writeSource(t, fs, filepath.Join("layouts", "section", "sect1-baseof.html"), `Base: {{block "main" .}}block{{end}}`) writeSource(t, fs, filepath.Join("layouts", "section", "sect1.html"), `{{define "main"}}sect{{ end }}`) - }, func(t *testing.T) { th.assertFileContent(filepath.Join("public", "sect1", "index.html"), "Base: sect") @@ -62,7 +61,6 @@ func TestTemplateLookupOrder(t *testing.T) { func(t *testing.T) { writeSource(t, fs, filepath.Join("layouts", "baseof.html"), `Base: {{block "main" .}}block{{end}}`) writeSource(t, fs, filepath.Join("layouts", "index.html"), `{{define "main"}}index{{ end }}`) - }, func(t *testing.T) { th.assertFileContent(filepath.Join("public", "index.html"), "Base: index") @@ -73,7 +71,6 @@ func TestTemplateLookupOrder(t *testing.T) { func(t *testing.T) { writeSource(t, fs, filepath.Join("layouts", "_default", "list-baseof.html"), `Base: {{block "main" .}}block{{end}}`) writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`) - }, func(t *testing.T) { th.assertFileContent(filepath.Join("public", "sect1", "index.html"), "Base: list") @@ -84,7 +81,6 @@ func TestTemplateLookupOrder(t *testing.T) { func(t *testing.T) { writeSource(t, fs, filepath.Join("layouts", "_default", "baseof.html"), `Base: {{block "main" .}}block{{end}}`) writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`) - }, func(t *testing.T) { th.assertFileContent(filepath.Join("public", "sect1", "index.html"), "Base: list") @@ -97,7 +93,6 @@ func TestTemplateLookupOrder(t *testing.T) { writeSource(t, fs, filepath.Join("layouts", "section", "sect1-baseof.html"), `Base: {{block "main" .}}block{{end}}`) writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "section", "sect-baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`) writeSource(t, fs, filepath.Join("layouts", "section", "sect1.html"), `{{define "main"}}sect{{ end }}`) - }, func(t *testing.T) { th.assertFileContent(filepath.Join("public", "sect1", "index.html"), "Base: sect") @@ -109,7 +104,6 @@ func TestTemplateLookupOrder(t *testing.T) { cfg.Set("theme", "mytheme") writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "section", "sect1-baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`) writeSource(t, fs, filepath.Join("layouts", "section", "sect1.html"), `{{define "main"}}sect{{ end }}`) - }, func(t *testing.T) { th.assertFileContent(filepath.Join("public", "sect1", "index.html"), "Base Theme: sect") @@ -123,7 +117,6 @@ func TestTemplateLookupOrder(t *testing.T) { writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "_default", "baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`) writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`) writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "index.html"), `{{define "main"}}index{{ end }}`) - }, func(t *testing.T) { th.assertFileContent(filepath.Join("public", "sect1", "index.html"), "Base: list") @@ -136,7 +129,6 @@ func TestTemplateLookupOrder(t *testing.T) { cfg.Set("theme", "mytheme") writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "_default", "baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`) writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`) - }, func(t *testing.T) { th.assertFileContent(filepath.Join("public", "sect1", "index.html"), "Base Theme: list") @@ -158,7 +150,6 @@ func TestTemplateLookupOrder(t *testing.T) { // sect2 with list template in /section writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "section", "sect2.html"), `sect2 list`) - }, func(t *testing.T) { th.assertFileContent(filepath.Join("public", "sect1", "index.html"), "sect list") @@ -170,7 +161,6 @@ func TestTemplateLookupOrder(t *testing.T) { // Issue #2995 "Test section list and single template selection with base template", func(t *testing.T) { - writeSource(t, fs, filepath.Join("layouts", "_default", "baseof.html"), `Base Default: {{block "main" .}}block{{end}}`) writeSource(t, fs, filepath.Join("layouts", "sect1", "baseof.html"), `Base Sect1: {{block "main" .}}block{{end}}`) writeSource(t, fs, filepath.Join("layouts", "section", "sect2-baseof.html"), `Base Sect2: {{block "main" .}}block{{end}}`) @@ -183,7 +173,6 @@ func TestTemplateLookupOrder(t *testing.T) { // sect2 with list template in /section writeSource(t, fs, filepath.Join("layouts", "section", "sect2.html"), `{{define "main"}}sect2 list{{ end }}`) - }, func(t *testing.T) { th.assertFileContent(filepath.Join("public", "sect1", "index.html"), "Base Sect1", "sect1 list") @@ -214,7 +203,7 @@ Some content this.setup(t) buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) - //helpers.PrintFs(s.BaseFs.Layouts.Fs, "", os.Stdout) + // helpers.PrintFs(s.BaseFs.Layouts.Fs, "", os.Stdout) this.assert(t) }) @@ -223,7 +212,6 @@ Some content // https://github.com/gohugoio/hugo/issues/4895 func TestTemplateBOM(t *testing.T) { - b := newTestSitesBuilder(t).WithSimpleConfigFile() bom := "\ufeff" @@ -242,7 +230,6 @@ Page Content b.CreateSites().Build(BuildCfg{}) b.AssertFileContent("public/page/index.html", "Base: Hi!?") - } func TestTemplateManyBaseTemplates(t *testing.T) { @@ -278,7 +265,6 @@ Base %d: {{ block "main" . }}FOO{{ end }} id := i + 1 b.AssertFileContent(fmt.Sprintf("public/page%d/index.html", id), fmt.Sprintf(`Base %d: %d`, id, id)) } - } // https://github.com/gohugoio/hugo/issues/6790 @@ -315,7 +301,6 @@ title: The Page b.AssertFileContent("public/blog/p1/index.html", `single`) b.AssertFileContent("public/blog/index.html", `list`) - } // https://github.com/gohugoio/hugo/issues/6816 @@ -336,7 +321,6 @@ func TestTemplateBaseWithComment(t *testing.T) { b.Build(BuildCfg{}) b.AssertFileContent("public/index.html", `Base: Bonjour`) - } func TestTemplateLookupSite(t *testing.T) { @@ -389,13 +373,10 @@ title: My Page b.AssertFileContent("public/fr/index.html", `Baseof fr: Main Home Fr`) b.AssertFileContent("public/en/mysection/index.html", `Baseof mysection: Main Default List`) b.AssertFileContent("public/en/mysection/p1/index.html", `Baseof mysection: Main Default Single`) - }) - } func TestTemplateFuncs(t *testing.T) { - b := newTestSitesBuilder(t).WithDefaultMultiSiteConfig() homeTpl := `Site: {{ site.Language.Lang }} / {{ .Site.Language.Lang }} / {{ site.BaseURL }} @@ -419,11 +400,9 @@ Hugo: {{ hugo.Generator }} "Sites: en", "Hugo: