You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

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