make symlink for the library

This commit is contained in:
Marcell Mars 2020-12-18 00:31:16 +01:00
parent dad20ec835
commit 7b6bdd72b2
2 changed files with 11 additions and 3 deletions

14
main.go
View file

@ -67,7 +67,7 @@ func hugoLogs(logLines string, lines []string, hugoInstance string) string {
return logLines
}
func getOutdir(tmpRepoPath, gitRepoPath string) string {
func getOutdirAndConfigCatalog(tmpRepoPath, gitRepoPath string) (string, string, string) {
viper.SetConfigName("config")
viper.SetConfigType("toml")
viper.AddConfigPath(filepath.Join(tmpRepoPath))
@ -78,7 +78,7 @@ func getOutdir(tmpRepoPath, gitRepoPath string) string {
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
check(err)
outdirRepoName := reg.ReplaceAllString(viper.GetString("title"), "")
return strings.ToLower(outdirRepoName) + "-" + outdirChecksum
return (strings.ToLower(outdirRepoName) + "-" + outdirChecksum), viper.GetString("params.sandpointsCatalogName"), viper.GetString("params.sandpointsCatalogPrefix")
}
func main() {
@ -154,7 +154,7 @@ func main() {
gitRemoveWorktree.Env = append(gitRemoveWorktree.Env, fmt.Sprintf("GIT_INDEX_FILE=%s%s", gitRepoPath, gitIndexPath))
defer gitRemoveWorktree.Run()
outSandpointsDir := getOutdir(tmpRepoPath, gitRepoPath)
outSandpointsDir, sandpointsCatalogName, sandpointsCatalogPrefix := getOutdirAndConfigCatalog(tmpRepoPath, gitRepoPath)
logLines = logLines + fmt.Sprintf("to be moved to: %s\n", filepath.Join(outDir, outSandpointsDir))
tmpHugoGiteaPath := filepath.Join(os.TempDir(), fmt.Sprintf("sandpoints_hugo_%06d", rand.Intn(100001)))
tmpHugoPreviewPath := filepath.Join(tmpHugoGiteaPath, "_preview")
@ -228,9 +228,17 @@ func main() {
if published {
err = os.Rename(tmpHugoGiteaPath, filepath.Join(outDir, outSandpointsDir))
check(err)
if sandpointsCatalogPrefix != "" && sandpointsCatalogName != "" {
err = os.Symlink(filepath.Join(outDir, outSandpointsDir, sandpointsCatalogPrefix), filepath.Join(outDir, "libraries", sandpointsCatalogName))
check(err)
}
} else {
err = os.Rename(tmpHugoPreviewPath, filepath.Join(outDir, outSandpointsDir, "_preview"))
check(err)
if sandpointsCatalogPrefix != "" && sandpointsCatalogName != "" {
err = os.Symlink(filepath.Join(outDir, outSandpointsDir, "_preview", sandpointsCatalogPrefix), filepath.Join(outDir, "libraries", sandpointsCatalogName))
check(err)
}
}
publishedMessage := ""

BIN
sphook

Binary file not shown.