2020-07-16 10:07:28 -04:00
|
|
|
module Depend
|
|
|
|
(dependSingle, dependSingle',
|
|
|
|
dependGallery, dependGallery',
|
2022-05-16 04:25:16 -04:00
|
|
|
thumbFile, pageFile, bigFile)
|
2020-07-16 10:07:28 -04:00
|
|
|
where
|
2020-07-15 05:45:15 -04:00
|
|
|
|
2022-01-03 14:45:55 -05:00
|
|
|
import BuilderQQ hiding (CanBuild (..))
|
2020-07-15 05:45:15 -04:00
|
|
|
import Info hiding (Text)
|
2020-07-15 14:09:14 -04:00
|
|
|
|
2020-07-21 19:48:29 -04:00
|
|
|
import Data.Maybe (fromMaybe, mapMaybe)
|
2020-07-15 05:45:15 -04:00
|
|
|
import Data.Text.Lazy (Text)
|
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
|
2020-07-16 10:07:28 -04:00
|
|
|
dependSingle yamlDir info prefix build nsfw =
|
|
|
|
toLazyText $ dependSingle' yamlDir info prefix build nsfw
|
|
|
|
|
|
|
|
dependSingle' :: FilePath -> Info -> FilePath -> FilePath -> Bool -> Builder
|
|
|
|
dependSingle' yamlDir info prefix build nsfw =
|
2020-08-30 13:13:40 -04:00
|
|
|
[b|$page: $deps $$(MAKEPAGES)|]
|
2020-07-25 21:03:55 -04:00
|
|
|
where
|
2021-08-23 10:30:11 -04:00
|
|
|
images = #all if nsfw then #images info else #sfwImages info
|
2020-07-25 21:03:55 -04:00
|
|
|
|
2020-08-04 18:52:39 -04:00
|
|
|
paths = map #path images
|
|
|
|
dls = mapMaybe #download images
|
|
|
|
extras = #extras info
|
2020-07-25 21:03:55 -04:00
|
|
|
|
|
|
|
dir = build </> prefix </> yamlDir
|
|
|
|
page = dir </> "index.html"
|
|
|
|
deps = unwords $ map (dir </>) $
|
2022-05-16 04:25:16 -04:00
|
|
|
thumbFile (thumbnail info) :
|
|
|
|
map pageFile paths ++
|
|
|
|
map bigFile paths ++
|
|
|
|
dls ++ extras
|
2020-07-16 10:07:28 -04:00
|
|
|
|
|
|
|
dependGallery :: GalleryInfo
|
2020-08-03 20:25:59 -04:00
|
|
|
-> FilePath -- ^ index file
|
2020-07-16 10:07:28 -04:00
|
|
|
-> [(FilePath, Info)] -- ^ relative to data dir
|
|
|
|
-> FilePath -- ^ build dir
|
|
|
|
-> FilePath -- ^ data dir
|
|
|
|
-> FilePath -- ^ tmp dir
|
|
|
|
-> Text
|
2020-08-03 20:25:59 -04:00
|
|
|
dependGallery ginfo index infos build data_ tmp =
|
|
|
|
toLazyText $ dependGallery' ginfo index infos build data_ tmp
|
2020-07-16 10:07:28 -04:00
|
|
|
|
2020-08-03 20:25:59 -04:00
|
|
|
dependGallery' :: GalleryInfo -> FilePath -> [(FilePath, Info)]
|
2020-07-16 10:07:28 -04:00
|
|
|
-> FilePath -> FilePath -> FilePath -> Builder
|
2020-08-03 20:25:59 -04:00
|
|
|
dependGallery' (GalleryInfo {prefix, filters})
|
|
|
|
indexFile infos' build data_ tmp = [b|@0
|
2020-08-30 13:13:40 -04:00
|
|
|
$index: $gallery
|
2020-07-25 21:03:55 -04:00
|
|
|
|
2020-08-30 13:13:40 -04:00
|
|
|
$gallery: $pages' $files' $rss $indexFile $$(MAKEPAGES)
|
|
|
|
$$(call gallery,$indexFile,$prefix)
|
2020-07-16 10:07:28 -04:00
|
|
|
|
2020-08-30 13:13:40 -04:00
|
|
|
$rss: $files' $indexFile $$(MAKEPAGES)
|
|
|
|
$$(call rss,$indexFile,$prefix,$data_)
|
2020-07-19 12:04:40 -04:00
|
|
|
|
2020-07-16 10:07:28 -04:00
|
|
|
$rules
|
|
|
|
|
|
|
|
$incs
|
|
|
|
|]
|
2020-07-18 05:40:56 -04:00
|
|
|
where
|
2020-07-25 21:03:55 -04:00
|
|
|
infos = filter (matchFilters filters . #second) infos'
|
|
|
|
|
|
|
|
files = map #first infos
|
|
|
|
files' = unwords $ map (data_ </>) files
|
|
|
|
|
|
|
|
page d = build </> prefix </> takeDirectory d </> "index.html"
|
|
|
|
pages = map page files
|
|
|
|
pages' = unwords pages
|
|
|
|
|
|
|
|
index = build </> "index.html"
|
|
|
|
gallery = build </> prefix </> "index.html"
|
|
|
|
rss = build </> prefix </> "rss.xml"
|
|
|
|
|
|
|
|
rules = makeRules prefix filters build data_ tmp
|
|
|
|
|
|
|
|
inc d = tmp </> prefix </> takeDirectory d <.> "mk"
|
|
|
|
incFiles = unwords $ map inc files
|
2020-08-30 13:13:40 -04:00
|
|
|
incs = if null infos then "" else [b|include $incFiles|]
|
2020-07-25 21:03:55 -04:00
|
|
|
|
2020-07-16 10:07:28 -04:00
|
|
|
makeRules :: FilePath -- ^ prefix
|
|
|
|
-> GalleryFilters
|
|
|
|
-> FilePath -- ^ build dir
|
|
|
|
-> FilePath -- ^ data dir
|
|
|
|
-> FilePath -- ^ tmp dir
|
|
|
|
-> Builder
|
|
|
|
makeRules prefix filters build data_ tmp = [b|@0
|
2020-08-30 13:13:40 -04:00
|
|
|
$buildPrefix/%/index.html: $data_/%/info.yaml $$(MAKEPAGES)
|
|
|
|
$$(call single,$data_,$prefix,$flags)
|
2020-07-16 10:07:28 -04:00
|
|
|
|
2020-08-30 13:13:40 -04:00
|
|
|
$tmpPrefix/%.mk: $data_/%/info.yaml $$(MAKEPAGES)
|
|
|
|
$$(call depend-single,$prefix,$build,$data_,$flags)
|
2020-07-24 09:20:10 -04:00
|
|
|
|
2020-08-30 13:13:40 -04:00
|
|
|
$buildPrefix/%: $tmp/%
|
2020-07-31 23:09:23 -04:00
|
|
|
$$(call copy,-l)
|
2020-07-16 10:07:28 -04:00
|
|
|
|
2020-08-30 13:13:40 -04:00
|
|
|
$buildPrefix/%: $data_/%
|
2020-07-24 09:20:10 -04:00
|
|
|
$$(call copy)
|
2020-07-16 10:07:28 -04:00
|
|
|
|]
|
|
|
|
where
|
|
|
|
buildPrefix = build </> prefix
|
|
|
|
tmpPrefix = tmp </> prefix
|
|
|
|
flags = filtersToFlags filters
|
2020-07-15 05:45:15 -04:00
|
|
|
|
2020-07-16 10:07:28 -04:00
|
|
|
filtersToFlags :: GalleryFilters -> Builder
|
|
|
|
filtersToFlags (GalleryFilters {nsfw}) =
|
2020-07-24 19:10:52 -04:00
|
|
|
case nsfw of NoNsfw -> ""; _ -> "-n"
|
2020-07-15 05:45:15 -04:00
|
|
|
|
|
|
|
thumbnail :: Info -> FilePath
|
2020-07-15 14:07:51 -04:00
|
|
|
thumbnail = fromMaybe (error "no thumbnail or sfw images") . #thumb
|