From a29fff1094930c749897614c11cf433bd671f0f4 Mon Sep 17 00:00:00 2001 From: Rhiannon Morris Date: Sat, 18 Jul 2020 11:45:32 +0200 Subject: [PATCH] add footer to index page --- make-pages/IndexPage.hs | 14 +++++++++----- make-pages/Info.hs | 14 ++++++++++++++ make-pages/Main.hs | 14 +++++++------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/make-pages/IndexPage.hs b/make-pages/IndexPage.hs index d389822..d2813a7 100644 --- a/make-pages/IndexPage.hs +++ b/make-pages/IndexPage.hs @@ -6,11 +6,11 @@ import Data.Text.Lazy.Builder (Builder, toLazyText) import BuilderQQ import Info -make :: [GalleryInfo] -> Lazy.Text -make ginfos = toLazyText $ make' ginfos +make :: IndexInfo -> Lazy.Text +make iinfo = toLazyText $ make' iinfo -make' :: [GalleryInfo] -> Builder -make' ginfos = [b|@0 +make' :: IndexInfo -> Builder +make' (IndexInfo {galleries, footer}) = [b|@0 @@ -27,9 +27,13 @@ make' ginfos = [b|@0 $4.items + + |] where - items = map makeItem ginfos + items = map makeItem galleries makeItem :: GalleryInfo -> Builder makeItem (GalleryInfo {title, prefix, filters}) = [b|@4 diff --git a/make-pages/Info.hs b/make-pages/Info.hs index db4f3d9..25a5594 100644 --- a/make-pages/Info.hs +++ b/make-pages/Info.hs @@ -3,6 +3,7 @@ module Info (Info (..), Artist (..), Image (..), Link (..), GalleryInfo (..), GalleryFilters (..), Whose (..), + IndexInfo (..), readWhose, matchWhose, matchNsfw, matchFilters, -- ** Reexports Day (..), Text) @@ -195,6 +196,19 @@ instance FromYAML GalleryFilters where instance FromYAML Whose where parseYAML = YAML.withStr "whose" readWhose +data IndexInfo = + IndexInfo { + galleries :: ![GalleryInfo], + footer :: !Text + } + deriving Show + +instance FromYAML IndexInfo where + parseYAML = YAML.withMap "index info" \m -> + IndexInfo <$> m .:? "galleries" .!= [] + <*> m .:? "footer" .!= "" + + data Pair a b = Pair !a !b instance (FromYAML a, FromYAML b) => FromYAML (Pair a b) where diff --git a/make-pages/Main.hs b/make-pages/Main.hs index b26cf3a..940be6c 100644 --- a/make-pages/Main.hs +++ b/make-pages/Main.hs @@ -14,7 +14,7 @@ import System.FilePath.Find (find, always, fileName, (==?)) import System.IO (hPrint, stderr) import Depend -import Info (Info) +import Info (IndexInfo (..), Info) import Options import qualified SinglePage import qualified GalleryPage @@ -56,9 +56,9 @@ main2 (GalleryPage {title, files, nsfw, output, dataDir}) = do writeOutput output page main2 (IndexPage {file, output}) = do - ginfos <- readYAML file - printV $ "galleries" := ginfos - let page = IndexPage.make ginfos + info <- readYAML file + printV $ "info" := info + let page = IndexPage.make info writeOutput output page main2 (DependSingle {file, nsfw, output, prefix, buildDir, dataDir}) = do @@ -70,14 +70,14 @@ main2 (DependSingle {file, nsfw, output, prefix, buildDir, dataDir}) = do writeOutput output deps main2 (DependGallery {file, output, buildDir, dataDir, tmpDir, infoName}) = do - ginfos <- readYAML @[_] file - printV $ "galleries" := ginfos + IndexInfo {galleries} <- readYAML file + printV $ "galleries" := galleries infos <- mapM (infoYAML dataDir) =<< find always (fileName ==? infoName) dataDir printV $ "info files" := infos let dependGallery0 g = dependGallery' g infos buildDir dataDir tmpDir let deps = toLazyText $ mconcat $ intersperse "\n\n\n" $ - map dependGallery0 ginfos + map dependGallery0 galleries writeOutput output deps infoYAML :: FilePath -- ^ data dir