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.

62 lines
1.4 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "log"
  6. "strings"
  7. blackfriday "gopkg.in/russross/blackfriday.v2"
  8. )
  9. func main() {
  10. //savelog()
  11. log.Println("kunigu")
  12. scrapDirectory(".")
  13. }
  14. func scrapDirectory(path string) {
  15. filesList, _ := ioutil.ReadDir(path)
  16. for _, f := range filesList {
  17. fileNameSplitted := strings.Split(f.Name(), ".")
  18. if len(fileNameSplitted) > 1 {
  19. if fileNameSplitted[1] == "txt" || fileNameSplitted[1] == "html" {
  20. file := readFile(path + "/" + f.Name())
  21. if strings.Contains(file, "{{kunigu ") {
  22. fmt.Println(path + "/" + f.Name())
  23. r := kuniguFile(file)
  24. writeFile(path+"/"+fileNameSplitted[0]+"OUT."+fileNameSplitted[1], r)
  25. }
  26. }
  27. } else {
  28. //is a directory
  29. //fmt.Println(path + "/" + f.Name())
  30. scrapDirectory(path + "/" + f.Name())
  31. }
  32. }
  33. }
  34. func kuniguFile(file string) string {
  35. lines := getLines(file)
  36. var resultL []string
  37. for _, l := range lines {
  38. if strings.Contains(l, "{{kunigu ") {
  39. var htmlcontent string
  40. includefile := strings.Split(l, " @")[1]
  41. includefile = strings.Replace(includefile, "}}", "", -1)
  42. if strings.Contains(l, "--md-to-html") {
  43. mdcontent := readFile(includefile)
  44. htmlcontent = string(blackfriday.Run([]byte(mdcontent)))
  45. } else {
  46. htmlcontent = readFile(includefile)
  47. }
  48. resultL = append(resultL, htmlcontent)
  49. } else {
  50. resultL = append(resultL, l)
  51. }
  52. }
  53. result := concatStringsWithJumps(resultL)
  54. return result
  55. }