diff options
-rw-r--r-- | common.go | 13 | ||||
-rw-r--r-- | dynamic.go | 7 | ||||
-rw-r--r-- | interactive.go | 2 |
3 files changed, 17 insertions, 5 deletions
@@ -67,7 +67,8 @@ func merge(files map[string][]byte) (merged []byte) { | |||
67 | 67 | ||
68 | // COMPILED and INTERACTIVE modes | 68 | // COMPILED and INTERACTIVE modes |
69 | 69 | ||
70 | func parse(dirPath string, elements map[string][]byte, exts []string, overwrite bool) map[string][]byte { | 70 | func parse(dirPath string, elements map[string][]byte, exts []string, overwrite bool) (map[string][]byte, bool) { |
71 | parsed := false | ||
71 | _, filesList := fcmd.Ls(dirPath) | 72 | _, filesList := fcmd.Ls(dirPath) |
72 | for _, fileName := range filesList { | 73 | for _, fileName := range filesList { |
73 | if isParsable(fileName, exts) && (overwrite || elements[fileName[:len(fileName)-len(path.Ext(fileName))]] == nil) { | 74 | if isParsable(fileName, exts) && (overwrite || elements[fileName[:len(fileName)-len(path.Ext(fileName))]] == nil) { |
@@ -76,9 +77,10 @@ func parse(dirPath string, elements map[string][]byte, exts []string, overwrite | |||
76 | if err != nil { | 77 | if err != nil { |
77 | fmt.Println(err) | 78 | fmt.Println(err) |
78 | } | 79 | } |
80 | parsed = true | ||
79 | } | 81 | } |
80 | } | 82 | } |
81 | return elements | 83 | return elements, parsed |
82 | } | 84 | } |
83 | 85 | ||
84 | func compile(dirPath string, elements map[string][]byte, sourceDir, outputDir, saveAs string, exts []string, recursive bool) { | 86 | func compile(dirPath string, elements map[string][]byte, sourceDir, outputDir, saveAs string, exts []string, recursive bool) { |
@@ -88,7 +90,8 @@ func compile(dirPath string, elements map[string][]byte, sourceDir, outputDir, s | |||
88 | return | 90 | return |
89 | } | 91 | } |
90 | 92 | ||
91 | elements = parse(dirPath, elements, exts, true) | 93 | parsed := false |
94 | elements, parsed = parse(dirPath, elements, exts, true) | ||
92 | 95 | ||
93 | if recursive { | 96 | if recursive { |
94 | dirs, _ := fcmd.Ls(dirPath) | 97 | dirs, _ := fcmd.Ls(dirPath) |
@@ -98,6 +101,10 @@ func compile(dirPath string, elements map[string][]byte, sourceDir, outputDir, s | |||
98 | } | 101 | } |
99 | } | 102 | } |
100 | 103 | ||
104 | if !parsed { | ||
105 | return | ||
106 | } | ||
107 | |||
101 | pagePath := strings.TrimPrefix(dirPath, sourceDir) | 108 | pagePath := strings.TrimPrefix(dirPath, sourceDir) |
102 | 109 | ||
103 | template := merge(elements) | 110 | template := merge(elements) |
@@ -46,7 +46,12 @@ func handle(w http.ResponseWriter, r *http.Request) { | |||
46 | // parse these dirs | 46 | // parse these dirs |
47 | elements := make(map[string][]byte) | 47 | elements := make(map[string][]byte) |
48 | for i := len(dirs) - 1; i >= 0; i-- { | 48 | for i := len(dirs) - 1; i >= 0; i-- { |
49 | elements = parse(path.Join(*settings.sourceDir, dirs[i]), elements, settings.exts, false) | 49 | parsed := false |
50 | elements, parsed = parse(path.Join(*settings.sourceDir, dirs[i]), elements, settings.exts, false) | ||
51 | if (i == len(dirs)-1) && !parsed { | ||
52 | http.Error(w, "404 page not found", http.StatusNotFound) | ||
53 | return | ||
54 | } | ||
50 | } | 55 | } |
51 | 56 | ||
52 | // render the page | 57 | // render the page |
diff --git a/interactive.go b/interactive.go index 1baa4cc..221a189 100644 --- a/interactive.go +++ b/interactive.go | |||
@@ -46,7 +46,7 @@ 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, exts, false) | 49 | elements, _ = parse(path.Join(sourceDir, dir), elements, exts, false) |
50 | } | 50 | } |
51 | return elements | 51 | return elements |
52 | } | 52 | } |