mirror of
https://github.com/arnaucube/konstrui.git
synced 2026-02-07 03:26:43 +01:00
implemented functionallity to get the files to apply templating from the json file of config
This commit is contained in:
17
README.md
17
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
Normal file
BIN
example.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 110 KiB |
23
main.go
23
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
readTimmyConfig.go
Normal file
27
readTimmyConfig.go
Normal file
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user