basic hugo integration
This commit is contained in:
36
pkg/hugo/hugo.go
Normal file
36
pkg/hugo/hugo.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package hugo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"git.assilvestrar.club/lourenco/go-hugo-cms.git/pkg/git"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (g *git.GitOptions) NewBlog() {
|
||||||
|
if empty, _ := g.CheckIfEmpty(); !empty {
|
||||||
|
log.Fatal("blog dir is not empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command("hugo", "new", "site", g.Name)
|
||||||
|
if err := cmd; err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *git.GitOptions) CheckIfEmpty() (bool, error) {
|
||||||
|
dir := os.Open(g.Name)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
defer dir.Close()
|
||||||
|
|
||||||
|
_, err := os.Readdirnames(1)
|
||||||
|
if err == io.EOF {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user