From 430ab983587c525004d2aa0dc8e7707312c7ab60 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 29 Dec 2019 13:53:28 +0100 Subject: compiler: handle empty sidecar files GitHub: closes #1 --- compiler/src/Input.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/src/Input.hs b/compiler/src/Input.hs index 64c1933..c90db5c 100644 --- a/compiler/src/Input.hs +++ b/compiler/src/Input.hs @@ -69,13 +69,21 @@ data Sidecar = Sidecar , tags :: Maybe [String] } deriving (Generic, FromJSON, Show) +emptySidecar :: Sidecar +emptySidecar = Sidecar + { title = Nothing + , date = Nothing + , description = Nothing + , tags = Nothing } + readInputTree :: AnchoredFSNode -> IO InputTree readInputTree (AnchoredFSNode anchor root@Dir{}) = mkDirNode root where mkInputNode :: FSNode -> IO (Maybe InputTree) mkInputNode (File path@(filename:pathto)) | ".yaml" `isExtensionOf` filename = - decodeYamlFile (localPath $ anchor /> path) + (decodeYamlFile (localPath $ anchor /> path) :: IO (Maybe Sidecar)) + >>= return . maybe emptySidecar id >>= return . InputFile ((dropExtension filename):pathto) >>= return . Just mkInputNode File{} = return Nothing -- cgit v1.2.3