52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package mailer
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
|
|
"clickandjoin.app/emailserver/modules/cache"
|
|
"clickandjoin.app/emailserver/modules/config"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/tdewolff/minify/v2/minify"
|
|
)
|
|
|
|
func readTemplatesConfig() {
|
|
logrus.Debugln("START READING TEMPLATE CONFIG")
|
|
|
|
byteValue, err := os.ReadFile(config.Cfg.Templates.ConfigPath)
|
|
|
|
if err != nil {
|
|
logrus.Fatalln("Failed to read config file, err:", err)
|
|
}
|
|
|
|
err = json.Unmarshal(byteValue, &cache.Templates)
|
|
|
|
if err != nil {
|
|
logrus.Fatalln("Failed to unmarshal templates config, err:", err)
|
|
}
|
|
|
|
logrus.Debug("FINISHED READING TEMPLATE CONFIG")
|
|
}
|
|
|
|
func loadTemplateFiles() {
|
|
logrus.Debugln("STARTING IMPORTING TEMPLATE FILES")
|
|
|
|
for templateName, _ := range cache.Templates.Templates {
|
|
data, err := os.ReadFile(config.Cfg.Templates.FolderPath + templateName + ".html")
|
|
|
|
if err != nil {
|
|
logrus.Fatalln("Failed to read file, err:", err)
|
|
}
|
|
|
|
minifiedHtml, err := minify.HTML(string(data))
|
|
|
|
if err != nil {
|
|
logrus.Fatalln("Failed to minify html, err:", err)
|
|
}
|
|
|
|
cache.BodyTemplates[templateName] = []byte(minifiedHtml)
|
|
}
|
|
|
|
logrus.Debugln("FINISHED IMPORTING TEMPLATE FILES")
|
|
}
|