module Depend where import Info hiding (Text) import Data.Foldable import System.FilePath import Data.Text.Lazy (Text) import Data.Text.Lazy.Builder (toLazyText) import BuildVar dependSingle' :: FilePath -- ^ yaml file name (relative to data dir!) -> Info -> FilePath -- ^ build dir -> Bool -- ^ include nsfw? -> Text dependSingle' yaml info build nsfw = let dir = build takeDirectory yaml images = if nsfw then #images info else filter #sfw $ #images info paths = map #path images index = dir "index.html" deps = map (dir ) $ thumbFile (thumbnail info) : map pageFile paths ++ paths deps' = unwords deps in toLazyText [b|$@index: $@deps'|] thumbnail :: Info -> FilePath thumbnail (Info {thumb = Just t}) = t thumbnail (Info {images}) | Just i <- find #sfw images = #path i | otherwise = error "no thumbnail or sfw images" 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"