diff options
author | pacien | 2020-06-13 03:41:39 +0200 |
---|---|---|
committer | pacien | 2020-06-16 18:23:01 +0200 |
commit | ce2210e6deff1d981186b6d7ddb1176f27e41f49 (patch) | |
tree | 63d83660e733f16ef18d48debbc97c091c492c1f /compiler/src/Files.hs | |
parent | 34b90f08a21fbe3f1928e16a8ea48f1fc7453e4e (diff) | |
download | ldgallery-ce2210e6deff1d981186b6d7ddb1176f27e41f49.tar.gz |
compiler: make GalleryIndex loadable from JSON
Diffstat (limited to 'compiler/src/Files.hs')
-rw-r--r-- | compiler/src/Files.hs | 14 |
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 | |||
31 | import Data.List (isPrefixOf, length, sortOn) | 31 | import Data.List (isPrefixOf, length, sortOn) |
32 | import Data.Function ((&)) | 32 | import Data.Function ((&)) |
33 | import Data.Functor ((<&>)) | 33 | import Data.Functor ((<&>)) |
34 | import Data.Text (pack) | 34 | import Data.Text (pack, unpack) |
35 | import Data.Aeson (ToJSON) | 35 | import Data.Aeson (ToJSON, FromJSON) |
36 | import qualified Data.Aeson as JSON | 36 | import qualified Data.Aeson as JSON |
37 | 37 | ||
38 | import System.Directory | 38 | import System.Directory |
@@ -59,8 +59,11 @@ newtype Path = Path [FileName] deriving Show | |||
59 | instance ToJSON Path where | 59 | instance ToJSON Path where |
60 | toJSON = JSON.String . pack . webPath | 60 | toJSON = JSON.String . pack . webPath |
61 | 61 | ||
62 | instance FromJSON Path where | ||
63 | parseJSON = JSON.withText "Path" (return . fromWebPath . unpack) | ||
64 | |||
62 | instance Eq Path where | 65 | instance 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 | |||
95 | webPath :: Path -> WebPath | 98 | webPath :: Path -> WebPath |
96 | webPath (Path path) = System.FilePath.Posix.joinPath $ reverse path | 99 | webPath (Path path) = System.FilePath.Posix.joinPath $ reverse path |
97 | 100 | ||
101 | fromWebPath :: WebPath -> Path | ||
102 | fromWebPath = Path . reverse . System.FilePath.Posix.splitDirectories | ||
103 | |||
98 | 104 | ||
99 | data FSNode = | 105 | data FSNode = |
100 | File | 106 | File |