diff options
Diffstat (limited to 'compiler/src/Compiler.hs')
-rw-r--r-- | compiler/src/Compiler.hs | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 8819ffc..d392f74 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs | |||
@@ -26,6 +26,7 @@ import Control.Monad (liftM2) | |||
26 | import Data.List (any) | 26 | import Data.List (any) |
27 | import System.FilePath ((</>)) | 27 | import System.FilePath ((</>)) |
28 | import qualified System.FilePath.Glob as Glob | 28 | import qualified System.FilePath.Glob as Glob |
29 | import System.Directory (canonicalizePath) | ||
29 | 30 | ||
30 | import Data.Aeson (ToJSON) | 31 | import Data.Aeson (ToJSON) |
31 | import qualified Data.Aeson as JSON | 32 | import qualified Data.Aeson as JSON |
@@ -52,9 +53,6 @@ galleryConf = "gallery.yaml" | |||
52 | indexFile :: String | 53 | indexFile :: String |
53 | indexFile = "index.json" | 54 | indexFile = "index.json" |
54 | 55 | ||
55 | viewerMainFile :: String | ||
56 | viewerMainFile = "index.html" | ||
57 | |||
58 | viewerConfFile :: String | 56 | viewerConfFile :: String |
59 | viewerConfFile = "viewer.json" | 57 | viewerConfFile = "viewer.json" |
60 | 58 | ||
@@ -72,11 +70,11 @@ writeJSON outputPath object = | |||
72 | ensureParentDir JSON.encodeFile outputPath object | 70 | ensureParentDir JSON.encodeFile outputPath object |
73 | 71 | ||
74 | 72 | ||
75 | galleryDirFilter :: CompilerConfig -> FSNode -> Bool | 73 | galleryDirFilter :: CompilerConfig -> FilePath -> FSNode -> Bool |
76 | galleryDirFilter config = | 74 | galleryDirFilter config outputDir = |
77 | (not . isHidden) | 75 | (not . isHidden) |
76 | &&& (not . isOutputGallery) | ||
78 | &&& (not . matchesFile (== galleryConf)) | 77 | &&& (not . matchesFile (== galleryConf)) |
79 | &&& (not . containsOutputGallery) | ||
80 | &&& ((matchesDir $ anyPattern $ includedDirectories config) ||| | 78 | &&& ((matchesDir $ anyPattern $ includedDirectories config) ||| |
81 | (matchesFile $ anyPattern $ includedFiles config)) | 79 | (matchesFile $ anyPattern $ includedFiles config)) |
82 | &&& (not . ((matchesDir $ anyPattern $ excludedDirectories config) ||| | 80 | &&& (not . ((matchesDir $ anyPattern $ excludedDirectories config) ||| |
@@ -97,10 +95,9 @@ galleryDirFilter config = | |||
97 | anyPattern :: [String] -> FileName -> Bool | 95 | anyPattern :: [String] -> FileName -> Bool |
98 | anyPattern patterns filename = any (flip Glob.match filename) (map Glob.compile patterns) | 96 | anyPattern patterns filename = any (flip Glob.match filename) (map Glob.compile patterns) |
99 | 97 | ||
100 | containsOutputGallery :: FSNode -> Bool | 98 | isOutputGallery :: FSNode -> Bool |
101 | containsOutputGallery File{} = False | 99 | isOutputGallery Dir{canonicalPath} = canonicalPath == outputDir |
102 | containsOutputGallery Dir{items} = | 100 | isOutputGallery File{} = False |
103 | any (matchesFile (== indexFile) ||| matchesFile (== viewerMainFile)) items | ||
104 | 101 | ||
105 | 102 | ||
106 | compileGallery :: FilePath -> FilePath -> Bool -> Bool -> IO () | 103 | compileGallery :: FilePath -> FilePath -> Bool -> Bool -> IO () |
@@ -110,7 +107,8 @@ compileGallery inputDirPath outputDirPath rebuildAll cleanOutput = | |||
110 | let config = compiler fullConfig | 107 | let config = compiler fullConfig |
111 | 108 | ||
112 | inputDir <- readDirectory inputDirPath | 109 | inputDir <- readDirectory inputDirPath |
113 | let sourceFilter = galleryDirFilter config | 110 | canonicalOutPath <- canonicalizePath outputDirPath |
111 | let sourceFilter = galleryDirFilter config canonicalOutPath | ||
114 | let sourceTree = filterDir sourceFilter inputDir | 112 | let sourceTree = filterDir sourceFilter inputDir |
115 | inputTree <- readInputTree sourceTree | 113 | inputTree <- readInputTree sourceTree |
116 | 114 | ||