gallery/make-pages/Depend.hs

42 lines
1.1 KiB
Haskell
Raw Normal View History

module Depend where
2020-07-15 15:31:46 -04:00
import BuilderQQ
import Info hiding (Text)
2020-07-15 14:09:14 -04:00
import Data.Maybe (fromMaybe)
import Data.Text.Lazy (Text)
import Data.Text.Lazy.Builder (toLazyText)
2020-07-15 14:09:14 -04:00
import System.FilePath
2020-07-15 14:10:09 -04:00
dependSingle :: FilePath -- ^ yaml file name (relative to data dir!)
-> Info
-> FilePath -- ^ output prefix
-> FilePath -- ^ build dir
-> Bool -- ^ include nsfw?
-> Text
dependSingle yaml info prefix build nsfw =
2020-07-15 14:09:14 -04:00
let dir = build </> prefix </> takeDirectory yaml
2020-07-16 05:47:02 -04:00
images = if nsfw then #images info else #sfwImages info
paths = map #path images
index = dir </> "index.html"
2020-07-15 14:09:14 -04:00
deps = thumbFile (thumbnail info) : map pageFile paths ++ paths
deps' = unwords $ map (dir </>) deps
in
toLazyText [b|$@index: $@deps'|]
thumbnail :: Info -> FilePath
2020-07-15 14:07:51 -04:00
thumbnail = fromMaybe (error "no thumbnail or sfw images") . #thumb
addSuffix :: String -> FilePath -> FilePath
addSuffix suf path =
let (pre, ext) = splitExtension path in
pre ++ suf ++ ext
thumbFile :: FilePath -> FilePath
thumbFile = addSuffix "_small"
pageFile :: FilePath -> FilePath
pageFile = addSuffix "_med"