hugo-medialog/utils/utils.go

31 lines
554 B
Go
Raw Normal View History

2024-10-08 21:08:01 +02:00
// utils/utils.go
package utils
import (
"bytes"
"os"
"text/template"
)
func CreateDirIfNotExists(dir string) error {
if _, err := os.Stat(dir); os.IsNotExist(err) {
return os.MkdirAll(dir, 0755)
}
return nil
}
func GenerateMarkdown(templatePath string, outputPath string, data map[string]interface{}) error {
tmpl, err := template.ParseFiles(templatePath)
if err != nil {
return err
}
var output bytes.Buffer
err = tmpl.Execute(&output, data)
if err != nil {
return err
}
return os.WriteFile(outputPath, output.Bytes(), 0644)
}