2020-07-15 05:45:15 -04:00
|
|
|
module Depend where
|
|
|
|
|
2020-07-15 14:09:14 -04:00
|
|
|
import BuildVar
|
2020-07-15 05:45:15 -04:00
|
|
|
import Info hiding (Text)
|
2020-07-15 14:09:14 -04:00
|
|
|
|
|
|
|
import Data.Maybe (fromMaybe)
|
2020-07-15 05:45:15 -04:00
|
|
|
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 05:45:15 -04:00
|
|
|
|
|
|
|
|
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-15 05:45:15 -04:00
|
|
|
images = if nsfw then #images info else filter #sfw $ #images 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
|
2020-07-15 05:45:15 -04:00
|
|
|
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
|
2020-07-15 05:45:15 -04:00
|
|
|
|
|
|
|
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"
|