module Depend where import BuildVar import Info hiding (Text) import Data.Maybe (fromMaybe) import Data.Text.Lazy (Text) import Data.Text.Lazy.Builder (toLazyText) import System.FilePath 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 = let dir = build prefix takeDirectory yaml images = if nsfw then #images info else filter #sfw $ #images info paths = map #path images index = dir "index.html" deps = thumbFile (thumbnail info) : map pageFile paths ++ paths deps' = unwords $ map (dir ) deps in toLazyText [b|$@index: $@deps'|] thumbnail :: Info -> FilePath 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"