support passing a different root dir

This commit is contained in:
facundoolano 2024-02-15 12:38:17 -03:00
parent e5917dc21e
commit 513befe8b8
2 changed files with 13 additions and 5 deletions

View file

@ -2,6 +2,7 @@ package commands
import (
"fmt"
"path/filepath"
"github.com/facundoolano/blorg/site"
)
@ -30,12 +31,15 @@ func New() error {
}
// Read the files in src/ render them and copy the result to target/
// TODO add root dir override support
func Build() error {
site, err := site.Load(SRC_DIR, LAYOUTS_DIR)
func Build(root string) error {
src := filepath.Join(root, SRC_DIR)
target := filepath.Join(root, TARGET_DIR)
layouts := filepath.Join(root, LAYOUTS_DIR)
site, err := site.Load(src, layouts)
if err != nil {
return err
}
return site.Build(SRC_DIR, TARGET_DIR, true, false)
return site.Build(src, target, true, false)
}

View file

@ -34,7 +34,11 @@ func run(args []string) error {
initCmd.Parse(os.Args[2:])
return commands.Init()
case "build":
return commands.Build()
rootDir := "."
if len(os.Args) > 2 {
rootDir = os.Args[2]
}
return commands.Build(rootDir)
case "new":
newCmd.Parse(os.Args[2:])
return commands.New()