You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 rivejä
1.8 KiB
Go
63 rivejä
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"hash/crc32"
|
|
"path/filepath"
|
|
"regexp"
|
|
"runtime"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/PumpkinSeed/cage"
|
|
"github.com/gohugoio/hugo/commands"
|
|
hg "github.com/gohugoio/hugo/common/hugo"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func hugoContext(hugo *Hugo, gitRepoPath string) {
|
|
viper.SetConfigName("config")
|
|
viper.SetConfigType("toml")
|
|
viper.AddConfigPath(filepath.Join(hugo.SourceDir))
|
|
err := viper.ReadInConfig()
|
|
check(err)
|
|
gitRepoPathChecksum := strconv.FormatUint(uint64(crc32.ChecksumIEEE([]byte(gitRepoPath))), 16)
|
|
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
|
|
check(err)
|
|
hugoTitle := reg.ReplaceAllString(viper.GetString("title"), "")
|
|
hugo.PublicHTMLName = strings.ToLower(hugoTitle) + "-" + gitRepoPathChecksum
|
|
hugo.CatalogName = viper.GetString("params.sandpointsCatalogName")
|
|
hugo.CatalogPrefix = viper.GetString("params.sandpointsCatalogPrefix")
|
|
hugo.DestinationDir = filepath.Join(hugo.SourceDir, "public")
|
|
}
|
|
|
|
func hugoRun(hugoCommands []string) []string {
|
|
logs := cage.Start()
|
|
hugoCommand := hugoCommands
|
|
err := commands.Execute(hugoCommand)
|
|
if err != nil {
|
|
check(err)
|
|
runtime.Goexit()
|
|
}
|
|
cage.Stop(logs)
|
|
|
|
return logs.Data
|
|
}
|
|
|
|
func hugoRender(hugo *Hugo, hook *Hook) string {
|
|
// fmt.Println("hugo", "-s", hugo.SourceDir, "-d", hugo.DestinationDir, "--templateMetrics")
|
|
hugoCommands := []string{"-s", hugo.SourceDir, "-d", hugo.DestinationDir, "--templateMetrics"}
|
|
if hook.Offline {
|
|
hugoCommands = append(hugoCommands, []string{"-e", "offline"}...)
|
|
} else if hook.Context == "PostReceive" {
|
|
hugoCommands = append(hugoCommands, []string{"-e", "gitea"}...)
|
|
}
|
|
logs := hugoRun(hugoCommands)
|
|
|
|
lgs := fmt.Sprintf("~~~~~~~ Hugo's logs (v0.%d)~~~~~~~\n", hg.CurrentVersion.Minor)
|
|
for _, l := range logs {
|
|
lgs = lgs + l + "\n"
|
|
}
|
|
return lgs
|
|
}
|