add nsfw class to relevant gallery items

but only on galleries showing nsfw at all
This commit is contained in:
Rhiannon Morris 2020-07-18 11:40:56 +02:00
parent 0ffebd2a00
commit 4a08a6bb9a
4 changed files with 23 additions and 11 deletions

View file

@ -63,13 +63,15 @@ dependGallery' (GalleryInfo {title, prefix, filters}) infos' build data_ tmp =
$@path: $@pages' $@files'
echo "[gallery] "$$@
mkdir -p $$(dir $$@)
$$(MAKEPAGES) $$(MPFLAGS) gallery -t "$*title" -o "$$@" \
$$(MAKEPAGES) $$(MPFLAGS) gallery -t "$*title" $flags -o "$$@" \
$$(filter $$(DATADIR)/%/$$(INFONAME),$$^)
$rules
$incs
|]
where
flags = filtersToFlags filters
makeRules :: FilePath -- ^ prefix
-> GalleryFilters

View file

@ -16,11 +16,14 @@ newtype NoThumb = NoThumb FilePath
deriving stock Eq deriving anyclass Exception
instance Show NoThumb where show (NoThumb dir) = "no thumbnail for " ++ dir
make :: Text -> [(FilePath, Info)] -> Lazy.Text
make title infos = toLazyText $ make' title infos
make :: Text -- ^ title
-> Bool -- ^ nsfw is included?
-> [(FilePath, Info)]
-> Lazy.Text
make title nsfw infos = toLazyText $ make' title nsfw infos
make' :: Text -> [(FilePath, Info)] -> Builder
make' title infos' = [b|@0
make' :: Text -> Bool -> [(FilePath, Info)] -> Builder
make' title nsfw infos = [b|@0
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
@ -43,9 +46,9 @@ make' title infos' = [b|@0
infos = sortBy (cmpInfo `on` snd) infos'
cmpInfo = flip (comparing #date) <> comparing #title
makeItem :: FilePath -> Info -> Builder
makeItem file info = [b|@4
<li class=item>
makeItem :: Bool -> FilePath -> Info -> Builder
makeItem nsfw file info = [b|@4
<li $cls>
<figure>
<a href="$@dir">
<img src="$@thumb">
@ -62,3 +65,5 @@ makeItem file info = [b|@4
$*t
</figcaption>
|]
cls | nsfw && #anyNsfw info = [b|class="item nsfw"|]
| otherwise = [b|class=item|]

View file

@ -49,10 +49,10 @@ main2 (SinglePage {file, nsfw, output}) = do
let page = SinglePage.make nsfw info
writeOutput output page
main2 (GalleryPage {title, files, output, dataDir}) = do
main2 (GalleryPage {title, files, nsfw, output, dataDir}) = do
infos <- mapM (infoYAML dataDir) files
printV $ "infos" := infos
let page = GalleryPage.make title infos
let page = GalleryPage.make title nsfw infos
writeOutput output page
main2 (IndexPage {file, output}) = do

View file

@ -18,6 +18,7 @@ data ModeOptions =
}
| GalleryPage {
files :: [FilePath],
nsfw :: Bool,
title :: Text,
output :: Maybe FilePath,
dataDir :: FilePath
@ -72,9 +73,13 @@ optionsParser = globalOpts `info` mainInfo where
indexInfo = progDesc "generate an index page for all galleries"
gallery = command "gallery" $ galleryOpts `info` galleryInfo
galleryOpts = GalleryPage <$> files <*> title <*> output <*> dataDir
galleryOpts =
GalleryPage <$> files <*> nsfwG <*> title <*> output <*> dataDir
files = many $ strArgument $
metavar "FILE..." <> help "yaml files to read"
nsfwG = switch $
short 'n' <> long "nsfw" <>
help "nsfw versions are included"
title = strOption $
short 't' <> long "title" <> metavar "TITLE" <>
help "page title"