add footer to index page

This commit is contained in:
Rhiannon Morris 2020-07-18 11:45:32 +02:00
parent 185f8d5ca4
commit a29fff1094
3 changed files with 30 additions and 12 deletions

View file

@ -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
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
@ -27,9 +27,13 @@ make' ginfos = [b|@0
$4.items
</ul>
</main>
<footer>
$4*footer
</footer>
|]
where
items = map makeItem ginfos
items = map makeItem galleries
makeItem :: GalleryInfo -> Builder
makeItem (GalleryInfo {title, prefix, filters}) = [b|@4

View file

@ -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

View file

@ -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