arnaucube
arnaucube/konstruiPublic Self-hosted repository
konstrui/main.go
main.goRaw
 1package main
 2
 3import (
 4	"io/ioutil"
 5	"os"
 6	"strings"
 7)
 8
 9const rawFolderPath = "./webInput"
10const newFolderPath = "./webOutput"
11
12func parseDir(folderPath string, newDir string) {
13	files, _ := ioutil.ReadDir(folderPath)
14	for _, f := range files {
15		fileNameSplitted := strings.Split(f.Name(), ".")
16		extension := fileNameSplitted[len(fileNameSplitted)-1]
17		if extension == "html" {
18			fileContent := putTemplates(folderPath, f.Name())
19			writeFile(newDir+"/"+f.Name(), fileContent)
20		} else if extension == "css" {
21			fileContent := readFile(folderPath, f.Name())
22			writeFile(newDir+"/"+f.Name(), fileContent)
23		}
24		if len(fileNameSplitted) == 1 {
25			newDir := newDir + "/" + f.Name()
26			oldDir := rawFolderPath + "/" + f.Name()
27			if _, err := os.Stat(newDir); os.IsNotExist(err) {
28				_ = os.Mkdir(newDir, 0700)
29			}
30			parseDir(oldDir, newDir)
31		}
32	}
33}
34func main() {
35	c.Green("getting files from /webInput")
36	c.Green("templating")
37	parseDir(rawFolderPath, newFolderPath)
38	c.Green("webpage finished, wiles at /webOutput")
39}