diff options
author | pacien | 2020-01-25 13:47:27 +0100 |
---|---|---|
committer | Notkea | 2020-01-26 22:36:49 +0100 |
commit | 2a336b297237b546f065f706838f4cefad4c3e7c (patch) | |
tree | 9fc69eeaedff9be5ac3c42fb70b242701ae1e8ef /compiler/src/Processors.hs | |
parent | cf91102432b1196b8f3c1fa388b3963948ad49a6 (diff) | |
download | ldgallery-2a336b297237b546f065f706838f4cefad4c3e7c.tar.gz |
compiler: add resource timestamp in generated index
Add a timestamp to resource paths in the gallery index to invalidate
elements in the browser's cache when necessary.
Timestamps are added to resource URLs as a dummy numeric parameter.
GitHub: closes #40
Diffstat (limited to 'compiler/src/Processors.hs')
-rw-r--r-- | compiler/src/Processors.hs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/compiler/src/Processors.hs b/compiler/src/Processors.hs index 1c4a791..2abdec5 100644 --- a/compiler/src/Processors.hs +++ b/compiler/src/Processors.hs | |||
@@ -38,7 +38,7 @@ import Codec.Picture.Extra -- TODO: compare DCT and bilinear (and Lanczos, but i | |||
38 | 38 | ||
39 | import Resource | 39 | import Resource |
40 | ( ItemProcessor, ThumbnailProcessor | 40 | ( ItemProcessor, ThumbnailProcessor |
41 | , GalleryItemProps(..), Resolution(..) ) | 41 | , GalleryItemProps(..), Resolution(..), Resource(..) ) |
42 | 42 | ||
43 | import Files | 43 | import Files |
44 | 44 | ||
@@ -150,6 +150,10 @@ withCached processor inputPath outputPath = | |||
150 | skip = putStrLn $ "Skipping:\t" ++ outputPath | 150 | skip = putStrLn $ "Skipping:\t" ++ outputPath |
151 | 151 | ||
152 | 152 | ||
153 | resourceAt :: FilePath -> Path -> IO Resource | ||
154 | resourceAt fsPath resPath = getModificationTime fsPath >>= return . Resource resPath | ||
155 | |||
156 | |||
153 | type ItemFileProcessor = | 157 | type ItemFileProcessor = |
154 | FileName -- ^ Input base path | 158 | FileName -- ^ Input base path |
155 | -> FileName -- ^ Output base path | 159 | -> FileName -- ^ Output base path |
@@ -159,14 +163,15 @@ type ItemFileProcessor = | |||
159 | itemFileProcessor :: Maybe Resolution -> LossyExportQuality -> Cache -> ItemFileProcessor | 163 | itemFileProcessor :: Maybe Resolution -> LossyExportQuality -> Cache -> ItemFileProcessor |
160 | itemFileProcessor maxResolution jpegExportQuality cached inputBase outputBase resClass inputRes = | 164 | itemFileProcessor maxResolution jpegExportQuality cached inputBase outputBase resClass inputRes = |
161 | cached processor inPath outPath | 165 | cached processor inPath outPath |
162 | >> return (props relOutPath) | 166 | >> resourceAt outPath relOutPath |
167 | >>= return . props | ||
163 | where | 168 | where |
164 | relOutPath = resClass /> inputRes | 169 | relOutPath = resClass /> inputRes |
165 | inPath = localPath $ inputBase /> inputRes | 170 | inPath = localPath $ inputBase /> inputRes |
166 | outPath = localPath $ outputBase /> relOutPath | 171 | outPath = localPath $ outputBase /> relOutPath |
167 | (processor, props) = processorFor maxResolution $ formatFromPath inputRes | 172 | (processor, props) = processorFor maxResolution $ formatFromPath inputRes |
168 | 173 | ||
169 | processorFor :: Maybe Resolution -> Format -> (FileProcessor, Path -> GalleryItemProps) | 174 | processorFor :: Maybe Resolution -> Format -> (FileProcessor, Resource -> GalleryItemProps) |
170 | processorFor Nothing _ = | 175 | processorFor Nothing _ = |
171 | (copyFileProcessor, Other) | 176 | (copyFileProcessor, Other) |
172 | processorFor _ (PictureFormat Gif) = | 177 | processorFor _ (PictureFormat Gif) = |
@@ -192,11 +197,12 @@ thumbnailFileProcessor maxRes jpegExportQuality cached inputBase outputBase resC | |||
192 | inPath = localPath $ inputBase /> inputRes | 197 | inPath = localPath $ inputBase /> inputRes |
193 | outPath = localPath $ outputBase /> relOutPath | 198 | outPath = localPath $ outputBase /> relOutPath |
194 | 199 | ||
195 | process :: Maybe FileProcessor -> IO (Maybe Path) | 200 | process :: Maybe FileProcessor -> IO (Maybe Resource) |
196 | process Nothing = return Nothing | 201 | process Nothing = return Nothing |
197 | process (Just proc) = | 202 | process (Just proc) = |
198 | proc inPath outPath | 203 | proc inPath outPath |
199 | >> return (Just relOutPath) | 204 | >> resourceAt outPath relOutPath |
205 | >>= return . Just | ||
200 | 206 | ||
201 | processorFor :: Format -> Maybe FileProcessor | 207 | processorFor :: Format -> Maybe FileProcessor |
202 | processorFor (PictureFormat picFormat) = | 208 | processorFor (PictureFormat picFormat) = |