konstrui/main.go
main.goRaw
1package main
2
3import (
4 "fmt"
5 "io/ioutil"
6 "os"
7 "strings"
8)
9
10const rawFolderPath = "./webInput"
11const newFolderPath = "./webOutput"
12const konstruiConfigFile = "konstruiConfig.json"
13
14func parseDir(folderPath string, newDir string) {
15 files, _ := ioutil.ReadDir(folderPath)
16 for _, f := range files {
17 fileNameSplitted := strings.Split(f.Name(), ".")
18 extension := fileNameSplitted[len(fileNameSplitted)-1]
19 if extension == "html" {
20 fileContent := putTemplates(folderPath, f.Name())
21 writeFile(newDir+"/"+f.Name(), fileContent)
22 } else if extension == "css" {
23 fileContent := readFile(folderPath, f.Name())
24 writeFile(newDir+"/"+f.Name(), fileContent)
25 }
26 if len(fileNameSplitted) == 1 {
27 newDir := newDir + "/" + f.Name()
28 oldDir := rawFolderPath + "/" + f.Name()
29 if _, err := os.Stat(newDir); os.IsNotExist(err) {
30 _ = os.Mkdir(newDir, 0700)
31 }
32 parseDir(oldDir, newDir)
33 }
34 }
35}
36func startTemplating(folderPath string, newDir string) {
37 for i := 0; i < len(konstruiConfig.Files); i++ {
38 fName := konstruiConfig.Files[i]
39 fileNameSplitted := strings.Split(fName, ".")
40 extension := fileNameSplitted[len(fileNameSplitted)-1]
41 if extension == "html" {
42 fileContent := putTemplates(folderPath, fName)
43 writeFile(newDir+"/"+fName, fileContent)
44 } else if extension == "css" {
45 fileContent := readFile(folderPath, fName)
46 writeFile(newDir+"/"+fName, fileContent)
47 }
48 }
49}
50func main() {
51 c.Green("getting files from /webInput")
52 c.Green("getting conifg from file konstruiConfig.json")
53 readKonstruiConfig(rawFolderPath + "/" + konstruiConfigFile)
54 c.Green("configuration:")
55 fmt.Println(konstruiConfig.Files)
56 c.Green("templating")
57 //parseDir(rawFolderPath, newFolderPath)
58 startTemplating(rawFolderPath, newFolderPath)
59 c.Green("webpage finished, wiles at /webOutput")
60}