Using Hugo as part of another Go application

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

  1. It uses AeroFS. What is the most basic version where it pulls the .md from “somewhere” (filesystem) and spits out rendered pages
  2. 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"
weight = 1
languageName = "English"
weight = 2
languageName = "Nynorsk"
  source = 'archetypes'
  target = 'archetypes'
  source = 'content'
  target = 'content'
  lang = 'en'
  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


	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


thank you.
I haven’t made it that far as missing alot of concepts I believe…

1 Like