Hey
I am wanting to embed “basic hugo” into another application. Looking through tests etc, and trying to pull together a code snippet i have got “so far”.
Concepts I’m not sure of
- It uses AeroFS. What is the most basic version where it pulls the .md from “somewhere” (filesystem) and spits out rendered pages
- Can I request a theme from code rather than cloning?
My snippet as it looks is this: however I am just trying to get a simple main() that reads the source and theme and spits out the static files. Please can some one assist me?
const exampleConfig = `
theme = "mytheme"
[languages]
[languages.en]
weight = 1
languageName = "English"
[languages.nn]
weight = 2
languageName = "Nynorsk"
[module]
[[module.mounts]]
source = 'archetypes'
target = 'archetypes'
[[module.mounts]]
source = 'content'
target = 'content'
lang = 'en'
[[module.mounts]]
source = 'content_nn'
target = 'content'
lang = 'nn'
`
func main() {
var cfg = &deps.DepsCfg{}
osFs := hugofs.Os
err := afero.WriteFile(osFs, "/config.toml", []byte(exampleConfig), 0755)
if err != nil {
log.Fatal("error loading WriteFile", err)
}
config, _, err := hugolib.LoadConfig(hugolib.ConfigSourceDescriptor{Fs: osFs, Filename: "/config.toml"})
if err != nil {
log.Fatal("error loading config", err)
}
config.Set("workingDir", "/home/pknopf/git/test-pages")
cfg.Cfg = config
fmt.Println("test")
fs := hugofs.NewFrom(osFs, config)
config.Set("cacheDir", helpers.GetTempDir("hugo_cache", fs.Source))
cfg.Fs = fs
ps, err := helpers.NewPathSpec(fs, cfg.Cfg, nil)
//ps, err := helpers.NewPathSpec(fs, cfg.Cfg)
if err != nil {
log.Fatal("error NewPathSpec", err)
}
_ = ps
config.Set("publishDir", "./")
sites, err := hugolib.NewHugoSites(*cfg)
if err != nil {
log.Fatal("error NewHugoSites", err)
}
fmt.Printf("sites %+v\r/n", sites)
_ = sites
sites.Build(hugolib.BuildCfg{})
thank you.
I haven’t made it that far as missing alot of concepts I believe…