add extra link support to index page

This commit is contained in:
Rhiannon Morris 2020-07-19 12:22:02 +02:00
parent 980d790874
commit 5a1181ec76
3 changed files with 63 additions and 30 deletions

View file

@ -10,7 +10,7 @@ make :: IndexInfo -> Lazy.Text
make info = toLazyText $ make' info make info = toLazyText $ make' info
make' :: IndexInfo -> Builder make' :: IndexInfo -> Builder
make' (IndexInfo {title, galleries, footer}) = [b|@0 make' (IndexInfo {title, galleries, links, footer}) = [b|@0
<!DOCTYPE html> <!DOCTYPE html>
<html lang=en> <html lang=en>
<meta charset=utf-8> <meta charset=utf-8>
@ -23,24 +23,44 @@ make' (IndexInfo {title, galleries, footer}) = [b|@0
</header> </header>
<main> <main>
$galleryList
$linkList
</main>
$footer'
|]
where
galleryList = if null galleries then "" else [b|@2
<ul class=gallery-list> <ul class=gallery-list>
$4.items $4.items
</ul> </ul>
</main> |]
where items = map makeItem galleries
linkList = if null links then "" else [b|@2
<ul class=link-list>
$4.items
</ul>
|]
where items = map makeLink links
footer' = case footer of
Nothing -> ""
Just f -> [b|@0
<footer> <footer>
$4*footer $2*f
</footer> </footer>
|] |]
where
items = map makeItem galleries
makeItem :: GalleryInfo -> Builder makeItem :: GalleryInfo -> Builder
makeItem (GalleryInfo {title, prefix, filters}) = [b|@4 makeItem (GalleryInfo {title, prefix, filters}) = [b|@4
<li$nsfw><a href=$@prefix>$*title</a> <li$nsfw><a href=$@prefix>$*title</a>
|] |]
where where nsfw = if hasNsfw filters then " class=nsfw" else ""
nsfw = if hasNsfw filters then " class=nsfw" else ""
makeLink :: Link -> Builder
makeLink (Link {title, url, nsfw}) = [b|@4
<li$nsfw'><a href=$*url>$*title</a>
|]
where nsfw' = if nsfw then " class=nsfw" else ""
hasNsfw :: GalleryFilters -> Bool hasNsfw :: GalleryFilters -> Bool
hasNsfw (GalleryFilters {nsfw}) = nsfw /= Just False hasNsfw (GalleryFilters {nsfw}) = nsfw /= Just False

View file

@ -200,7 +200,8 @@ data IndexInfo =
IndexInfo { IndexInfo {
title :: !Text, title :: !Text,
galleries :: ![GalleryInfo], galleries :: ![GalleryInfo],
footer :: !Text links :: ![Link],
footer :: !(Maybe Text)
} }
deriving Show deriving Show
@ -208,7 +209,8 @@ instance FromYAML IndexInfo where
parseYAML = YAML.withMap "index info" \m -> parseYAML = YAML.withMap "index info" \m ->
IndexInfo <$> m .: "title" IndexInfo <$> m .: "title"
<*> m .:? "galleries" .!= [] <*> m .:? "galleries" .!= []
<*> m .:? "footer" .!= "" <*> m .:? "links" .!= []
<*> m .:? "footer"
data Pair a b = Pair !a !b data Pair a b = Pair !a !b

View file

@ -4,10 +4,12 @@ body {
width: 40em; width: 40em;
} }
.gallery-list { .gallery-list, .link-list {
display: grid; display: grid;
grid-template-columns: repeat(2, 50%);
align-items: center; align-items: center;
--gap: 0.05em;
grid-gap: var(--gap);
background: var(--text);
margin: 0; margin: 0;
padding: 0; padding: 0;
@ -16,41 +18,50 @@ body {
font-weight: 600; font-weight: 600;
} }
.gallery-list a { .gallery-list {
grid-template-columns: repeat(2, 50%);
}
.link-list {
grid-template-columns: 100%;
}
.gallery-list + .link-list {
padding-top: var(--gap);
}
main a {
display: block; display: block;
font-weight: inherit; font-weight: inherit;
color: var(--text); color: var(--text);
padding: 0.5em; padding: 0.5em;
} }
.gallery-list a:hover { main a:hover {
text-decoration: none; text-decoration: none;
} }
.gallery-list li { main li {
list-style: none; list-style: none;
text-align: center; text-align: center;
height: 100%; height: 100%;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
}
.gallery-list li {
background: var(--green); background: var(--green);
} }
.gallery-list li:nth-child(2n) { li.nsfw {
border-left: 2px solid hsla(0, 0%, 100%, 30%);
}
.gallery-list li:nth-child(2n+1) {
border-right: 2px solid hsla(0, 0%, 100%, 30%);
}
.gallery-list .nsfw {
background: var(--red); background: var(--red);
} }
.link-list li {
background: var(--yellow);
}
.nsfw a::after { .nsfw a::after {
content: url(18_plus.svg); content: url(18_plus.svg);
display: inline-block; display: inline-block;
@ -78,14 +89,14 @@ footer {
} }
@media (hover) and (prefers-reduced-motion: no-preference) { @media (hover) and (prefers-reduced-motion: no-preference) {
.gallery-list a:hover { main a:hover {
transform: scale(110%); transform: scale(110%);
transition: transform 0.25s ease-in-out; transition: transform 0.25s ease-in-out;
} }
} }
@media (pointer: coarse) { @media (pointer: coarse) {
.gallery-list { main {
font-size: 300%; font-size: 300%;
} }