package main

import (
	"fmt"
	"os"
	"path/filepath"
)

func writeLogToFile(logLines, path string) {
	lastPublishCommitLog, err := os.Create(filepath.Join(path, "last-commit-log.txt"))
	check(err)
	defer lastPublishCommitLog.Close()
	fmt.Fprintln(lastPublishCommitLog, logLines)
}

func writeLastCommitLog(logLines string, isBare bool, hugo *Hugo, hook *Hook) {
	if isBare {
		if hook.Publish {
			writeLogToFile(logLines, filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName))
		} else {
			writeLogToFile(logLines, filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName, "_preview"))
		}
	} else {
		writeLogToFile(logLines, filepath.Join(hugo.DestinationDir))
	}
}
