refactor Depend

This commit is contained in:
Rhiannon Morris 2020-07-26 03:03:55 +02:00
parent 1b63a30f49
commit 720cfcc341

View file

@ -23,15 +23,17 @@ dependSingle yamlDir info prefix build nsfw =
dependSingle' :: FilePath -> Info -> FilePath -> FilePath -> Bool -> Builder
dependSingle' yamlDir info prefix build nsfw =
let dir = build </> prefix </> yamlDir
images = if nsfw then #images info else #sfwImages info
paths = map #path images
dls = mapMaybe #download images
index = dir </> "index.html"
deps = thumbFile (thumbnail info) : map pageFile paths ++ paths ++ dls
deps' = unwords $ map (dir </>) deps
in
[b|$@index: $@deps' $$(MAKEPAGES)|]
[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
dependGallery :: GalleryInfo
-> [(FilePath, Info)] -- ^ relative to data dir
@ -45,24 +47,10 @@ dependGallery ginfo infos build data_ tmp =
dependGallery' :: GalleryInfo -> [(FilePath, Info)]
-> FilePath -> FilePath -> FilePath -> Builder
dependGallery' (GalleryInfo {title, desc, prefix, filters})
infos' build data_ tmp =
let 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
path = build </> prefix </> "index.html"
rss = build </> prefix </> "rss.xml"
rules = makeRules prefix filters build data_ tmp
inc d = tmp </> prefix </> takeDirectory d <.> "mk"
incs = if null infos then "" else
"include " <> fromString (unwords $ map inc files)
index = build </> "index.html"
in [b|@0
$@index: $@path
infos' build data_ tmp = [b|@0
$@index: $@gallery
$@path: $@pages' $@files' $@rss $$(MAKEPAGES)
$@gallery: $@pages' $@files' $@rss $$(MAKEPAGES)
$$(call gallery,$title',$@prefix,$flags)
$@rss: $@files' $$(MAKEPAGES)
@ -73,9 +61,29 @@ dependGallery' (GalleryInfo {title, desc, prefix, filters})
$incs
|]
where
flags = filtersToFlags filters
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|]
flags = filtersToFlags filters
title' = substComma title
desc' = substComma desc
desc' = substComma desc
substComma = textMap \case ',' -> "$(comma)"; c -> fromChar c
makeRules :: FilePath -- ^ prefix