mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-02 22:52:51 +02:00
all: Remove unused code
Using x/tools/cmd/deadcode
This commit is contained in:
@@ -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
|
||||
|
@@ -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", "")
|
||||
|
@@ -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) {
|
||||
|
@@ -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{
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user