summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-12-18 17:41:15 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-12-18 19:51:26 +0100
commit8adba648cc130a97d2c814c65aa8396044c251fd (patch)
tree95415853e28ee83e0342cc55944f3bc16d746f4f /hugolib
parent6f13430d4a3b0d8b196f13958fbfb6478be1f3aa (diff)
all: Remove unused code
Using x/tools/cmd/deadcode
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/filesystems/basefs.go14
-rw-r--r--hugolib/hugo_modules_test.go30
-rw-r--r--hugolib/hugo_sites.go17
-rw-r--r--hugolib/page.go4
-rw-r--r--hugolib/shortcode.go11
-rw-r--r--hugolib/template_test.go5
-rw-r--r--hugolib/testhelpers_test.go37
7 files changed, 19 insertions, 99 deletions
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go
index d5c94799d..a7c2a6271 100644
--- a/hugolib/filesystems/basefs.go
+++ b/hugolib/filesystems/basefs.go
@@ -57,7 +57,6 @@ var filePathSeparator = string(filepath.Separator)
// to underline that even if they can be composites, they all have a base path set to a specific
// resource folder, e.g "/my-project/content". So, no absolute filenames needed.
type BaseFs struct {
-
// SourceFilesystems contains the different source file systems.
*SourceFilesystems
@@ -180,7 +179,6 @@ func (b *BaseFs) AbsProjectContentDir(filename string) (string, string, error) {
return filename, filepath.Join(meta.Filename, filename), nil
}
}
-
}
return "", "", fmt.Errorf("could not determine content directory for %q", filename)
@@ -301,7 +299,6 @@ func (s SourceFilesystems) ContentStaticAssetFs(lang string) afero.Fs {
},
},
)
-
}
// StaticFs returns the static filesystem for the given language.
@@ -666,8 +663,8 @@ func (b *sourceFilesystemsBuilder) isStaticMount(mnt modules.Mount) bool {
func (b *sourceFilesystemsBuilder) createOverlayFs(
collector *filesystemsCollector,
- mounts []mountsDescriptor) error {
-
+ mounts []mountsDescriptor,
+) error {
if len(mounts) == 0 {
appendNopIfEmpty := func(ofs *overlayfs.OverlayFs) *overlayfs.OverlayFs {
if ofs.NumFilesystems() > 0 {
@@ -857,13 +854,6 @@ func (c *filesystemsCollector) addDir(rfs *hugofs.RootMappingFs, componentFolder
}
}
-func (c *filesystemsCollector) reverseFis(fis []hugofs.FileMetaInfo) {
- for i := len(fis)/2 - 1; i >= 0; i-- {
- opp := len(fis) - 1 - i
- fis[i], fis[opp] = fis[opp], fis[i]
- }
-}
-
type mountsDescriptor struct {
modules.Module
dir string
diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go
index 88a0c3ec6..44500cae5 100644
--- a/hugolib/hugo_modules_test.go
+++ b/hugolib/hugo_modules_test.go
@@ -63,11 +63,11 @@ path="github.com/gohugoio/hugoTestModule2"
b := newTestSitesBuilder(t)
tempDir := t.TempDir()
workingDir := filepath.Join(tempDir, "myhugosite")
- b.Assert(os.MkdirAll(workingDir, 0777), qt.IsNil)
+ b.Assert(os.MkdirAll(workingDir, 0o777), qt.IsNil)
cfg := config.New()
cfg.Set("workingDir", workingDir)
cfg.Set("publishDir", "public")
- b.Fs = hugofs.NewDefaultOld(cfg)
+ b.Fs = hugofs.NewDefault(cfg)
b.WithWorkingDir(workingDir).WithConfigFile("toml", createConfig(workingDir, moduleOpts))
b.WithTemplates(
"index.html", `
@@ -352,7 +352,7 @@ ignoreVendorPaths = %q
b := newTestSitesBuilder(t)
// Need to use OS fs for this.
- b.Fs = hugofs.NewDefaultOld(v)
+ b.Fs = hugofs.NewDefault(v)
b.WithWorkingDir(workingDir).WithConfigFile("toml", config)
b.WithContent("page.md", `
@@ -683,11 +683,11 @@ Data: {{ .Site.Data }}
createDirsAndFiles := func(baseDir string) {
for _, dir := range files.ComponentFolders {
realDir := filepath.Join(baseDir, dir, "real")
- c.Assert(os.MkdirAll(realDir, 0777), qt.IsNil)
- c.Assert(afero.WriteFile(fs.Source, filepath.Join(realDir, "data.toml"), []byte("[hello]\nother = \"hello\""), 0777), qt.IsNil)
+ c.Assert(os.MkdirAll(realDir, 0o777), qt.IsNil)
+ c.Assert(afero.WriteFile(fs.Source, filepath.Join(realDir, "data.toml"), []byte("[hello]\nother = \"hello\""), 0o777), qt.IsNil)
}
- c.Assert(afero.WriteFile(fs.Source, filepath.Join(baseDir, "layouts", "index.html"), []byte(homeTemplate), 0777), qt.IsNil)
+ c.Assert(afero.WriteFile(fs.Source, filepath.Join(baseDir, "layouts", "index.html"), []byte(homeTemplate), 0o777), qt.IsNil)
}
// Create project dirs and files.
@@ -849,7 +849,7 @@ workingDir = %q
cfg.Set("workingDir", workingDir)
cfg.Set("publishDir", "public")
- b.Fs = hugofs.NewDefaultOld(cfg)
+ b.Fs = hugofs.NewDefault(cfg)
b.WithWorkingDir(workingDir).WithConfigFile("toml", tomlConfig)
b.WithTemplatesAdded("index.html", `
@@ -877,8 +877,8 @@ workingDir = %q
<a href="{{ $link | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if $isRemote }} target="_blank"{{ end }}>{{ .Text | safeHTML }}</a>
`)
- os.Mkdir(filepath.Join(workingDir, "mycontent"), 0777)
- os.Mkdir(filepath.Join(workingDir, "mycontent", "mybundle"), 0777)
+ os.Mkdir(filepath.Join(workingDir, "mycontent"), 0o777)
+ os.Mkdir(filepath.Join(workingDir, "mycontent", "mybundle"), 0o777)
b.WithSourceFile("README.md", `---
title: "Readme Title"
@@ -974,9 +974,9 @@ workingDir = %q
cfg := config.New()
cfg.Set("workingDir", workingDir)
cfg.Set("publishDir", "public")
- b.Fs = hugofs.NewDefaultOld(cfg)
+ b.Fs = hugofs.NewDefault(cfg)
- os.MkdirAll(filepath.Join(workingDir, "content", "blog"), 0777)
+ os.MkdirAll(filepath.Join(workingDir, "content", "blog"), 0o777)
b.WithWorkingDir(workingDir).WithConfigFile("toml", tomlConfig)
@@ -1034,12 +1034,12 @@ title: P1
defer test.clean()
subContentDir := filepath.Join(test.workingDir, "mycontent", "sub")
- os.MkdirAll(subContentDir, 0777)
+ os.MkdirAll(subContentDir, 0o777)
myPartialsDir := filepath.Join(test.workingDir, "subdir", "mypartials")
- os.MkdirAll(myPartialsDir, 0777)
+ os.MkdirAll(myPartialsDir, 0o777)
absShortcodesDir := filepath.Join(absDir, "abs", "myshortcodes")
- os.MkdirAll(absShortcodesDir, 0777)
+ os.MkdirAll(absShortcodesDir, 0o777)
b.WithSourceFile("README.md", "---\ntitle: Readme\n---")
b.WithSourceFile("mycontent/sub/p1.md", "---\ntitle: P1\n---")
@@ -1128,7 +1128,7 @@ title: Abs
---
Content.
-`), 0777)
+`), 0o777)
b.WithWorkingDir(workDir).WithConfigFile("toml", config)
b.WithContent("dummy.md", "")
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
index eb0385cda..f3f5c3eb2 100644
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -50,7 +50,6 @@ import (
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/page/pagemeta"
- "github.com/gohugoio/hugo/tpl"
)
// HugoSites represents the sites to build. Each site represents a language.
@@ -319,21 +318,6 @@ func (h *HugoSites) loadGitInfo() error {
return nil
}
-func (s *Site) withSiteTemplates(withTemplates ...func(templ tpl.TemplateManager) error) func(templ tpl.TemplateManager) error {
- return func(templ tpl.TemplateManager) error {
- for _, wt := range withTemplates {
- if wt == nil {
- continue
- }
- if err := wt(templ); err != nil {
- return err
- }
- }
-
- return nil
- }
-}
-
// Reset resets the sites and template caches etc., making it ready for a full rebuild.
func (h *HugoSites) reset(config *BuildCfg) {
if config.ResetState {
@@ -659,7 +643,6 @@ func (h *HugoSites) errWithFileContext(err error, f source.File) error {
realFilename := fim.Meta().Filename
return herrors.NewFileErrorFromFile(err, realFilename, h.SourceSpec.Fs.Source, nil)
-
}
func (h *HugoSites) readData(f source.File) (any, error) {
diff --git a/hugolib/page.go b/hugolib/page.go
index 2ea936af2..bf5e19ac4 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -851,10 +851,6 @@ func (p *pageState) pathOrTitle() string {
return p.Title()
}
-func (p *pageState) posFromPage(offset int) text.Position {
- return p.posFromInput(p.source.parsed.Input(), offset)
-}
-
func (p *pageState) posFromInput(input []byte, offset int) text.Position {
if offset < 0 {
return text.Position{
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index c10896bef..77c5b4e7e 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -484,10 +484,6 @@ func doRenderShortcode(
return prerenderedShortcode{s: result, hasVariants: hasVariants}, err
}
-func (s *shortcodeHandler) hasShortcodes() bool {
- return s != nil && len(s.shortcodes) > 0
-}
-
func (s *shortcodeHandler) addName(name string) {
s.nameSetMu.Lock()
defer s.nameSetMu.Unlock()
@@ -529,13 +525,6 @@ func (s *shortcodeHandler) prepareShortcodesForPage(ctx context.Context, p *page
return rendered, nil
}
-func (s *shortcodeHandler) parseError(err error, input []byte, pos int) error {
- if s.p != nil {
- return s.p.parseError(err, input, pos)
- }
- return err
-}
-
// pageTokens state:
// - before: positioned just before the shortcode start
// - after: shortcode(s) consumed (plural when they are nested)
diff --git a/hugolib/template_test.go b/hugolib/template_test.go
index 802ce40e2..d18b4c6f0 100644
--- a/hugolib/template_test.go
+++ b/hugolib/template_test.go
@@ -16,7 +16,6 @@ package hugolib
import (
"fmt"
"path/filepath"
- "strings"
"testing"
"github.com/gohugoio/hugo/config"
@@ -636,10 +635,6 @@ func collectIdentities(set map[identity.Identity]bool, provider identity.Provide
}
}
-func ident(level int) string {
- return strings.Repeat(" ", level)
-}
-
func TestPartialInline(t *testing.T) {
b := newTestSitesBuilder(t)
diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go
index 700aa8c3d..cf054897d 100644
--- a/hugolib/testhelpers_test.go
+++ b/hugolib/testhelpers_test.go
@@ -43,7 +43,6 @@ import (
"github.com/spf13/cast"
"github.com/gohugoio/hugo/helpers"
- "github.com/gohugoio/hugo/tpl"
"github.com/gohugoio/hugo/resources/resource"
@@ -522,7 +521,7 @@ func (s *sitesBuilder) CreateSitesE() error {
"data",
"i18n",
} {
- if err := os.MkdirAll(filepath.Join(s.workingDir, dir), 0777); err != nil {
+ if err := os.MkdirAll(filepath.Join(s.workingDir, dir), 0o777); err != nil {
return fmt.Errorf("failed to create %q: %w", dir, err)
}
}
@@ -555,7 +554,6 @@ func (s *sitesBuilder) CreateSitesE() error {
depsCfg.TestLogger = s.logger
sites, err := NewHugoSites(depsCfg)
-
if err != nil {
return fmt.Errorf("failed to create sites: %w", err)
}
@@ -878,20 +876,6 @@ func (th testHelper) assertFileContent(filename string, matches ...string) {
}
}
-func (th testHelper) assertFileContentRegexp(filename string, matches ...string) {
- filename = th.replaceDefaultContentLanguageValue(filename)
- content := readWorkingDir(th, th.Fs, filename)
- for _, match := range matches {
- match = th.replaceDefaultContentLanguageValue(match)
- r := regexp.MustCompile(match)
- matches := r.MatchString(content)
- if !matches {
- fmt.Println("Expected to match regexp:\n"+match+"\nGot:\n", content)
- }
- th.Assert(matches, qt.Equals, true)
- }
-}
-
func (th testHelper) assertFileNotExist(filename string) {
exists, err := helpers.Exists(filename, th.Fs.PublishDir)
th.Assert(err, qt.IsNil)
@@ -908,16 +892,11 @@ func (th testHelper) replaceDefaultContentLanguageValue(value string) string {
return value
}
-func loadTestConfig(fs afero.Fs) (*allconfig.Configs, error) {
- res, err := allconfig.LoadConfig(allconfig.ConfigSourceDescriptor{Fs: fs})
- return res, err
-}
-
func loadTestConfigFromProvider(cfg config.Provider) (*allconfig.Configs, error) {
workingDir := cfg.GetString("workingDir")
fs := afero.NewMemMapFs()
if workingDir != "" {
- fs.MkdirAll(workingDir, 0755)
+ fs.MkdirAll(workingDir, 0o755)
}
res, err := allconfig.LoadConfig(allconfig.ConfigSourceDescriptor{Flags: cfg, Fs: fs})
return res, err
@@ -972,18 +951,6 @@ func newTestSitesFromConfig(t testing.TB, afs afero.Fs, tomlConfig string, layou
return th, h
}
-func createWithTemplateFromNameValues(additionalTemplates ...string) func(templ tpl.TemplateManager) error {
- return func(templ tpl.TemplateManager) error {
- for i := 0; i < len(additionalTemplates); i += 2 {
- err := templ.AddTemplate(additionalTemplates[i], additionalTemplates[i+1])
- if err != nil {
- return err
- }
- }
- return nil
- }
-}
-
// TODO(bep) replace these with the builder
func buildSingleSite(t testing.TB, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site {
t.Helper()