diff --git a/README.md b/README.md index bf77d70..f6c1ff4 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,23 @@ webInput/ ] ``` +- Set the configuration file timmyConfig.json in the webInput directory: + +```json +{ + "title": "Web example", + "author": "arnaucode", + "github": "github.com/arnaucode", + "website": "arnaucode.com", + "files": [ + "index.html", + "projects.html", + "app.css" + ] +} +``` + + - Execute Timmy ``` diff --git a/example.png b/example.png new file mode 100644 index 0000000..2dbbebf Binary files /dev/null and b/example.png differ diff --git a/main.go b/main.go index bd34bec..c8bc8f1 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "io/ioutil" "os" "strings" @@ -8,6 +9,7 @@ import ( const rawFolderPath = "./webInput" const newFolderPath = "./webOutput" +const timmyConfigFile = "timmyConfig.json" func parseDir(folderPath string, newDir string) { files, _ := ioutil.ReadDir(folderPath) @@ -31,9 +33,28 @@ func parseDir(folderPath string, newDir string) { } } } +func startTemplating(folderPath string, newDir string) { + for i := 0; i < len(timmyConfig.Files); i++ { + fName := timmyConfig.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 timmyConfig.json") + readTimmyConfig(rawFolderPath + "/" + timmyConfigFile) + c.Green("configuration:") + fmt.Println(timmyConfig.Files) c.Green("templating") - parseDir(rawFolderPath, newFolderPath) + //parseDir(rawFolderPath, newFolderPath) + startTemplating(rawFolderPath, newFolderPath) c.Green("webpage finished, wiles at /webOutput") } diff --git a/readTimmyConfig.go b/readTimmyConfig.go new file mode 100644 index 0000000..1fbcac7 --- /dev/null +++ b/readTimmyConfig.go @@ -0,0 +1,27 @@ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" +) + +//TimmyConfig is the configuration from the file timmyConfig.json, on the folder /webInput +type TimmyConfig struct { + Title string `json:"title"` + Author string `json:"author"` + Github string `json:"github"` + Website string `json:"website"` + Files []string `json:"files"` +} + +var timmyConfig TimmyConfig + +func readTimmyConfig(path string) { + file, e := ioutil.ReadFile(path) + if e != nil { + fmt.Println("error:", e) + } + content := string(file) + json.Unmarshal([]byte(content), &timmyConfig) +}