diff options
Diffstat (limited to 'interactive.go')
-rw-r--r-- | interactive.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/interactive.go b/interactive.go index 34c2f68..22f5933 100644 --- a/interactive.go +++ b/interactive.go | |||
@@ -42,19 +42,19 @@ func watch(dirPath string, watcher *fsnotify.Watcher) *fsnotify.Watcher { | |||
42 | return watcher | 42 | return watcher |
43 | } | 43 | } |
44 | 44 | ||
45 | func parseParents(dir, sourceDir string) map[string][]byte { | 45 | func parseParents(dir, sourceDir string, exts []string) map[string][]byte { |
46 | dirs := strings.Split(strings.TrimPrefix(dir, sourceDir), "/") | 46 | dirs := strings.Split(strings.TrimPrefix(dir, sourceDir), "/") |
47 | elements := make(map[string][]byte) | 47 | elements := make(map[string][]byte) |
48 | for _, dir := range dirs { | 48 | for _, dir := range dirs { |
49 | elements = parse(path.Join(sourceDir, dir), elements, false) | 49 | elements = parse(path.Join(sourceDir, dir), elements, exts, false) |
50 | } | 50 | } |
51 | return elements | 51 | return elements |
52 | } | 52 | } |
53 | 53 | ||
54 | func interactive(sourceDir, outputDir string) { | 54 | func interactive(sourceDir, outputDir string, exts []string, saveAs string) { |
55 | 55 | ||
56 | // compile the whole site | 56 | // compile the whole site |
57 | compiled(sourceDir, outputDir) | 57 | compiled(sourceDir, outputDir, exts, saveAs) |
58 | 58 | ||
59 | // watch the source dir | 59 | // watch the source dir |
60 | watcher, err := fsnotify.NewWatcher() | 60 | watcher, err := fsnotify.NewWatcher() |
@@ -90,7 +90,7 @@ func interactive(sourceDir, outputDir string) { | |||
90 | // remove previously compiled files | 90 | // remove previously compiled files |
91 | if ev.IsDelete() || ev.IsRename() || ev.IsModify() { | 91 | if ev.IsDelete() || ev.IsRename() || ev.IsModify() { |
92 | var err error | 92 | var err error |
93 | if isDir(ev.Name) || !isParsable(ev.Name) { | 93 | if isDir(ev.Name) || !isParsable(ev.Name, exts) { |
94 | err = os.RemoveAll(path.Join(outputDir, strings.TrimPrefix(ev.Name, sourceDir))) | 94 | err = os.RemoveAll(path.Join(outputDir, strings.TrimPrefix(ev.Name, sourceDir))) |
95 | } else { | 95 | } else { |
96 | err = os.RemoveAll(path.Join(outputDir, strings.TrimPrefix(dir, sourceDir))) | 96 | err = os.RemoveAll(path.Join(outputDir, strings.TrimPrefix(dir, sourceDir))) |
@@ -104,17 +104,17 @@ func interactive(sourceDir, outputDir string) { | |||
104 | // recompile changed files | 104 | // recompile changed files |
105 | if ev.IsCreate() || ev.IsModify() { | 105 | if ev.IsCreate() || ev.IsModify() { |
106 | if isDir(ev.Name) { | 106 | if isDir(ev.Name) { |
107 | elements := parseParents(ev.Name, sourceDir) | 107 | elements := parseParents(ev.Name, sourceDir, exts) |
108 | dirPath := path.Join(sourceDir, strings.TrimPrefix(ev.Name, sourceDir)) | 108 | dirPath := path.Join(sourceDir, strings.TrimPrefix(ev.Name, sourceDir)) |
109 | go compile(dirPath, elements, sourceDir, outputDir, true) | 109 | go compile(dirPath, elements, sourceDir, outputDir, saveAs, exts, true) |
110 | go copyFiles(dirPath, sourceDir, outputDir, true) | 110 | go copyFiles(dirPath, sourceDir, outputDir, exts, true) |
111 | } else { | 111 | } else { |
112 | dirPath := path.Join(sourceDir, strings.TrimPrefix(dir, sourceDir)) | 112 | dirPath := path.Join(sourceDir, strings.TrimPrefix(dir, sourceDir)) |
113 | if isParsable(path.Ext(ev.Name)) { | 113 | if isParsable(path.Ext(ev.Name), exts) { |
114 | elements := parseParents(dir, sourceDir) | 114 | elements := parseParents(dir, sourceDir, exts) |
115 | go compile(dirPath, elements, sourceDir, outputDir, true) | 115 | go compile(dirPath, elements, sourceDir, outputDir, saveAs, exts, true) |
116 | } | 116 | } |
117 | go copyFiles(dirPath, sourceDir, outputDir, false) | 117 | go copyFiles(dirPath, sourceDir, outputDir, exts, false) |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||