aboutsummaryrefslogtreecommitdiff
path: root/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'common.go')
-rw-r--r--common.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/common.go b/common.go
index 3547af1..56bffd1 100644
--- a/common.go
+++ b/common.go
@@ -22,6 +22,7 @@ package main
22import ( 22import (
23 "bytes" 23 "bytes"
24 "fmt" 24 "fmt"
25 "github.com/Pacien/fcmd"
25 "github.com/drbawb/mustache" 26 "github.com/drbawb/mustache"
26 "github.com/russross/blackfriday" 27 "github.com/russross/blackfriday"
27 "io/ioutil" 28 "io/ioutil"
@@ -69,7 +70,7 @@ func merge(files map[string][]byte) (merged []byte) {
69// render and write everything inside 70// render and write everything inside
70 71
71func parse(dirPath string, elements map[string][]byte, exts []string, overwrite bool) map[string][]byte { 72func parse(dirPath string, elements map[string][]byte, exts []string, overwrite bool) map[string][]byte {
72 _, filesList := ls(dirPath) 73 _, filesList := fcmd.Ls(dirPath)
73 for _, fileName := range filesList { 74 for _, fileName := range filesList {
74 if isParsable(fileName, exts) && (overwrite || elements[fileName[:len(fileName)-len(path.Ext(fileName))]] == nil) { 75 if isParsable(fileName, exts) && (overwrite || elements[fileName[:len(fileName)-len(path.Ext(fileName))]] == nil) {
75 var err error 76 var err error
@@ -93,7 +94,7 @@ func compile(dirPath string, elements map[string][]byte, sourceDir, outputDir, s
93 elements = parse(dirPath, elements, exts, true) 94 elements = parse(dirPath, elements, exts, true)
94 95
95 if recursive { 96 if recursive {
96 dirs, _ := ls(dirPath) 97 dirs, _ := fcmd.Ls(dirPath)
97 for _, dir := range dirs { 98 for _, dir := range dirs {
98 go compile(path.Join(dirPath, dir), elements, sourceDir, outputDir, saveAs, exts, recursive) 99 go compile(path.Join(dirPath, dir), elements, sourceDir, outputDir, saveAs, exts, recursive)
99 } 100 }
@@ -102,7 +103,7 @@ func compile(dirPath string, elements map[string][]byte, sourceDir, outputDir, s
102 template := merge(elements) 103 template := merge(elements)
103 page := mustache.Render(string(template), makeContext(dirPath, sourceDir, outputDir, exts)) 104 page := mustache.Render(string(template), makeContext(dirPath, sourceDir, outputDir, exts))
104 105
105 err := writeFile(path.Join(outputDir, strings.TrimPrefix(dirPath, sourceDir), saveAs), []byte(page)) 106 err := fcmd.WriteFile(path.Join(outputDir, strings.TrimPrefix(dirPath, sourceDir), saveAs), []byte(page))
106 if err != nil { 107 if err != nil {
107 fmt.Println(err) 108 fmt.Println(err)
108 return 109 return
@@ -117,10 +118,10 @@ func copyFiles(dirPath, sourceDir, outputDir string, exts []string, recursive bo
117 return 118 return
118 } 119 }
119 120
120 dirs, files := ls(dirPath) 121 dirs, files := fcmd.Ls(dirPath)
121 for _, file := range files { 122 for _, file := range files {
122 if !isParsable(file, exts) { 123 if !isParsable(file, exts) {
123 err := cp(path.Join(dirPath, file), path.Join(outputDir, strings.TrimPrefix(dirPath, sourceDir), file)) 124 err := fcmd.Cp(path.Join(dirPath, file), path.Join(outputDir, strings.TrimPrefix(dirPath, sourceDir), file))
124 if err != nil { 125 if err != nil {
125 fmt.Println(err) 126 fmt.Println(err)
126 } 127 }