diff options
author | pacien | 2020-05-02 04:11:24 +0200 |
---|---|---|
committer | pacien | 2020-05-02 04:11:24 +0200 |
commit | 8e3ac8fe44bebb38e1882ca7f06b8100078ad88d (patch) | |
tree | a748fa1e639cb3b5e1f24a8150e89dbb28c980cb /compiler | |
parent | 7042ffc06326fa8ffe70f5a59747709250166c16 (diff) | |
parent | 0e0b5b0ae44da7c1d67983dedd8f8d8d3516236f (diff) | |
download | ldgallery-8e3ac8fe44bebb38e1882ca7f06b8100078ad88d.tar.gz |
Merge branch 'develop': release v1.0v1.0
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/app/Main.hs | 117 | ||||
-rw-r--r-- | compiler/ldgallery.1.md | 191 | ||||
-rw-r--r-- | compiler/package.yaml | 13 | ||||
-rw-r--r-- | compiler/src/Compiler.hs | 130 | ||||
-rw-r--r-- | compiler/src/Config.hs | 76 | ||||
-rw-r--r-- | compiler/src/Files.hs | 55 | ||||
-rw-r--r-- | compiler/src/Input.hs | 25 | ||||
-rw-r--r-- | compiler/src/Processors.hs | 144 | ||||
-rw-r--r-- | compiler/src/Resource.hs | 151 | ||||
-rw-r--r-- | compiler/stack.yaml | 8 | ||||
-rw-r--r-- | compiler/stack.yaml.lock | 8 | ||||
-rw-r--r-- | compiler/win_build.cmd | 4 | ||||
-rw-r--r-- | compiler/win_compile_example.cmd | 10 |
13 files changed, 657 insertions, 275 deletions
diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 1a42abf..48e5644 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs | |||
@@ -18,20 +18,33 @@ | |||
18 | 18 | ||
19 | module Main where | 19 | module Main where |
20 | 20 | ||
21 | import GHC.Generics (Generic) | ||
21 | import Paths_ldgallery_compiler (version, getDataFileName) | 22 | import Paths_ldgallery_compiler (version, getDataFileName) |
23 | import Control.Monad (when) | ||
24 | import Data.Maybe (isJust) | ||
22 | import Data.Version (showVersion) | 25 | import Data.Version (showVersion) |
26 | import Data.Aeson (ToJSON) | ||
23 | import System.FilePath ((</>)) | 27 | import System.FilePath ((</>)) |
28 | import System.Directory (canonicalizePath, listDirectory) | ||
24 | import System.Console.CmdArgs | 29 | import System.Console.CmdArgs |
25 | 30 | ||
26 | import Compiler | 31 | import Compiler |
27 | import Files (readDirectory, copyTo) | 32 | import Files (readDirectory, copyTo, remove) |
33 | |||
34 | |||
35 | data ViewerConfig = ViewerConfig | ||
36 | { galleryRoot :: String | ||
37 | } deriving (Generic, Show, ToJSON) | ||
28 | 38 | ||
29 | 39 | ||
30 | data Options = Options | 40 | data Options = Options |
31 | { inputDir :: String | 41 | { inputDir :: FilePath |
32 | , outputDir :: String | 42 | , outputDir :: FilePath |
43 | , outputIndex :: FilePath | ||
44 | , galleryConfig :: FilePath | ||
33 | , rebuilAll :: Bool | 45 | , rebuilAll :: Bool |
34 | , withViewer :: Bool | 46 | , cleanOutput :: Bool |
47 | , withViewer :: Maybe FilePath | ||
35 | } deriving (Show, Data, Typeable) | 48 | } deriving (Show, Data, Typeable) |
36 | 49 | ||
37 | options :: Options | 50 | options :: Options |
@@ -48,16 +61,35 @@ options = Options | |||
48 | &= name "output-dir" | 61 | &= name "output-dir" |
49 | &= explicit | 62 | &= explicit |
50 | &= help "Generated gallery output path (default=./out)" | 63 | &= help "Generated gallery output path (default=./out)" |
64 | , outputIndex = "" | ||
65 | &= typFile | ||
66 | &= name "x" | ||
67 | &= name "output-index" | ||
68 | &= explicit | ||
69 | &= help "Generated gallery index output path (default=<output-dir>/index.json)" | ||
70 | , galleryConfig = "" | ||
71 | &= typFile | ||
72 | &= name "g" | ||
73 | &= name "gallery-config" | ||
74 | &= explicit | ||
75 | &= help "Gallery configuration file (default=<input-dir>/gallery.yaml)" | ||
51 | , rebuilAll = False | 76 | , rebuilAll = False |
52 | &= name "r" | 77 | &= name "r" |
53 | &= name "rebuild-all" | 78 | &= name "rebuild-all" |
54 | &= explicit | 79 | &= explicit |
55 | &= help "Invalidate cache and recompile everything" | 80 | &= help "Invalidate cache and recompile everything" |
56 | , withViewer = False | 81 | , cleanOutput = False |
82 | &= name "c" | ||
83 | &= name "clean-output" | ||
84 | &= explicit | ||
85 | &= help "Remove unnecessary files from the output directory" | ||
86 | , withViewer = Nothing | ||
87 | &= typDir | ||
88 | &= opt ("" :: FilePath) | ||
57 | &= name "w" | 89 | &= name "w" |
58 | &= name "with-viewer" | 90 | &= name "with-viewer" |
59 | &= explicit | 91 | &= explicit |
60 | &= help "Include the static web viewer in the output" | 92 | &= help "Deploy either the bundled or the given static web viewer to the output directory" |
61 | } | 93 | } |
62 | 94 | ||
63 | &= summary ("ldgallery v" ++ (showVersion version) ++ " - a static web gallery generator with tags") | 95 | &= summary ("ldgallery v" ++ (showVersion version) ++ " - a static web gallery generator with tags") |
@@ -71,21 +103,62 @@ main :: IO () | |||
71 | main = | 103 | main = |
72 | do | 104 | do |
73 | opts <- cmdArgs options | 105 | opts <- cmdArgs options |
74 | compileGallery (inputDir opts) (galleryOutputDir "gallery" opts) (rebuilAll opts) | 106 | buildGallery opts |
75 | if (withViewer opts) then copyViewer (outputDir opts) else noop | 107 | |
108 | when (isJust $ withViewer opts) $ do | ||
109 | viewerDist <- viewerDistPath $ withViewer opts | ||
110 | deployViewer viewerDist opts | ||
76 | 111 | ||
77 | where | 112 | where |
78 | galleryOutputDir :: FilePath -> Options -> FilePath | 113 | gallerySubdir :: String |
79 | galleryOutputDir gallerySubdir opts = | 114 | gallerySubdir = "gallery" |
80 | if withViewer opts then outputBase </> gallerySubdir else outputBase | 115 | |
81 | where outputBase = outputDir opts | 116 | viewerConfig :: ViewerConfig |
82 | 117 | viewerConfig = ViewerConfig (gallerySubdir ++ "/") | |
83 | copyViewer :: FilePath -> IO () | 118 | |
84 | copyViewer target = | 119 | viewerDistPath :: Maybe FilePath -> IO FilePath |
85 | putStrLn "Copying viewer webapp" | 120 | viewerDistPath (Just "") = getDataFileName "viewer" |
86 | >> getDataFileName "viewer" | 121 | viewerDistPath (Just dist) = return dist |
87 | >>= readDirectory | 122 | viewerDistPath Nothing = fail "No viewer distribution" |
88 | >>= copyTo target | 123 | |
89 | 124 | buildGallery :: Options -> IO () | |
90 | noop :: IO () | 125 | buildGallery opts = |
91 | noop = return () | 126 | checkDistinctPaths (inputDir opts) (outputDir opts) |
127 | >> compileGallery | ||
128 | (galleryConfig opts) | ||
129 | (inputDir opts) | ||
130 | (galleryOutputDir opts) | ||
131 | (outputIndex opts) | ||
132 | [outputDir opts] | ||
133 | (rebuilAll opts) | ||
134 | (cleanOutput opts) | ||
135 | where | ||
136 | checkDistinctPaths :: FilePath -> FilePath -> IO () | ||
137 | checkDistinctPaths a b = do | ||
138 | canonicalA <- canonicalizePath a | ||
139 | canonicalB <- canonicalizePath b | ||
140 | when (canonicalA == canonicalB) $ error "Input and output paths refer to the same location." | ||
141 | |||
142 | galleryOutputDir :: Options -> FilePath | ||
143 | galleryOutputDir Options{withViewer, outputDir} | ||
144 | | isJust withViewer = outputDir </> gallerySubdir | ||
145 | | otherwise = outputDir | ||
146 | |||
147 | deployViewer :: FilePath -> Options -> IO () | ||
148 | deployViewer distPath Options{outputDir, cleanOutput} = | ||
149 | (when cleanOutput $ cleanViewerDir outputDir) | ||
150 | >> copyViewer distPath outputDir | ||
151 | >> writeJSON (outputDir </> "config.json") viewerConfig | ||
152 | |||
153 | where | ||
154 | cleanViewerDir :: FilePath -> IO () | ||
155 | cleanViewerDir target = | ||
156 | listDirectory target | ||
157 | >>= return . filter (/= gallerySubdir) | ||
158 | >>= mapM_ remove . map (target </>) | ||
159 | |||
160 | copyViewer :: FilePath -> FilePath -> IO () | ||
161 | copyViewer dist target = | ||
162 | putStrLn "Copying viewer webapp" | ||
163 | >> readDirectory dist | ||
164 | >>= copyTo target | ||
diff --git a/compiler/ldgallery.1.md b/compiler/ldgallery.1.md new file mode 100644 index 0000000..a60a3b1 --- /dev/null +++ b/compiler/ldgallery.1.md | |||
@@ -0,0 +1,191 @@ | |||
1 | --- | ||
2 | pagetitle: Compiler user manual - ldgallery | ||
3 | title: LDGALLERY(1) ldgallery | ||
4 | author: Pacien TRAN-GIRARD, Guillaume FOUET | ||
5 | date: 2020-04-30 (v1.0) | ||
6 | --- | ||
7 | |||
8 | |||
9 | # NAME | ||
10 | |||
11 | ldgallery - a static web gallery generator with tags | ||
12 | |||
13 | |||
14 | # DESCRIPTION | ||
15 | |||
16 | ldgallery is a static gallery generator which turns a collection of tagged pictures into a searchable web gallery. | ||
17 | |||
18 | The ldgallery compiler program processes pictures and aggregates metadata from plain text sidecar files to generate an indexed version of the gallery. | ||
19 | It can optionally output a static web viewer along, which allows the content to be presented and searched through from a JavaScript-enabled web browser. | ||
20 | This client-side web application does not require any special software on the server's side. | ||
21 | |||
22 | |||
23 | # COMMAND | ||
24 | |||
25 | ldgallery [\--input-dir _./_] [\--output-dir _./out_] [\--with-viewer] | ||
26 | |||
27 | Available options are: | ||
28 | |||
29 | -i, \--input-dir _DIR_ | ||
30 | : Gallery source directory. | ||
31 | Defaults to the current directory. | ||
32 | |||
33 | -o, \--output-dir _DIR_ | ||
34 | : Generated gallery output path. | ||
35 | Must be distinct from the source directory. | ||
36 | Defaults to ./out. | ||
37 | |||
38 | -x, \--output-index _FILE_ | ||
39 | : Generated gallery index output path. | ||
40 | Defaults to \<output-dir\>/index.json. | ||
41 | |||
42 | -g, \--gallery-config _FILE_ | ||
43 | : Gallery configuration file. | ||
44 | Defaults to \<input-dir\>/gallery.yaml. | ||
45 | |||
46 | -r, \--rebuild-all | ||
47 | : Invalidate cache and recompile everything. | ||
48 | |||
49 | -c, \--clean-output | ||
50 | : Remove unnecessary files from the output directory. | ||
51 | |||
52 | -w, \--with-viewer[=_DIR_] | ||
53 | : Deploy either the bundled or the given static web viewer to the output directory. | ||
54 | The compiled gallery itself is then placed in \<output-dir\>/gallery. | ||
55 | |||
56 | -h, \--help | ||
57 | : Display help message. | ||