You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

60 lines
1.8 KiB

package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
)
const rawFolderPath = "./webInput"
const newFolderPath = "./webOutput"
const konstruiConfigFile = "konstruiConfig.json"
func parseDir(folderPath string, newDir string) {
files, _ := ioutil.ReadDir(folderPath)
for _, f := range files {
fileNameSplitted := strings.Split(f.Name(), ".")
extension := fileNameSplitted[len(fileNameSplitted)-1]
if extension == "html" {
fileContent := putTemplates(folderPath, f.Name())
writeFile(newDir+"/"+f.Name(), fileContent)
} else if extension == "css" {
fileContent := readFile(folderPath, f.Name())
writeFile(newDir+"/"+f.Name(), fileContent)
}
if len(fileNameSplitted) == 1 {
newDir := newDir + "/" + f.Name()
oldDir := rawFolderPath + "/" + f.Name()
if _, err := os.Stat(newDir); os.IsNotExist(err) {
_ = os.Mkdir(newDir, 0700)
}
parseDir(oldDir, newDir)
}
}
}
func startTemplating(folderPath string, newDir string) {
for i := 0; i < len(konstruiConfig.Files); i++ {
fName := konstruiConfig.Files[i]
fileNameSplitted := strings.Split(fName, ".")
extension := fileNameSplitted[len(fileNameSplitted)-1]
if extension == "html" {
fileContent := putTemplates(folderPath, fName)
writeFile(newDir+"/"+fName, fileContent)
} else if extension == "css" {
fileContent := readFile(folderPath, fName)
writeFile(newDir+"/"+fName, fileContent)
}
}
}
func main() {
c.Green("getting files from /webInput")
c.Green("getting conifg from file konstruiConfig.json")
readKonstruiConfig(rawFolderPath + "/" + konstruiConfigFile)
c.Green("configuration:")
fmt.Println(konstruiConfig.Files)
c.Green("templating")
//parseDir(rawFolderPath, newFolderPath)
startTemplating(rawFolderPath, newFolderPath)
c.Green("webpage finished, wiles at /webOutput")
}