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.

73 lines
2.2 KiB

7 years ago
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 konstruiConfigFile = "konstruiConfig.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. path := folderPath + "/" + f.Name()
  21. fileContent := readFile(path)
  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. }
  34. func startTemplating(folderPath string, newDir string) {
  35. for i := 0; i < len(konstruiConfig.Files); i++ {
  36. fName := konstruiConfig.Files[i]
  37. fileNameSplitted := strings.Split(fName, ".")
  38. extension := fileNameSplitted[len(fileNameSplitted)-1]
  39. if extension == "html" {
  40. fileContent := putTemplates(folderPath, fName)
  41. writeFile(newDir+"/"+fName, fileContent)
  42. } else if extension == "css" {
  43. path := folderPath + "/" + fName
  44. fileContent := readFile(path)
  45. writeFile(newDir+"/"+fName, fileContent)
  46. }
  47. }
  48. c.Cyan("starting to generate Pages to repeat")
  49. for i := 0; i < len(konstruiConfig.RepeatPages); i++ {
  50. pageTemplate, data := getHtmlAndDataFromRepeatPages(konstruiConfig.RepeatPages[i])
  51. for j := 0; j < len(data); j++ {
  52. fmt.Println(j)
  53. generatedPage := generatePageFromTemplateAndData(pageTemplate, data[j])
  54. fmt.Println(data[j])
  55. writeFile(newDir+"/"+data[j]["pageName"]+"Page.html", generatedPage)
  56. }
  57. }
  58. }
  59. func main() {
  60. c.Green("getting files from /webInput")
  61. c.Green("getting conifg from file konstruiConfig.json")
  62. readKonstruiConfig(rawFolderPath + "/" + konstruiConfigFile)
  63. c.Green("configuration:")
  64. fmt.Println(konstruiConfig.Files)
  65. c.Green("templating")
  66. //parseDir(rawFolderPath, newFolderPath)
  67. startTemplating(rawFolderPath, newFolderPath)
  68. c.Green("webpage finished, wiles at /webOutput")
  69. }