add nsfw class to relevant gallery items
but only on galleries showing nsfw at all
This commit is contained in:
parent
0ffebd2a00
commit
4a08a6bb9a
4 changed files with 23 additions and 11 deletions
|
@ -63,13 +63,15 @@ dependGallery' (GalleryInfo {title, prefix, filters}) infos' build data_ tmp =
|
||||||
$@path: $@pages' $@files'
|
$@path: $@pages' $@files'
|
||||||
echo "[gallery] "$$@
|
echo "[gallery] "$$@
|
||||||
mkdir -p $$(dir $$@)
|
mkdir -p $$(dir $$@)
|
||||||
$$(MAKEPAGES) $$(MPFLAGS) gallery -t "$*title" -o "$$@" \
|
$$(MAKEPAGES) $$(MPFLAGS) gallery -t "$*title" $flags -o "$$@" \
|
||||||
$$(filter $$(DATADIR)/%/$$(INFONAME),$$^)
|
$$(filter $$(DATADIR)/%/$$(INFONAME),$$^)
|
||||||
|
|
||||||
$rules
|
$rules
|
||||||
|
|
||||||
$incs
|
$incs
|
||||||
|]
|
|]
|
||||||
|
where
|
||||||
|
flags = filtersToFlags filters
|
||||||
|
|
||||||
makeRules :: FilePath -- ^ prefix
|
makeRules :: FilePath -- ^ prefix
|
||||||
-> GalleryFilters
|
-> GalleryFilters
|
||||||
|
|
|
@ -16,11 +16,14 @@ newtype NoThumb = NoThumb FilePath
|
||||||
deriving stock Eq deriving anyclass Exception
|
deriving stock Eq deriving anyclass Exception
|
||||||
instance Show NoThumb where show (NoThumb dir) = "no thumbnail for " ++ dir
|
instance Show NoThumb where show (NoThumb dir) = "no thumbnail for " ++ dir
|
||||||
|
|
||||||
make :: Text -> [(FilePath, Info)] -> Lazy.Text
|
make :: Text -- ^ title
|
||||||
make title infos = toLazyText $ make' title infos
|
-> Bool -- ^ nsfw is included?
|
||||||
|
-> [(FilePath, Info)]
|
||||||
|
-> Lazy.Text
|
||||||
|
make title nsfw infos = toLazyText $ make' title nsfw infos
|
||||||
|
|
||||||
make' :: Text -> [(FilePath, Info)] -> Builder
|
make' :: Text -> Bool -> [(FilePath, Info)] -> Builder
|
||||||
make' title infos' = [b|@0
|
make' title nsfw infos = [b|@0
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang=en>
|
<html lang=en>
|
||||||
<meta charset=utf-8>
|
<meta charset=utf-8>
|
||||||
|
@ -43,9 +46,9 @@ make' title infos' = [b|@0
|
||||||
infos = sortBy (cmpInfo `on` snd) infos'
|
infos = sortBy (cmpInfo `on` snd) infos'
|
||||||
cmpInfo = flip (comparing #date) <> comparing #title
|
cmpInfo = flip (comparing #date) <> comparing #title
|
||||||
|
|
||||||
makeItem :: FilePath -> Info -> Builder
|
makeItem :: Bool -> FilePath -> Info -> Builder
|
||||||
makeItem file info = [b|@4
|
makeItem nsfw file info = [b|@4
|
||||||
<li class=item>
|
<li $cls>
|
||||||
<figure>
|
<figure>
|
||||||
<a href="$@dir">
|
<a href="$@dir">
|
||||||
<img src="$@thumb">
|
<img src="$@thumb">
|
||||||
|
@ -62,3 +65,5 @@ makeItem file info = [b|@4
|
||||||
$*t
|
$*t
|
||||||
</figcaption>
|
</figcaption>
|
||||||
|]
|
|]
|
||||||
|
cls | nsfw && #anyNsfw info = [b|class="item nsfw"|]
|
||||||
|
| otherwise = [b|class=item|]
|
||||||
|
|
|
@ -49,10 +49,10 @@ main2 (SinglePage {file, nsfw, output}) = do
|
||||||
let page = SinglePage.make nsfw info
|
let page = SinglePage.make nsfw info
|
||||||
writeOutput output page
|
writeOutput output page
|
||||||
|
|
||||||
main2 (GalleryPage {title, files, output, dataDir}) = do
|
main2 (GalleryPage {title, files, nsfw, output, dataDir}) = do
|
||||||
infos <- mapM (infoYAML dataDir) files
|
infos <- mapM (infoYAML dataDir) files
|
||||||
printV $ "infos" := infos
|
printV $ "infos" := infos
|
||||||
let page = GalleryPage.make title infos
|
let page = GalleryPage.make title nsfw infos
|
||||||
writeOutput output page
|
writeOutput output page
|
||||||
|
|
||||||
main2 (IndexPage {file, output}) = do
|
main2 (IndexPage {file, output}) = do
|
||||||
|
|
|
@ -18,6 +18,7 @@ data ModeOptions =
|
||||||
}
|
}
|
||||||
| GalleryPage {
|
| GalleryPage {
|
||||||
files :: [FilePath],
|
files :: [FilePath],
|
||||||
|
nsfw :: Bool,
|
||||||
title :: Text,
|
title :: Text,
|
||||||
output :: Maybe FilePath,
|
output :: Maybe FilePath,
|
||||||
dataDir :: FilePath
|
dataDir :: FilePath
|
||||||
|
@ -72,9 +73,13 @@ optionsParser = globalOpts `info` mainInfo where
|
||||||
indexInfo = progDesc "generate an index page for all galleries"
|
indexInfo = progDesc "generate an index page for all galleries"
|
||||||
|
|
||||||
gallery = command "gallery" $ galleryOpts `info` galleryInfo
|
gallery = command "gallery" $ galleryOpts `info` galleryInfo
|
||||||
galleryOpts = GalleryPage <$> files <*> title <*> output <*> dataDir
|
galleryOpts =
|
||||||
|
GalleryPage <$> files <*> nsfwG <*> title <*> output <*> dataDir
|
||||||
files = many $ strArgument $
|
files = many $ strArgument $
|
||||||
metavar "FILE..." <> help "yaml files to read"
|
metavar "FILE..." <> help "yaml files to read"
|
||||||
|
nsfwG = switch $
|
||||||
|
short 'n' <> long "nsfw" <>
|
||||||
|
help "nsfw versions are included"
|
||||||
title = strOption $
|
title = strOption $
|
||||||
short 't' <> long "title" <> metavar "TITLE" <>
|
short 't' <> long "title" <> metavar "TITLE" <>
|
||||||
help "page title"
|
help "page title"
|
||||||
|
|
Loading…
Reference in a new issue