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.

39 lines
1.0 KiB

7 years ago
  1. package main
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "strings"
  6. )
  7. const rawFolderPath = "./webInput"
  8. const newFolderPath = "./webOutput"
  9. func parseDir(folderPath string, newDir string) {
  10. files, _ := ioutil.ReadDir(folderPath)
  11. for _, f := range files {
  12. fileNameSplitted := strings.Split(f.Name(), ".")
  13. extension := fileNameSplitted[len(fileNameSplitted)-1]
  14. if extension == "html" {
  15. fileContent := putTemplates(folderPath, f.Name())
  16. writeFile(newDir+"/"+f.Name(), fileContent)
  17. } else if extension == "css" {
  18. fileContent := readFile(folderPath, f.Name())
  19. writeFile(newDir+"/"+f.Name(), fileContent)
  20. }
  21. if len(fileNameSplitted) == 1 {
  22. newDir := newDir + "/" + f.Name()
  23. oldDir := rawFolderPath + "/" + f.Name()
  24. if _, err := os.Stat(newDir); os.IsNotExist(err) {
  25. _ = os.Mkdir(newDir, 0700)
  26. }
  27. parseDir(oldDir, newDir)
  28. }
  29. }
  30. }
  31. func main() {
  32. c.Green("getting files from /webInput")
  33. c.Green("templating")
  34. parseDir(rawFolderPath, newFolderPath)
  35. c.Green("webpage finished, wiles at /webOutput")
  36. }