aboutsummaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ldgallery.1.md154
-rw-r--r--compiler/src/Compiler.hs7
-rw-r--r--compiler/src/Config.hs45
3 files changed, 180 insertions, 26 deletions
diff --git a/compiler/ldgallery.1.md b/compiler/ldgallery.1.md
new file mode 100644
index 0000000..5524409
--- /dev/null
+++ b/compiler/ldgallery.1.md
@@ -0,0 +1,154 @@
1---
2pagetitle: User manual - ldgallery
3title: LDGALLERY(1) ldgallery user manual
4author: Pacien TRAN-GIRARD, Guillaume FOUET
5date: 2020-02-15 (v0.1.0.0-SNAPSHOT)
6---
7
8
9# NAME
10
11ldgallery - a static web gallery generator with tags
12
13
14# DESCRIPTION
15
16ldgallery is a static gallery generator which turns a collection of tagged pictures into a searchable web gallery.
17
18The ldgallery compiler program processes pictures and aggregates metadata from plain text sidecar files to generate an indexed version of the gallery. 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. This client-side web application does not require any special software on the server's side.
19
20
21# COMMAND
22
23ldgallery [\--input-dir _./_] [\--output-dir _./out_] [\--with-viewer]
24
25Available options are:
26
27-i, \--input-dir _DIR_
28: Gallery source directory.
29 Defaults to the current directory.
30
31-o, \--output-dir _DIR_
32: Generated gallery output path.
33 Must be distinct from the source directory.
34 Defaults to ./out.
35
36-g, \--gallery-config _FILE_
37: Gallery configuration file.
38 Defaults to $input-dir/gallery.yaml.
39
40-r, \--rebuild-all
41: Invalidate cache and recompile everything.
42
43-c, \--clean-output
44: Remove unnecessary files from the output directory.
45
46-w, \--with-viewer
47: Include the static web viewer in the output.
48
49-h, \--help
50: Display help message.
51
52\--version
53: Print version information.
54
55\--numeric-version
56: Print just the version number.
57
58
59# INPUT GALLERY STRUCTURE
60
61A gallery source directory contains the gallery items and their sidecar metadata files, optionally grouped inside sub-directories.
62
63Directory thumbnails can be set by placing a picture file named "_directory", with any image file extension, inside of directories.
64
65An example input gallery directory structure could be as follows:
66
67```
68./example-gallery
69├── DSC0001.jpg --------- a picture
70├── DSC0001.jpg.yaml ---- its associated sidecar metadata file
71├── Some directory ------ a directory grouping gallery items
72│ ├── _directory.jpg -- a thumbnail for its parent directory
73│ ├── _directory.yaml - directory sidecar metadata file
74│ ├── DSC0002.jpg
75│ ├── DSC0002.jpg.yaml
76│ ├── DSC0003.jpg
77│ └── DSC0003.jpg.yaml
78└── gallery.yaml -------- gallery settings file
79```
80
81
82# METADATA SIDECAR
83
84File metadata are read from sidecar files of the same name, with the ".yaml" extension appended.
85Metadata contained within item files themselves (e.g. Exif fields for pictures) are ignored.
86
87Directory metadata are read from sidecar files named "_directory.yaml" located within the directory.
88
89When a sidecar file is absent or a particular key omitted, values are set as empty or to their fallback value specified below.
90
91title
92: Title of the item.
93 Defaults to the name of the file or directory.
94
95datetime
96: ISO 8601 zoned date and time.
97 Defaults to the last modification time of the file itself,
98 or the most recent modification date of a directory's items.
99
100description
101: Description for the item.
102
103tags
104: List of tags for the item.
105 Tag groups can be defined using prefixes separated by "." (dot).
106 Tags specified in a directory metadata sidecar are applied to all items within that directory.
107
108
109# GALLERY CONFIGURATION
110
111The gallery settings reside in a file named "gallery.yaml" located at the root of the gallery's source directory.
112
113includedDirectories[]
114: Glob patterns of directory names to include in the gallery. Defaults to ["*"] (matches all directory names).
115
116excludedDirectories[]
117: Glob patterns of directory names to exclude from the gallery. Defaults to [] (none).
118
119includedFiles[]
120: Glob patterns of file names to include in the gallery. Defaults to ["*"] (matches all file names).
121
122excludedFiles[]
123: Glob patterns of file names to exclude from the gallery. Defaults to [] (none).
124
125tagsFromDirectories.fromParents
126: Automatically generate tags from the name of parent directories,
127 looking up in the hierarchy as far as indicated by this parameter.
128 Defaults to 0 (do not generate tags from parent directories).
129
130tagsFromDirectories.prefix
131: Prefix to use for tags automatically generated from the parent directories' names.
132
133thumbnailMaxResolution.width
134: Maximum width in pixels of the item thumbnails, 400 by default.
135
136thumbnailMaxResolution.height
137: Maximum height in pixels of the item thumbnails, 300 by default.
138
139pictureMaxResolution.width
140: Maximum width in pixels of the picture items, unlimited by default.
141
142pictureMaxResolution.height
143: Maximum height in pixels of the picture items, unlimited by default.
144
145
146# SEE ALSO
147
148The ldgallery source code is available on <https://ldgallery.pacien.org>.
149
150Copyright (C) 2019-2020 Pacien TRAN-GIRARD and Guillaume FOUET.
151
152This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
153
154This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details <https://www.gnu.org/licenses/agpl-3.0.html>.
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs
index bb0ee97..73ac8a4 100644
--- a/compiler/src/Compiler.hs
+++ b/compiler/src/Compiler.hs
@@ -70,7 +70,7 @@ writeJSON outputPath object =
70 ensureParentDir JSON.encodeFile outputPath object 70 ensureParentDir JSON.encodeFile outputPath object
71 71
72 72
73galleryDirFilter :: CompilerConfig -> [FilePath] -> FSNode -> Bool 73galleryDirFilter :: GalleryConfig -> [FilePath] -> FSNode -> Bool
74galleryDirFilter config excludedCanonicalDirs = 74galleryDirFilter config excludedCanonicalDirs =
75 (not . isHidden) 75 (not . isHidden)
76 &&& (not . isExcludedDir) 76 &&& (not . isExcludedDir)
@@ -102,8 +102,7 @@ galleryDirFilter config excludedCanonicalDirs =
102compileGallery :: FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () 102compileGallery :: FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO ()
103compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = 103compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput =
104 do 104 do
105 fullConfig <- readConfig $ inputGalleryConf configPath 105 config <- readConfig $ inputGalleryConf configPath
106 let config = compiler fullConfig
107 106
108 inputDir <- readDirectory inputDirPath 107 inputDir <- readDirectory inputDirPath
109 excludedCanonicalDirs <- mapM canonicalizePath excludedDirs 108 excludedCanonicalDirs <- mapM canonicalizePath excludedDirs
@@ -119,7 +118,7 @@ compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cle
119 118
120 when cleanOutput $ galleryCleanupResourceDir resources outputDirPath 119 when cleanOutput $ galleryCleanupResourceDir resources outputDirPath
121 writeJSON outputIndex resources 120 writeJSON outputIndex resources
122 writeJSON outputViewerConf $ viewer fullConfig 121 writeJSON outputViewerConf $ viewerConfig config
123 122
124 where 123 where
125 inputGalleryConf :: FilePath -> FilePath 124 inputGalleryConf :: FilePath -> FilePath
diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs
index bf5a28e..5f1806d 100644
--- a/compiler/src/Config.hs
+++ b/compiler/src/Config.hs
@@ -17,11 +17,10 @@
17-- along with this program. If not, see <https://www.gnu.org/licenses/>. 17-- along with this program. If not, see <https://www.gnu.org/licenses/>.
18 18
19module Config 19module Config
20 ( GalleryConfig(..) 20 ( GalleryConfig(..), readConfig
21 , CompilerConfig(..) 21 , ViewerConfig(..), viewerConfig
22 , TagsFromDirectoriesConfig(..) 22 , TagsFromDirectoriesConfig(..)
23 , Resolution(..) 23 , Resolution(..)
24 , readConfig
25 ) where 24 ) where
26 25
27 26
@@ -39,7 +38,18 @@ data Resolution = Resolution
39 } deriving (Generic, Show, ToJSON, FromJSON) 38 } deriving (Generic, Show, ToJSON, FromJSON)
40 39
41 40
42data CompilerConfig = CompilerConfig 41data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig
42 { fromParents :: Int
43 , prefix :: String
44 } deriving (Generic, Show)
45
46instance FromJSON TagsFromDirectoriesConfig where
47 parseJSON = withObject "TagsFromDirectoriesConfig" $ \v -> TagsFromDirectoriesConfig
48 <$> v .:? "fromParents" .!= 0
49 <*> v .:? "prefix" .!= ""
50
51
52data GalleryConfig = GalleryConfig
43 { includedDirectories :: [String] 53 { includedDirectories :: [String]
44 , excludedDirectories :: [String] 54 , excludedDirectories :: [String]
45 , includedFiles :: [String] 55 , includedFiles :: [String]
@@ -49,8 +59,8 @@ data CompilerConfig = CompilerConfig
49 , pictureMaxResolution :: Maybe Resolution 59 , pictureMaxResolution :: Maybe Resolution
50 } deriving (Generic, Show) 60 } deriving (Generic, Show)
51 61
52instance FromJSON CompilerConfig where 62instance FromJSON GalleryConfig where
53 parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig 63 parseJSON = withObject "GalleryConfig" $ \v -> GalleryConfig
54 <$> v .:? "includedDirectories" .!= ["*"]