2020-07-16 10:07:28 -04:00
|
|
|
module Depend
|
|
|
|
(dependSingle, dependSingle',
|
|
|
|
dependGallery, dependGallery',
|
|
|
|
thumbFile, pageFile)
|
|
|
|
where
|
2020-07-15 05:45:15 -04:00
|
|
|
|
2020-07-15 15:31:46 -04:00
|
|
|
import BuilderQQ
|
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-07-25 21:03:55 -04:00
|
|
|
[b|$@page: $@deps $$(MAKEPAGES)|]
|
|
|
|
where
|
|
|
|
images = if nsfw then #images info else #sfwImages info
|
|
|
|
|
|
|
|
paths = map #path images
|
|
|
|
dls = mapMaybe #download images
|
|
|
|
|
|
|
|
dir = build </> prefix </> yamlDir
|
|
|
|
page = dir </> "index.html"
|
|
|
|
deps = unwords $ map (dir </>) $
|
|
|
|
thumbFile (thumbnail info) : map pageFile paths ++ paths ++ dls
|
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-07-25 21:03:55 -04:00
|
|
|
$@index: $@gallery
|
|
|
|
|
2020-08-03 20:25:59 -04:00
|
|
|
$@gallery: $@pages' $@files' $@rss $@indexFile $$(MAKEPAGES)
|
|
|
|
$$(call gallery,$@indexFile,$@prefix)
|
2020-07-16 10:07:28 -04:00
|
|
|
|
2020-08-03 20:25:59 -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
|
|
|
|
incs = if null infos then "" else [b|include $@incFiles|]
|
|
|
|
|
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-07-19 11:56:46 -04:00
|
|
|
$@buildPrefix/%/index.html: $@data_/%/info.yaml $$(MAKEPAGES)
|
2020-07-24 09:20:10 -04:00
|
|
|
$$(call single,$@data_,$flags)
|
2020-07-16 10:07:28 -04:00
|
|
|
|
2020-07-19 11:56:46 -04:00
|
|
|
$@tmpPrefix/%.mk: $@data_/%/info.yaml $$(MAKEPAGES)
|
2020-07-24 09:20:10 -04:00
|
|
|
$$(call depend-single,$@prefix,$@build,$@data_,$flags)
|
|
|
|
|
|
|
|
$@buildPrefix/%: $@tmp/%
|
2020-07-31 23:09:23 -04:00
|
|
|
$$(call copy,-l)
|
2020-07-16 10:07:28 -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
|
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
|
2020-07-18 05:43:10 -04:00
|
|
|
pageFile f
|
|
|
|
| takeExtension f == ".gif" = f
|
|
|
|
| otherwise = addSuffix "_med" f
|