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