a lot of stuff sorry
This commit is contained in:
parent
adfc8b9a82
commit
375c6e833a
9 changed files with 297 additions and 151 deletions
|
@ -1,11 +1,15 @@
|
|||
module Depend where
|
||||
module Depend
|
||||
(dependSingle, dependSingle',
|
||||
dependGallery, dependGallery',
|
||||
thumbFile, pageFile)
|
||||
where
|
||||
|
||||
import BuilderQQ
|
||||
import Info hiding (Text)
|
||||
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Data.Text.Lazy (Text)
|
||||
import Data.Text.Lazy.Builder (toLazyText)
|
||||
import Data.Text.Lazy.Builder (Builder, toLazyText, fromString)
|
||||
import System.FilePath
|
||||
|
||||
|
||||
|
@ -15,16 +19,100 @@ dependSingle :: FilePath -- ^ yaml file name (relative to data dir!)
|
|||
-> FilePath -- ^ build dir
|
||||
-> Bool -- ^ include nsfw?
|
||||
-> Text
|
||||
dependSingle yaml info prefix build nsfw =
|
||||
let dir = build </> prefix </> takeDirectory yaml
|
||||
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 =
|
||||
let dir = build </> prefix </> yamlDir
|
||||
images = if nsfw then #images info else #sfwImages info
|
||||
paths = map #path images
|
||||
index = dir </> "index.html"
|
||||
deps = thumbFile (thumbnail info) : map pageFile paths ++ paths
|
||||
deps' = unwords $ map (dir </>) deps
|
||||
in
|
||||
toLazyText [b|$@index: $@deps'|]
|
||||
[b|$@index: $@deps'|]
|
||||
|
||||
dependGallery :: GalleryInfo
|
||||
-> [(FilePath, Info)] -- ^ relative to data dir
|
||||
-> FilePath -- ^ build dir
|
||||
-> FilePath -- ^ data dir
|
||||
-> FilePath -- ^ tmp dir
|
||||
-> Text
|
||||
dependGallery ginfo infos build data_ tmp =
|
||||
toLazyText $ dependGallery' ginfo infos build data_ tmp
|
||||
|
||||
dependGallery' :: GalleryInfo -> [(FilePath, Info)]
|
||||
-> FilePath -> FilePath -> FilePath -> Builder
|
||||
dependGallery' (GalleryInfo {title, prefix, filters}) infos' build data_ tmp =
|
||||
let infos = filter (matchFilters filters . snd) infos'
|
||||
files = map fst infos
|
||||
files' = unwords $ map (data_ </>) files
|
||||
page d = build </> prefix </> takeDirectory d </> "index.html"
|
||||
pages = map (page . fst) infos
|
||||
pages' = unwords pages
|
||||
path = build </> prefix </> "index.html"
|
||||
rules = makeRules prefix filters build data_ tmp
|
||||
inc d = tmp </> prefix </> takeDirectory d <.> "d"
|
||||
incs = if null infos then "" else
|
||||
"include " <> fromString (unwords $ map inc files)
|
||||
index = build </> "index.html"
|
||||
in [b|@0
|
||||
$@index: $@path
|
||||
|
||||
$@path: $@pages'
|
||||
$@path: $@files'
|
||||
echo "[gallery] "$$@
|
||||
mkdir -p $$(dir $$@)
|
||||
$$(MAKEPAGES) gallery -t "$*title" -o "$$@" $$<
|
||||
|
||||
$rules
|
||||
|
||||
$incs
|
||||
|]
|
||||
|
||||
makeRules :: FilePath -- ^ prefix
|
||||
-> GalleryFilters
|
||||
-> FilePath -- ^ build dir
|
||||
-> FilePath -- ^ data dir
|
||||
-> FilePath -- ^ tmp dir
|
||||
-> Builder
|
||||
makeRules prefix filters build data_ tmp = [b|@0
|
||||
$@buildPrefix/%/index.html: $@data_/%/info.yaml
|
||||
echo "[single] "$$@
|
||||
mkdir -p $$(dir $$@)
|
||||
$$(MAKEPAGES) single "$$<" -o "$$@" $flags
|
||||
|
||||
$@tmpPrefix/%.d: $@data_/%/info.yaml
|
||||
echo "[deps] "$$@
|
||||
mkdir -p $$(dir $$@)
|
||||
$$(MAKEPAGES) depend-single $flags \
|
||||
-o "$$@" -p "$@prefix" -B "$@build" -D "$@data_" $$<
|
||||
|
||||
$@buildPrefix/%: $@data_/%
|
||||
echo "[copy] "$$@
|
||||
mkdir -p $$(dir $$@)
|
||||
cp "$$<" "$$@"
|
||||
|
||||
$@buildPrefix/%_small.png: $@data_/%.png
|
||||
echo "[resize] "$$@
|
||||
mkdir -p $$(dir $$@)
|
||||
convert -resize '$$(SMALL)x$$(SMALL)^' \
|
||||
-gravity center -crop 1:1+0 "$$<" "$$@"
|
||||
|
||||
$@buildPrefix/%_med.png: $@data_/%.png
|
||||
echo "[resize] "$$@
|
||||
mkdir -p $$(dir $$@)
|
||||
convert -resize '$$(MED)x$$(MED)>' "$$<" "$$@"
|
||||
|]
|
||||
where
|
||||
buildPrefix = build </> prefix
|
||||
tmpPrefix = tmp </> prefix
|
||||
flags = filtersToFlags filters
|
||||
|
||||
filtersToFlags :: GalleryFilters -> Builder
|
||||
filtersToFlags (GalleryFilters {nsfw}) =
|
||||
case nsfw of Just False -> ""; _ -> "-n"
|
||||
|
||||
thumbnail :: Info -> FilePath
|
||||
thumbnail = fromMaybe (error "no thumbnail or sfw images") . #thumb
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue