Skip to content

Instantly share code, notes, and snippets.

@marcellmars
Created Mar 13, 2021
Embed
What would you like to do?
hugo tests
package main
import (
"fmt"
"log"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/hugolib"
"github.com/gohugoio/hugo/langs"
"github.com/spf13/afero"
)
func main() {
aFs := afero.NewBasePathFs(afero.NewOsFs(), "/tmp/barfoo")
cfg, err := config.FromFile(aFs, "config.toml")
if err != nil {
return
}
osFs := hugofs.Os
cfg.Set("workingDir", "/tmp/barfoo")
l := langs.NewDefaultLanguage(cfg)
cfg.Set("languagesSorted", langs.NewLanguages(l))
fs := hugofs.NewFrom(osFs, cfg)
fmt.Printf("fs: %#v\n", fs)
dd := &deps.DepsCfg{}
dd.Fs = fs
fmt.Printf("dd.Fs: %#v\n", *dd.Fs)
dd.Cfg = cfg
sites, err := hugolib.NewHugoSites(*dd)
if err != nil {
log.Fatal("Could not load Hugo site(s)", err)
}
_ = sites
hh := hugolib.BuildCfg{SkipRender: true}
err = sites.Build(hh)
if err != nil {
log.Fatal("Could not run render", err)
}
// for _, p := range sites.Pages() {
// fmt.Println(p)
// }
}
@marcellmars

This comment has been minimized.

Copy link
Owner Author

@marcellmars marcellmars commented Mar 13, 2021

fs: &hugofs.Fs{Source:(*afero.OsFs)(0x222af60), Destination:(*afero.OsFs)(0x222af60), Os:(*afero.OsFs)(0x222b3e8), WorkingDir:(*afero.BasePathFs)(0xc0004e6dc0)}
dd.Fs: hugofs.Fs{Source:(*afero.OsFs)(0x222af60), Destination:(*afero.OsFs)(0x222af60), Os:(*afero.OsFs)(0x222b3e8), WorkingDir:(*afero.BasePathFs)(0xc0004e6dc0)}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x78 pc=0x76052f]

goroutine 1 [running]:
github.com/spf13/afero.(*BasePathFs).LstatIfPossible(0xc0004e7c00, 0xc000794a60, 0x7, 0x7f8af4766f58, 0xc0004e7c00, 0x147ab01, 0x5, 0x8)
	/home/m/go/pkg/mod/github.com/spf13/afero@v1.5.1/basepath.go:183 +0x1cf
github.com/gohugoio/hugo/hugofs.lstatIfPossible(0x1a17120, 0xc0004e7c00, 0x0, 0x0, 0x8, 0x203000, 0x8, 0x203000, 0x7f8b1d427f18)
	/home/m/go/pkg/mod/github.com/gohugoio/hugo@v0.81.0/hugofs/walk.go:143 +0x74
github.com/gohugoio/hugo/hugofs.(*FilterFs).LstatIfPossible(0xc0004e7c20, 0x0, 0x0, 0x10, 0x1355c40, 0xc0007db060, 0x0, 0x7f8af475e768)
	/home/m/go/pkg/mod/github.com/gohugoio/hugo@v0.81.0/hugofs/filter_fs.go:145 +0x66
github.com/gohugoio/hugo/hugofs.(*FilterFs).Stat(0xc0004e7c20, 0x0, 0x0, 0x10, 0xc000000180, 0xe5dbc6, 0xc0006d5440)
	/home/m/go/pkg/mod/github.com/gohugoio/hugo@v0.81.0/hugofs/filter_fs.go:205 +0x3f
github.com/gohugoio/hugo/hugolib.(*pagesCollector).collectDir(0xc0007e42a0, 0x0, 0x0, 0x1a0bb00, 0x0, 0x7f8af6b15fff, 0x400)
	/home/m/go/pkg/mod/github.com/gohugoio/hugo@v0.81.0/hugolib/pages_capture.go:328 +0x66
github.com/gohugoio/hugo/hugolib.(*pagesCollector).Collect(0xc0007e42a0, 0x0, 0x0)
	/home/m/go/pkg/mod/github.com/gohugoio/hugo@v0.81.0/hugolib/pages_capture.go:172 +0x639
github.com/gohugoio/hugo/hugolib.(*Site).readAndProcessContent(0xc0000b66c0, 0x0, 0x0, 0x0, 0x12c5520, 0x1)
	/home/m/go/pkg/mod/github.com/gohugoio/hugo@v0.81.0/hugolib/site.go:1370 +0x185
github.com/gohugoio/hugo/hugolib.(*Site).process(0xc0000b66c0, 0x0, 0x0, 0x0, 0x1, 0xc0007dad40, 0x0, 0x0, 0x0, 0x1, ...)
	/home/m/go/pkg/mod/github.com/gohugoio/hugo@v0.81.0/hugolib/site.go:1194 +0x65
github.com/gohugoio/hugo/hugolib.(*HugoSites).process(0xc0004c2000, 0xc0007d9600, 0xc0006d5ab0, 0x0, 0x0, 0x0, 0x222b3e8, 0x11cf701)
	/home/m/go/pkg/mod/github.com/gohugoio/hugo@v0.81.0/hugolib/hugo_sites_build.go:245 +0x129
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build.func3.2()
	/home/m/go/pkg/mod/github.com/gohugoio/hugo@v0.81.0/hugolib/hugo_sites_build.go:118 +0x65
runtime/trace.WithRegion(0x1a0bbe0, 0xc0007e80f0, 0x148794a, 0x7, 0xc0006d5ad8)
	/home/m/sdk/go1.16/src/runtime/trace/annotation.go:141 +0xf8
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build.func3(0x222b3e8, 0x1)
	/home/m/go/pkg/mod/github.com/gohugoio/hugo@v0.81.0/hugolib/hugo_sites_build.go:120 +0x165
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build.func4()
	/home/m/go/pkg/mod/github.com/gohugoio/hugo@v0.81.0/hugolib/hugo_sites_build.go:137 +0x2f
runtime/trace.WithRegion(0x1a0bbe0, 0xc0007e80f0, 0x14878e1, 0x7, 0xc0006d5c98)
	/home/m/sdk/go1.16/src/runtime/trace/annotation.go:141 +0xf8
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build(0xc0004c2000, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/home/m/go/pkg/mod/github.com/gohugoio/hugo@v0.81.0/hugolib/hugo_sites_build.go:139 +0xa57
main.main()
	/home/m/devel/mygodev/hugo_fs/main.go:39 +0x54e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment