Browse Source

implemented functionallity to get the files to apply templating from the json file of config

master
arnaucode 7 years ago
parent
commit
11f2b576a5
4 changed files with 66 additions and 1 deletions
  1. +17
    -0
      README.md
  2. BIN
      example.png
  3. +22
    -1
      main.go
  4. +27
    -0
      readTimmyConfig.go

+ 17
- 0
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
```

BIN
example.png

Before After
Width: 1004  |  Height: 649  |  Size: 110 KiB

+ 22
- 1
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")
}

+ 27
- 0
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)
}

Loading…
Cancel
Save