aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Files.hs
diff options
context:
space:
mode:
authorpacien2020-06-13 03:41:39 +0200
committerpacien2020-06-16 18:23:01 +0200
commitce2210e6deff1d981186b6d7ddb1176f27e41f49 (patch)
tree63d83660e733f16ef18d48debbc97c091c492c1f /compiler/src/Files.hs
parent34b90f08a21fbe3f1928e16a8ea48f1fc7453e4e (diff)
downloadldgallery-ce2210e6deff1d981186b6d7ddb1176f27e41f49.tar.gz
compiler: make GalleryIndex loadable from JSON
Diffstat (limited to 'compiler/src/Files.hs')
-rw-r--r--compiler/src/Files.hs14
1 files changed, 10 insertions, 4 deletions
diff --git a/compiler/src/Files.hs b/compiler/src/Files.hs
index 1f14e7f..023546b 100644
--- a/compiler/src/Files.hs
+++ b/compiler/src/Files.hs
@@ -20,7 +20,7 @@ module Files
20 ( FileName, LocalPath, WebPath, Path(..) 20 ( FileName, LocalPath, WebPath, Path(..)
21 , (</>), (</), (/>), (<.>) 21 , (</>), (</), (/>), (<.>)
22 , fileName, subPaths, pathLength 22 , fileName, subPaths, pathLength
23 , localPath, webPath 23 , localPath, webPath, fromWebPath
24 , FSNode(..), AnchoredFSNode(..) 24 , FSNode(..), AnchoredFSNode(..)
25 , nodeName, isHidden, flattenDir, filterDir 25 , nodeName, isHidden, flattenDir, filterDir
26 , readDirectory, copyTo 26 , readDirectory, copyTo
@@ -31,8 +31,8 @@ module Files
31import Data.List (isPrefixOf, length, sortOn) 31import Data.List (isPrefixOf, length, sortOn)
32import Data.Function ((&)) 32import Data.Function ((&))
33import Data.Functor ((<&>)) 33import Data.Functor ((<&>))
34import Data.Text (pack) 34import Data.Text (pack, unpack)
35import Data.Aeson (ToJSON) 35import Data.Aeson (ToJSON, FromJSON)
36import qualified Data.Aeson as JSON 36import qualified Data.Aeson as JSON
37 37
38import System.Directory 38import System.Directory
@@ -59,8 +59,11 @@ newtype Path = Path [FileName] deriving Show
59instance ToJSON Path where 59instance ToJSON Path where
60 toJSON = JSON.String . pack . webPath 60 toJSON = JSON.String . pack . webPath
61 61
62instance FromJSON Path where
63 parseJSON = JSON.withText "Path" (return . fromWebPath . unpack)
64
62instance Eq Path where 65instance Eq Path where
63 (Path left) == (Path right) = left == right 66 left == right = webPath left == webPath right
64 67
65(</>) :: Path -> Path -> Path 68(</>) :: Path -> Path -> Path
66(Path l) </> (Path r) = Path (r ++ l) 69(Path l) </> (Path r) = Path (r ++ l)
@@ -95,6 +98,9 @@ localPath (Path path) = System.FilePath.joinPath $ reverse path
95webPath :: Path -> WebPath 98webPath :: Path -> WebPath
96webPath (Path path) = System.FilePath.Posix.joinPath $ reverse path 99webPath (Path path) = System.FilePath.Posix.joinPath $ reverse path
97 100
101fromWebPath :: WebPath -> Path
102fromWebPath = Path . reverse . System.FilePath.Posix.splitDirectories
103
98 104
99data FSNode = 105data FSNode =
100 File 106 File