From 395a76bc4193c0c7182f87778458a68d0079e836 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 14 Feb 2020 15:39:56 +0100 Subject: compiler: metadata sidecar for whole directories GitHub: closes #3 --- compiler/src/Input.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'compiler/src/Input.hs') diff --git a/compiler/src/Input.hs b/compiler/src/Input.hs index cb837e3..e0fc8ef 100644 --- a/compiler/src/Input.hs +++ b/compiler/src/Input.hs @@ -58,6 +58,7 @@ data InputTree = | InputDir { path :: Path , modTime :: UTCTime + , sidecar :: Sidecar , dirThumbnailPath :: Maybe Path , items :: [InputTree] } deriving Show @@ -79,6 +80,9 @@ emptySidecar = Sidecar sidecarExt :: String sidecarExt = "yaml" +dirSidecar :: String +dirSidecar = "directory." ++ sidecarExt + readSidecarFile :: FilePath -> IO Sidecar readSidecarFile filepath = doesFileExist filepath @@ -107,7 +111,8 @@ readInputTree (AnchoredFSNode anchor root@Dir{}) = mkDirNode root do dirItems <- mapM mkInputNode items modTime <- getModificationTime $ localPath (anchor /> path) - return $ InputDir path modTime (findThumbnail items) (catMaybes dirItems) + sidecar <- readSidecarFile $ localPath (anchor /> path Bool isSidecar Dir{} = False -- cgit v1.2.3 From 26a85722e74eae23a22350064eed204480bbd032 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 16 Feb 2020 12:15:08 +0100 Subject: compiler: unify directory special files --- compiler/src/Input.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'compiler/src/Input.hs') diff --git a/compiler/src/Input.hs b/compiler/src/Input.hs index e0fc8ef..75d1ed3 100644 --- a/compiler/src/Input.hs +++ b/compiler/src/Input.hs @@ -80,8 +80,11 @@ emptySidecar = Sidecar sidecarExt :: String sidecarExt = "yaml" -dirSidecar :: String -dirSidecar = "directory." ++ sidecarExt +dirPropFile :: String +dirPropFile = "_directory" + +dirSidecar :: Path +dirSidecar = Path [dirPropFile] <.> sidecarExt readSidecarFile :: FilePath -> IO Sidecar readSidecarFile filepath = @@ -111,7 +114,7 @@ readInputTree (AnchoredFSNode anchor root@Dir{}) = mkDirNode root do dirItems <- mapM mkInputNode items modTime <- getModificationTime $ localPath (anchor /> path) - sidecar <- readSidecarFile $ localPath (anchor /> path path dirSidecar) return $ InputDir path modTime sidecar (findThumbnail items) (catMaybes dirItems) isSidecar :: FSNode -> Bool @@ -125,7 +128,7 @@ readInputTree (AnchoredFSNode anchor root@Dir{}) = mkDirNode root isThumbnail File{path} = fileName path & fmap dropExtension - & (maybe False ("thumbnail" ==)) + & (maybe False (dirPropFile ==)) findThumbnail :: [FSNode] -> Maybe Path findThumbnail = (fmap Files.path) . (find isThumbnail) -- cgit v1.2.3 From f09e9d9fa29284bd9ae872efe5ba1d526e349011 Mon Sep 17 00:00:00 2001 From: pacien Date: Wed, 26 Feb 2020 22:13:00 +0100 Subject: compiler: add tag inclusion and exclusion globs GitHub: closes #30 --- compiler/src/Input.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'compiler/src/Input.hs') diff --git a/compiler/src/Input.hs b/compiler/src/Input.hs index 75d1ed3..6ed7471 100644 --- a/compiler/src/Input.hs +++ b/compiler/src/Input.hs @@ -19,7 +19,7 @@ module Input ( decodeYamlFile , Sidecar(..) - , InputTree(..), readInputTree + , InputTree(..), readInputTree, filterInputTree ) where @@ -132,3 +132,14 @@ readInputTree (AnchoredFSNode anchor root@Dir{}) = mkDirNode root findThumbnail :: [FSNode] -> Maybe Path findThumbnail = (fmap Files.path) . (find isThumbnail) + +-- | Filters an InputTree. The root is always returned. +filterInputTree :: (InputTree -> Bool) -> InputTree -> InputTree +filterInputTree cond = filterNode + where + filterNode :: InputTree -> InputTree + filterNode inputFile@InputFile{} = inputFile + filterNode inputDir@InputDir{items} = + filter cond items + & map filterNode + & \curatedItems -> inputDir { items = curatedItems } :: InputTree -- cgit v1.2.3