add nsfw tags & put tags on singlepage

This commit is contained in:
Rhiannon Morris 2020-07-12 05:42:31 +02:00
parent bf6308de32
commit f61e9916fb
2 changed files with 16 additions and 1 deletions

View File

@ -20,6 +20,7 @@ data Info =
date :: !Day,
title :: !(Maybe Text),
tags :: ![Text],
nsfwTags :: ![Text],
description :: !(Maybe Text),
images :: ![Image],
thumb :: !Text,
@ -49,6 +50,7 @@ instance FromYAML Info where
Info <$> m .: "date"
<*> m .:? "title"
<*> m .:? "tags" .!= []
<*> m .:? "nsfwTags" .!= []
<*> m .:? "description"
<*> m .: "images"
<*> m .: "thumb"

View File

@ -25,7 +25,8 @@ make :: Bool -> Info -> Lazy.Text
make includeNsfw = toLazyText . make' includeNsfw
make' :: Bool -> Info -> Builder
make' includeNsfw (Info {date, title, tags, description, images, links}) =
make' includeNsfw (Info {date, title, tags, nsfwTags,
description, images, links}) =
"<!DOCTYPE html>\n" <>
"<html lang=en>\n" <>
"<meta charset=utf-8>\n" <>
@ -43,6 +44,7 @@ make' includeNsfw (Info {date, title, tags, description, images, links}) =
" <h2>description</h2>\n" <>
indent 4 d <>
" </div>\n") <>
makeTags includeNsfw tags nsfwTags <>
extLinks includeNsfw links <>
"</main>\n\n" <>
"<nav class=back>\n" <>
@ -113,6 +115,17 @@ indent n txt = spaces <> go (Strict.unpack txt) where
go (c:cs) = singleton c <> go cs
spaces = fromString $ replicate n ' '
makeTags :: Bool -> [Strict.Text] -> [Strict.Text] -> Builder
makeTags includeNsfw sfwTags nsfwTags =
if null tags then mempty else
" <div class=tags>\n" <>
" <h2>tags</h2>\n" <>
" <ul>\n" <> foldMap makeTag tags <> " </ul>\n" <>
" </div>\n\n"
where
tags = List.nub $ if includeNsfw then sfwTags else sfwTags <> nsfwTags
makeTag t = " <li>" <> fromText t <> "\n"
extLinks :: Bool -> [Link] -> Builder
extLinks includeNsfw links =
let links' =