pass index file to gallery/rss
(instead of trying to escape the strings inside in make & on the command line)
This commit is contained in:
parent
161cb48d3a
commit
28fc9db3e0
6 changed files with 63 additions and 67 deletions
19
Makefile
19
Makefile
|
@ -139,13 +139,13 @@ $(MAKEPAGES) $(MPFLAGS) depend-single \
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# args
|
# args
|
||||||
# 1. title
|
# 1. index file
|
||||||
# 2. gallery prefix
|
# 2. gallery prefix
|
||||||
# 3. other flags
|
# 3. other flags
|
||||||
define gallery
|
define gallery
|
||||||
echo "[gallery] "$@
|
echo "[gallery] "$@
|
||||||
mkdir -p "$(dir $@)"
|
mkdir -p "$(dir $@)"
|
||||||
$(MAKEPAGES) $(MPFLAGS) gallery -t "$(1)" -p "$(2)" $(3) -o "$@" \
|
$(MAKEPAGES) $(MPFLAGS) gallery -i "$(1)" -p "$(2)" $(3) -o "$@" \
|
||||||
$(filter $(DATADIR)/%/$(INFONAME),$^)
|
$(filter $(DATADIR)/%/$(INFONAME),$^)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
@ -159,21 +159,18 @@ $(MAKEPAGES) $(MPFLAGS) single -D "$(1)" $< -o "$@" $(2)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# args:
|
# args:
|
||||||
# 1. title with commas replaced with $(comma)
|
# 1. index file
|
||||||
# 2. description with commas replaced
|
# 2. gallery prefix
|
||||||
# 3. gallery prefix
|
# 3. data dir
|
||||||
# 4. data dir
|
# 4. other flags
|
||||||
# 5. other flags
|
|
||||||
define rss
|
define rss
|
||||||
echo "[rss] "$@
|
echo "[rss] "$@
|
||||||
mkdir -p "$(dir $@)"
|
mkdir -p "$(dir $@)"
|
||||||
$(MAKEPAGES) $(MPFLAGS) rss -t "$(1)" -d "$(2)" \
|
$(MAKEPAGES) $(MPFLAGS) rss -i "$(1)" \
|
||||||
-R "$(ROOT)" -p "$(3)" -D "$(4)" -o "$@" $(5) \
|
-R "$(ROOT)" -p "$(2)" -D "$(3)" -o "$@" $(4) \
|
||||||
$(filter $(DATADIR)/%/$(INFONAME),$^)
|
$(filter $(DATADIR)/%/$(INFONAME),$^)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
comma := ,
|
|
||||||
|
|
||||||
|
|
||||||
# never delete intermediate files
|
# never delete intermediate files
|
||||||
.SECONDARY:
|
.SECONDARY:
|
||||||
|
|
|
@ -36,25 +36,26 @@ dependSingle' yamlDir info prefix build nsfw =
|
||||||
thumbFile (thumbnail info) : map pageFile paths ++ paths ++ dls
|
thumbFile (thumbnail info) : map pageFile paths ++ paths ++ dls
|
||||||
|
|
||||||
dependGallery :: GalleryInfo
|
dependGallery :: GalleryInfo
|
||||||
|
-> FilePath -- ^ index file
|
||||||
-> [(FilePath, Info)] -- ^ relative to data dir
|
-> [(FilePath, Info)] -- ^ relative to data dir
|
||||||
-> FilePath -- ^ build dir
|
-> FilePath -- ^ build dir
|
||||||
-> FilePath -- ^ data dir
|
-> FilePath -- ^ data dir
|
||||||
-> FilePath -- ^ tmp dir
|
-> FilePath -- ^ tmp dir
|
||||||
-> Text
|
-> Text
|
||||||
dependGallery ginfo infos build data_ tmp =
|
dependGallery ginfo index infos build data_ tmp =
|
||||||
toLazyText $ dependGallery' ginfo infos build data_ tmp
|
toLazyText $ dependGallery' ginfo index infos build data_ tmp
|
||||||
|
|
||||||
dependGallery' :: GalleryInfo -> [(FilePath, Info)]
|
dependGallery' :: GalleryInfo -> FilePath -> [(FilePath, Info)]
|
||||||
-> FilePath -> FilePath -> FilePath -> Builder
|
-> FilePath -> FilePath -> FilePath -> Builder
|
||||||
dependGallery' (GalleryInfo {title, desc, prefix, filters})
|
dependGallery' (GalleryInfo {prefix, filters})
|
||||||
infos' build data_ tmp = [b|@0
|
indexFile infos' build data_ tmp = [b|@0
|
||||||
$@index: $@gallery
|
$@index: $@gallery
|
||||||
|
|
||||||
$@gallery: $@pages' $@files' $@rss $$(MAKEPAGES)
|
$@gallery: $@pages' $@files' $@rss $@indexFile $$(MAKEPAGES)
|
||||||
$$(call gallery,$title',$@prefix,$flags)
|
$$(call gallery,$@indexFile,$@prefix)
|
||||||
|
|
||||||
$@rss: $@files' $$(MAKEPAGES)
|
$@rss: $@files' $@indexFile $$(MAKEPAGES)
|
||||||
$$(call rss,$title',$desc',$@prefix,$@data_)
|
$$(call rss,$@indexFile,$@prefix,$@data_)
|
||||||
|
|
||||||
$rules
|
$rules
|
||||||
|
|
||||||
|
@ -80,12 +81,6 @@ dependGallery' (GalleryInfo {title, desc, prefix, filters})
|
||||||
incFiles = unwords $ map inc files
|
incFiles = unwords $ map inc files
|
||||||
incs = if null infos then "" else [b|include $@incFiles|]
|
incs = if null infos then "" else [b|include $@incFiles|]
|
||||||
|
|
||||||
flags = filtersToFlags filters
|
|
||||||
title' = substComma title
|
|
||||||
desc' = substComma desc
|
|
||||||
|
|
||||||
substComma = textMap \case ',' -> "$(comma)"; c -> fromChar c
|
|
||||||
|
|
||||||
makeRules :: FilePath -- ^ prefix
|
makeRules :: FilePath -- ^ prefix
|
||||||
-> GalleryFilters
|
-> GalleryFilters
|
||||||
-> FilePath -- ^ build dir
|
-> FilePath -- ^ build dir
|
||||||
|
|
|
@ -18,15 +18,12 @@ 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 -- ^ title
|
make :: GalleryInfo -> [(FilePath, Info)] -> Lazy.Text
|
||||||
-> FilePath -- ^ gallery url prefix
|
make ginfo infos = toLazyText $ make' ginfo infos
|
||||||
-> Bool -- ^ nsfw is included?
|
|
||||||
-> [(FilePath, Info)]
|
|
||||||
-> Lazy.Text
|
|
||||||
make title prefix nsfw infos = toLazyText $ make' title prefix nsfw infos
|
|
||||||
|
|
||||||
make' :: Text -> FilePath -> Bool -> [(FilePath, Info)] -> Builder
|
|
||||||
make' title prefix nsfw infos = [b|@0
|
make' :: GalleryInfo -> [(FilePath, Info)] -> Builder
|
||||||
|
make' (GalleryInfo {title, prefix, filters}) infos = [b|@0
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang=en>
|
<html lang=en>
|
||||||
<meta charset=utf-8>
|
<meta charset=utf-8>
|
||||||
|
@ -77,6 +74,7 @@ make' title prefix nsfw infos = [b|@0
|
||||||
|]
|
|]
|
||||||
where
|
where
|
||||||
items = map (uncurry $ makeYearItems nsfw) infosByYear
|
items = map (uncurry $ makeYearItems nsfw) infosByYear
|
||||||
|
|
||||||
infosByYear =
|
infosByYear =
|
||||||
[(the year, infopath) |
|
[(the year, infopath) |
|
||||||
infopath@(_, info) <- infos,
|
infopath@(_, info) <- infos,
|
||||||
|
@ -84,7 +82,9 @@ make' title prefix nsfw infos = [b|@0
|
||||||
let year = #year info,
|
let year = #year info,
|
||||||
then group by Down year using groupBy']
|
then group by Down year using groupBy']
|
||||||
groupBy' f = groupBy ((==) `on` f)
|
groupBy' f = groupBy ((==) `on` f)
|
||||||
|
|
||||||
undir = joinPath (replicate (length (splitPath prefix)) "..")
|
undir = joinPath (replicate (length (splitPath prefix)) "..")
|
||||||
|
|
||||||
allTags = infos
|
allTags = infos
|
||||||
& concatMap (map (,1) . tagsFor nsfw . #second)
|
& concatMap (map (,1) . tagsFor nsfw . #second)
|
||||||
& HashMap.fromListWith (+) & HashMap.toList
|
& HashMap.fromListWith (+) & HashMap.toList
|
||||||
|
@ -92,6 +92,8 @@ make' title prefix nsfw infos = [b|@0
|
||||||
requireFilters = map (uncurry $ makeFilter "require") allTags
|
requireFilters = map (uncurry $ makeFilter "require") allTags
|
||||||
excludeFilters = map (uncurry $ makeFilter "exclude") allTags
|
excludeFilters = map (uncurry $ makeFilter "exclude") allTags
|
||||||
|
|
||||||
|
nsfw = #nsfw filters /= NoNsfw
|
||||||
|
|
||||||
makeFilter :: Text -> Text -> Int -> Builder
|
makeFilter :: Text -> Text -> Int -> Builder
|
||||||
makeFilter prefix tag count = [b|@8
|
makeFilter prefix tag count = [b|@8
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -5,16 +5,18 @@ import Control.Monad
|
||||||
import Data.ByteString.Lazy (ByteString)
|
import Data.ByteString.Lazy (ByteString)
|
||||||
import qualified Data.ByteString.Lazy as ByteString
|
import qualified Data.ByteString.Lazy as ByteString
|
||||||
import Data.List (intersperse)
|
import Data.List (intersperse)
|
||||||
|
import qualified Data.List as List
|
||||||
import Data.Text.Lazy (Text)
|
import Data.Text.Lazy (Text)
|
||||||
import Data.Text.Lazy.Builder (toLazyText)
|
import Data.Text.Lazy.Builder (toLazyText)
|
||||||
import qualified Data.Text.Lazy.IO as Text
|
import qualified Data.Text.Lazy.IO as Text
|
||||||
import qualified Data.YAML as YAML
|
import qualified Data.YAML as YAML
|
||||||
import System.FilePath (makeRelative, takeDirectory, takeFileName)
|
import System.FilePath (makeRelative, takeDirectory, takeFileName)
|
||||||
import System.FilePath.Find (find, always, fileName, (==?))
|
import System.FilePath.Find (always, fileName, (==?))
|
||||||
|
import qualified System.FilePath.Find as File
|
||||||
import System.IO (hPrint, stderr)
|
import System.IO (hPrint, stderr)
|
||||||
|
|
||||||
import Depend
|
import Depend
|
||||||
import Info (IndexInfo (..), Info)
|
import Info hiding (Text)
|
||||||
import Options
|
import Options
|
||||||
import qualified SinglePage
|
import qualified SinglePage
|
||||||
import qualified GalleryPage
|
import qualified GalleryPage
|
||||||
|
@ -52,10 +54,12 @@ main2 (SinglePage {file, dataDir, nsfw, output}) = do
|
||||||
let page = SinglePage.make nsfw dir info
|
let page = SinglePage.make nsfw dir info
|
||||||
writeOutput output page
|
writeOutput output page
|
||||||
|
|
||||||
main2 (GalleryPage {title, prefix, files, nsfw, output, dataDir}) = do
|
main2 (GalleryPage {files, prefix, index, output, dataDir}) = do
|
||||||
|
ginfo <- galleryFromIndex index prefix
|
||||||
|
printV $ "gallery_info" := ginfo
|
||||||
infos <- mapM (infoYAML dataDir) files
|
infos <- mapM (infoYAML dataDir) files
|
||||||
printV $ "infos" := infos
|
printV $ "infos" := infos
|
||||||
let page = GalleryPage.make title prefix nsfw infos
|
let page = GalleryPage.make ginfo infos
|
||||||
writeOutput output page
|
writeOutput output page
|
||||||
|
|
||||||
main2 (IndexPage {file, output}) = do
|
main2 (IndexPage {file, output}) = do
|
||||||
|
@ -64,11 +68,13 @@ main2 (IndexPage {file, output}) = do
|
||||||
let page = IndexPage.make info
|
let page = IndexPage.make info
|
||||||
writeOutput output page
|
writeOutput output page
|
||||||
|
|
||||||
main2 (RSS {files, title, desc, root, prefix, output, dataDir}) = do
|
main2 (RSS {files, root, index, prefix, output, dataDir}) = do
|
||||||
|
ginfo <- galleryFromIndex index prefix
|
||||||
|
printV $ "gallery_info" := ginfo
|
||||||
infos <- mapM (infoYAML dataDir) files
|
infos <- mapM (infoYAML dataDir) files
|
||||||
printV $ "infos" := infos
|
printV $ "infos" := infos
|
||||||
let output' = takeFileName <$> output
|
let output' = takeFileName <$> output
|
||||||
let rss = RSS.make root title desc prefix output' infos
|
let rss = RSS.make root ginfo output' infos
|
||||||
writeOutput output rss
|
writeOutput output rss
|
||||||
|
|
||||||
main2 (DependSingle {file, nsfw, output, prefix, buildDir, dataDir}) = do
|
main2 (DependSingle {file, nsfw, output, prefix, buildDir, dataDir}) = do
|
||||||
|
@ -83,15 +89,15 @@ main2 (DependGallery {file, output, buildDir, dataDir, tmpDir, infoName}) = do
|
||||||
IndexInfo {galleries} <- readYAML file
|
IndexInfo {galleries} <- readYAML file
|
||||||
printV $ "galleries" := galleries
|
printV $ "galleries" := galleries
|
||||||
infos <- mapM (infoYAML dataDir) =<< findInfos dataDir infoName
|
infos <- mapM (infoYAML dataDir) =<< findInfos dataDir infoName
|
||||||
printV $ "info files" := infos
|
printV $ "info_files" := infos
|
||||||
let dependGallery0 g = dependGallery' g infos buildDir dataDir tmpDir
|
let dependGallery0 g = dependGallery' g file infos buildDir dataDir tmpDir
|
||||||
let deps = toLazyText $ mconcat $ intersperse "\n\n\n" $
|
let deps = toLazyText $ mconcat $ intersperse "\n\n\n" $
|
||||||
map dependGallery0 galleries
|
map dependGallery0 galleries
|
||||||
writeOutput output deps
|
writeOutput output deps
|
||||||
|
|
||||||
main2 (ListTags {nsfw, listUntagged, dataDir, infoName}) = do
|
main2 (ListTags {nsfw, listUntagged, dataDir, infoName}) = do
|
||||||
infos <- mapM (infoYAML dataDir) =<< findInfos dataDir infoName
|
infos <- mapM (infoYAML dataDir) =<< findInfos dataDir infoName
|
||||||
printV $ "info files" := infos
|
printV $ "info_files" := infos
|
||||||
ListTags.run nsfw listUntagged infos
|
ListTags.run nsfw listUntagged infos
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,11 +110,17 @@ infoYAML dataDir f = do
|
||||||
pure (f', info)
|
pure (f', info)
|
||||||
|
|
||||||
findInfos :: FilePath -> FilePath -> IO [FilePath]
|
findInfos :: FilePath -> FilePath -> IO [FilePath]
|
||||||
findInfos dataDir infoName = find always (fileName ==? infoName) dataDir
|
findInfos dataDir infoName = File.find always (fileName ==? infoName) dataDir
|
||||||
|
|
||||||
readYAML :: YAML.FromYAML a => FilePath -> IO a
|
readYAML :: YAML.FromYAML a => FilePath -> IO a
|
||||||
readYAML file = ByteString.readFile file >>= decode1Must file
|
readYAML file = ByteString.readFile file >>= decode1Must file
|
||||||
|
|
||||||
|
galleryFromIndex :: FilePath -> FilePath -> IO GalleryInfo
|
||||||
|
galleryFromIndex file prefix = do
|
||||||
|
IndexInfo {galleries} <- readYAML file
|
||||||
|
maybe (fail $ "no gallery with prefix " ++ prefix) pure $
|
||||||
|
List.find (\g -> #prefix g == prefix) galleries
|
||||||
|
|
||||||
decode1Must :: YAML.FromYAML a => FilePath -> ByteString -> IO a
|
decode1Must :: YAML.FromYAML a => FilePath -> ByteString -> IO a
|
||||||
decode1Must file txt =
|
decode1Must file txt =
|
||||||
case YAML.decode1 txt of
|
case YAML.decode1 txt of
|
||||||
|
|
|
@ -20,8 +20,7 @@ data ModeOptions =
|
||||||
| GalleryPage {
|
| GalleryPage {
|
||||||
files :: [FilePath],
|
files :: [FilePath],
|
||||||
prefix :: FilePath,
|
prefix :: FilePath,
|
||||||
nsfw :: Bool,
|
index :: FilePath,
|
||||||
title :: Text,
|
|
||||||
output :: Maybe FilePath,
|
output :: Maybe FilePath,
|
||||||
dataDir :: FilePath
|
dataDir :: FilePath
|
||||||
}
|
}
|
||||||
|
@ -31,9 +30,8 @@ data ModeOptions =
|
||||||
}
|
}
|
||||||
| RSS {
|
| RSS {
|
||||||
files :: [FilePath],
|
files :: [FilePath],
|
||||||
title :: Text,
|
|
||||||
desc :: Text,
|
|
||||||
root :: Text,
|
root :: Text,
|
||||||
|
index :: FilePath,
|
||||||
prefix :: FilePath,
|
prefix :: FilePath,
|
||||||
output :: Maybe FilePath,
|
output :: Maybe FilePath,
|
||||||
dataDir :: FilePath
|
dataDir :: FilePath
|
||||||
|
@ -92,27 +90,21 @@ optionsParser = globalOpts `info` mainInfo where
|
||||||
|
|
||||||
gallery = command "gallery" $ galleryOpts `info` galleryInfo
|
gallery = command "gallery" $ galleryOpts `info` galleryInfo
|
||||||
galleryOpts =
|
galleryOpts =
|
||||||
GalleryPage <$> files <*> prefix <*> nsfwG <*> title <*> output <*> dataDir
|
GalleryPage <$> files <*> prefix <*> indexFile <*> output <*> dataDir
|
||||||
prefix = strOption $
|
prefix = strOption $
|
||||||
short 'p' <> long "prefix" <> metavar "DIR" <>
|
short 'p' <> long "prefix" <> metavar "DIR" <>
|
||||||
value "" <>
|
value "" <>
|
||||||
help "output directory prefix"
|
help "output directory prefix"
|
||||||
|
indexFile = strOption $
|
||||||
|
short 'i' <> long "index" <> metavar "FILE" <>
|
||||||
|
help "path to index file"
|
||||||
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 $
|
|
||||||
short 't' <> long "title" <> metavar "TITLE" <>
|
|
||||||
help "page title"
|
|
||||||
galleryInfo = progDesc "generate a gallery page"
|
galleryInfo = progDesc "generate a gallery page"
|
||||||
|
|
||||||
rss = command "rss" $ rssOpts `info` rssInfo
|
rss = command "rss" $ rssOpts `info` rssInfo
|
||||||
rssOpts = RSS <$> files <*> title <*> desc <*> root
|
rssOpts = RSS <$> files <*> root <*> indexFile
|
||||||
<*> prefix <*> output <*> dataDir
|
<*> prefix <*> output <*> dataDir
|
||||||
desc = strOption $
|
|
||||||
short 'd' <> long "desc" <> metavar "DESC" <>
|
|
||||||
help "gallery description"
|
|
||||||
root = strOption $
|
root = strOption $
|
||||||
short 'R' <> long "root" <> metavar "URL" <>
|
short 'R' <> long "root" <> metavar "URL" <>
|
||||||
help "website root (no trailing slash)"
|
help "website root (no trailing slash)"
|
||||||
|
|
|
@ -14,18 +14,16 @@ import System.FilePath (takeDirectory)
|
||||||
|
|
||||||
|
|
||||||
make :: Strict.Text -- ^ website root e.g. @https://gallery.niss.website@
|
make :: Strict.Text -- ^ website root e.g. @https://gallery.niss.website@
|
||||||
-> Strict.Text -- ^ title
|
-> GalleryInfo
|
||||||
-> Strict.Text -- ^ description
|
|
||||||
-> FilePath -- ^ gallery prefix e.g. @main@
|
|
||||||
-> Maybe FilePath -- ^ output filename for self link
|
-> Maybe FilePath -- ^ output filename for self link
|
||||||
-> [(FilePath, Info)]
|
-> [(FilePath, Info)]
|
||||||
-> Lazy.Text
|
-> Lazy.Text
|
||||||
make root title desc prefix output infos =
|
make root ginfo output infos =
|
||||||
toLazyText $ make' root title desc prefix output infos
|
toLazyText $ make' root ginfo output infos
|
||||||
|
|
||||||
make' :: Strict.Text -> Strict.Text -> Strict.Text
|
make' :: Strict.Text -> GalleryInfo
|
||||||
-> FilePath -> Maybe FilePath -> [(FilePath, Info)] -> Builder
|
-> Maybe FilePath -> [(FilePath, Info)] -> Builder
|
||||||
make' root title desc prefix output infos = [b|@0
|
make' root (GalleryInfo {title, desc, prefix}) output infos = [b|@0
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||||
<channel>
|
<channel>
|
||||||
|
|
Loading…
Reference in a new issue